berryboot の作りをもう少し見たかったので、起動するboot img をばらして覗いてみました。手順は絶対忘れるのでメモしておきます。
作業は、osx でやっています。
とりあえず、作業用にRAMディスクを作っておきます。
作業は、RAMディスクの中じゃなくてもいいんですが、何かと速くて間違えなくて便利なので、自分用のメモの意味をあって書いています。独立したファイルシステムにフォーマットすることも簡単ですしね。
osx でRAMディスクを作成するには、
$ diskutil eraseDisk HFS+ RAMDISK `hdiutil attach -nomount ram://8388608`
この例では、ディスクサイズは8388608(4096 * 2048)で4GB のRAMディスクとしています。
コマンドラインがいやな場合は、RAMDiskCreator というツールをFlorian Bognerさんが公開しているので使ってみてください。
これ以下は、Linux でも同じなはずです。
file で berriboot.img を見ると、u-boot の uImage のようです。
$ file berryboot.img berryboot.img: u-boot legacy uImage, , Linux/ARM, RAMDisk Image (Not compressed), 10112736 bytes, Wed Apr 1 07:32:40 2015, Load Address: 0x00000000, Entry Point: 0x00000000, Header CRC: 0xAB28A904, Data CRC: 0x6870C48E
これは調べてみると、以下のようにすることで展開できるようです。
$ dd if=berryboot.img bs=64 skip=1 of=berryboot_initrd 158011+1 records in 158011+1 records out 10112736 bytes transferred in 0.315515 secs (32051518 bytes/sec)
先頭64bite に属性情報があるようで、それを飛ばして DD してやればよいようです。再度、file で見てみると、
$ file berryboot_initrd berryboot_initrd: gzip compressed data, was "rootfs.cpio", from Unix, last modified: Wed Apr 1 07:32:37 2015, max compression
cpio のようです。tmp ディレクトリを作成後、そこに展開してみます。
$ mkdir tmp $ cd tmp/ $ cpio -idm < ../berryboot_initrd
うまく展開されたようです。
init では以下のようなことをしているようです。
---- /init
#!/bin/sh
#
# BerryBoot, ugly but functional image chooser thingy
#
# Author: Floris Bos
#
# Standard busybox init
/bin/mount -t proc proc /proc
/bin/mount -o remount,rw,noatime /
/bin/mount -t sysfs sysfs /sys
/bin/mount -t devtmpfs dev /dev
/bin/hostname -F /etc/hostname
if grep -q debugconsole /proc/cmdline; then
/sbin/getty -L tty2 0 vt100 &
fi
if grep -q "mmc0_led" /proc/cmdline; then
if [ -e /sys/class/leds/ph20:green:led1 ]; then
echo mmc0 > /sys/class/leds/ph20:green:led1/trigger
fi
fi
if grep -q vncinstall /proc/cmdline; then
export QWS_DISPLAY="VNC:size=800x600:depth=32:0"
echo
echo Connect with your VNC client
echo If you wish to disable VNC mode: remove 'vncinstall' from cmdline.txt
echo
fi
# Show GUI, it will write the OS choosen to /tmp/answer
/usr/bin/BerrybootGUI -qws 2>/tmp/debug
# Clear screen
clear
IMAGE=`cat /tmp/answer`
DATADIR="/mnt/data/$IMAGE"
rm /tmp/answer
#
# Set CPU governor to "ondemand" when booting an OS on the Pi
# Set it to "performance" for other devices
#
if grep -q "BCM2708" /proc/cpuinfo; then
GOVERNOR=ondemand
else
GOVERNOR=performance
fi
if [ "$IMAGE" != "" ]; then
mkdir -p /squashfs /aufs $DATADIR
clear
echo Mounting image ${IMAGE}...
mount -o loop "/mnt/images/$IMAGE" /squashfs
cd /squashfs
if [ -e berryboot-init ]; then
echo Executing init script
. berryboot-init
fi
if [ -L lib -o -L sbin ]; then
echo
echo Error: having a symlink for /lib and/or /sbin inside your image is not allowed!
echo This conflicts with the shared AUFS folders
echo
sleep 5
fi
for initfile in sbin/init usr/lib/systemd/systemd init
do
if [ -e $initfile ]; then
echo Mounting RW data directory on top
mount -t aufs -o br:${DATADIR}:/mnt/shared:/squashfs none /aufs
cd /aufs
mount -o move /dev dev
mount -o move /sys sys
mount -o move /proc proc
echo Setting CPU governor to $GOVERNOR
echo "$GOVERNOR" > sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo Starting operating system ${IMAGE}...
exec switch_root . $initfile
fi
done
echo
echo Error: unable to locate or execute /sbin/init /usr/lib/systemd/systemd /init inside $IMAGE
echo
sleep 5
fi
# In case the user pressed cancel or something went wrong, show an emergency recovery shell
clear
echo
echo Emergency recovery shell activated
echo
/bin/sh
cmdline に mmc0_led があると、何か green にしているようですね。筐体のLED を緑にしているんですかね? あとで試してみます。vncinstall があると、環境変数QWS_DISPLAYにVNC のパラメータがセットされるようです。VNC インストールができるということですかね。あとで、試してみることに。
ちょっと勉強になりました。


