ブートの仕組みをみる


パーティション1にブート、2にルート以下がある
パーティション2を変更すればARM版の好きなlinuxOSに変えることが出来るはず。
その起動のためのパーティション1をLS-GL上で展開して見てみる。
root@LS-GL216:~# mount
rootfs on / type rootfs (rw)
/dev/root on / type xfs (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw)
/proc/bus/usb/ on /proc/bus/usb type usbfs (rw)
/dev/ram1 on /mnt/ram type tmpfs (rw)
/dev/ls_disk1_1 on /boot type ext3 (rw,data=ordered) ←ココ
/dev/ls_disk1_6 on /mnt/disk1 type xfs (rw)
/dev/loop0 on /media/sdb1 type ext2 (rw,nogrpid)
root@LS-GL216:~# ls /boot -l
-rw-r--r-- 1 root root 19773 Apr 30 08:27 conf_save.tgz
-rw-r--r-- 1 root root 4520692 Oct 12 2007 initrd.buffalo
drwx------ 2 root root 12288 Sep 11 2006 lost+found
-rw-r--r-- 1 root root 245776 Jan 28 2008 u-boot.buffalo
-rw-r--r-- 1 root root 1867068 Jan 28 2008 uImage.buffalo
root@LS-GL216:~# cp -p /boot/*buffalo ~
root@LS-GL216:~# cd
root@LS-GL216:~# ls
initrd.buffalo u-boot.buffalo uImage.buffalo

先頭の64バイトを取り除いてmkimage前のext2のgzipに戻す

root@LS-GL216:~# dd if=initrd.buffalo bs=64 skip=1 of=initrd.gz
70634+1 records in
70634+1 records out

解凍。

root@LS-GL216:~# gunzip initrd.gz
root@LS-GL216:~# file initrd
initrd: Linux rev 1.0 ext2 filesystem data

loopオプションでマウントして中身を見てみる。

root@LS-GL216:~# mkdir /media/sdb1
root@LS-GL216:~# mount -o loop ./initrd /media/sdb1
root@LS-GL216:~# ls -la /media/sdb1

ルート以下はこのようになっている

drwxr-xr-x 16 root root 1024 Oct 12 2007 .
drwxr-xr-x 4 root root 28 Apr 30 08:49 ..
drwxr-xr-x 2 root root 1024 Oct 12 2007 bin
drwxr-xr-x 6 root root 3072 Oct 12 2007 dev
drwxr-xr-x 9 root root 1024 Oct 12 2007 etc
drwxr-xr-x 2 root root 2048 Oct 12 2007 lib
-rwx------ 1 root root 5684 Oct 11 2007 linuxrc
drwx------ 2 root root 12288 Oct 12 2007 lost+found
drwxr-xr-x 2 root root 1024 Oct 12 2007 mnt
drwxr-xr-x 2 root root 1024 Jan 31 2006 proc
drwx------ 2 root root 1024 Jan 31 2006 root
drwxr-xr-x 2 root root 1024 Oct 12 2007 rootfs
drwxr-xr-x 2 root root 1024 Oct 12 2007 sbin
drwxr-xr-x 2 root root 1024 Oct 12 2007 sys
drwxr-xr-x 2 root root 1024 Jan 31 2006 tmp
drwxr-xr-x 8 root root 1024 Oct 12 2007 usr
drwxr-xr-x 4 root root 1024 Oct 12 2007 var

linuxrcをみてみる。

root@LS-GL216:~# cd /media/sdb1
root@LS-GL216:~# cat linuxrc
#!/bin/sh

export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin

echo "---- in linuxrc ---"

mount proc /proc -t proc
mount sysfs /sys -t sysfs

. /usr/local/bin/libbuffalo

## must be same as init.d/bootcomplete
ROOTFS_OK=/mnt/etc/rootfs_ok
HDDROOTMODE=/mnt/etc/hddrootmode
ROOTFS_BOOTING=/mnt/etc/rootfs_booting

SetRootfsBootMarker() {
date > $ROOTFS_OK
}

DelRootfsBootMarker() {
rm -f $ROOTFS_OK
}

CopyFromInitrdToHdd() {

echo "-- CopyFromInitrdToHdd --"
# these files should be same as initrd.
# therefore you shouldn't put these files into hddimg.

cp -a /etc/linkstation_emergence /mnt/etc/initrd_ver

# usr/local/bin
for i in bootchange.sh exec_libbuffalo kernelmon_exec.sh imhere.sh lcd_error_man.sh libbuffalo set_time.sh shutdown.sh imhere.sh
do
cp -af /usr/local/bin/$i /mnt/usr/local/bin/
done

# /usr/local/sbin
cp -af /usr/local/sbin/* /mnt/usr/local/sbin/

# etc/init.d/
for i in bootcomplete.sh checkroot.sh clientUtil_servd.sh create_devlink.sh diskmon.sh ftpd.sh
do
cp -af /etc/init.d/$i /mnt/etc/init.d/
done

for i in kernelmon.sh logtag micon_setup.sh miconmon.sh networking.sh procps.sh rcDown reboot.sh reboot_start.sh
do
cp -af /etc/init.d/$i /mnt/etc/init.d/
done

for i in restore_config.sh sethostname.sh sendsigs.sh shutdown_start.sh syslog.sh umount_disk.sh
do
cp -af /etc/init.d/$i /mnt/etc/init.d/
done

cp -af /usr/local/sbin/clientUtil_server /mnt/usr/local/sbin/
cp -af /etc/dhcpc /mnt/etc/
cp -af /sbin/dhcpcd /mnt/sbin/

return 0
}

fsck_disks()
{
##fsck_localdisks
echo "== fsck_disks =="
fsck.ext3 -pyf /dev/${DEV_BOOT}
FsckXFS /dev/${DEV_ROOTFS1}
}

HasUpdatedFile()
{
mkdir ${MPT_BOOT}
mount /dev/${DEV_BOOT} ${MPT_BOOT}
if [ $? -ne 0 ]; then
# retry
mount /dev/${DEV_BOOT} ${MPT_BOOT}
fi
if [ $? -ne 0 ]; then
return 0
fi
# delete lost+founc
rm -rf ${MPT_BOOT}/lost+found/*
#
if [ -f ${MPT_BOOT}/uImage.buffalo.updated ]; then
umount ${MPT_BOOT}
return 1
fi
if [ -f ${MPT_BOOT}/u-boot.buffalo.updated ]; then
umount ${MPT_BOOT}
return 1
fi
if [ -f ${MPT_BOOT}/initrd.buffalo.updated ]; then
umount ${MPT_BOOT}
return 1
fi
if [ -f ${MPT_BOOT}/hddrootfs.buffalo.updated ]; then
umount ${MPT_BOOT}
return 1
fi
umount ${MPT_BOOT}
return 0
}

TestRootfs()
{
##echo "-- TestRootfs --"
mount -n -o rw /dev/${DEV_ROOTFS1} /mnt
if [ $? != 0 ]; then
# retry
mount -n -o rw /dev/${DEV_ROOTFS1} /mnt
fi
if [ $? = 0 ]; then
PRDI1=`grep PRODUCTID /proc/buffalo/firmware`
PRDI2=`grep PRODUCTID /mnt/etc/linkstation_release`

# delete lost+founc
rm -rf /mnt/lost+found/*
#

echo $PRDI1 $PRDI2
## check RootfsBootMarker
if [ ! -f $HDDROOTMODE ]; then
echo "** use initrd mode. **"
umount /mnt
return 1;
fi

if [ ! -f $ROOTFS_OK ]; then
echo "*** not found $ROOTFS_OK file in rootfs. ***"
echo -n "*" >> $ROOTFS_BOOTING
chars=`cat $ROOTFS_BOOTING|wc -c`
echo "chars=$chars"
## chars=0 means 'write fail'.
if [ "$chars" = 0 ] || [ "$chars" -ge 3 ] ; then
echo "** over max retry. use initrd mode. **"
umount /mnt
return 1;
fi
fi
/usr/local/bin/vercomp /proc/buffalo/firmware /mnt/etc/linkstation_release
DATE_KERN=$?
/usr/local/bin/vercomp /etc/linkstation_emergence /mnt/etc/linkstation_release
DATE_INITRD=$?
if [ $DATE_KERN -ne 0 ] || [ $DATE_INITRD -ne 0 ]; then
echo "*** hddSys is old. use initrd mode. ***"
umount /mnt
return 1
fi
DelRootfsBootMarker
CopyFromInitrdToHdd
umount /mnt

if [ "$PRDI1" = "$PRDI2" ]; then
return 0;
else
echo "*** version mismatch. use initrd mode. ***"
fi
fi
return 1;
}


HddRoot() {
echo "-HddRoot-"
HasUpdatedFile
if [ $? != 0 ]; then
echo "** has Updated Files **"
echo "0x100" >/proc/sys/kernel/real-root-dev
return
fi
TestRootfs
if [ $? != 0 ]; then
echo "0x100" >/proc/sys/kernel/real-root-dev
fi
fsck_disks
}

RamdiskRoot() {
echo "-RamdiskRoot-"
echo "0x100" >/proc/sys/kernel/real-root-dev
}

CommandMdode() {
echo "-CommandMode-"
mount -a
/sbin/getty -L ttyS0 115200 vt100
##/bin/sh
}

rtc_check()
{
grep "0000/" /proc/driver/rtc >/dev/null
if [ $? -eq 0 ]; then
miconapl -b -a boot_device_error "Chip Error E17RTC Failure"
fi
}

pci_check()
{
PCI_ETH="device 11"
PCI_SATA1="device 12"
PCI_SATA2="device 13"
PCI_USB="device 14"

# ETH PCI-ID11 (REALTEK:10ec)
grep "$PCI_ETH" /proc/pci >/dev/null
if [ $? -ne 0 ]; then
miconapl -b -a boot_device_error "Chip Error E21Ethernet Failure"
fi
# SATA1 PCI-ID12 (SIL:1095)
grep "$PCI_SATA1" /proc/pci >/dev/null
if [ $? -ne 0 ]; then
miconapl -b -a boot_device_error "Chip Error E18SATA1 Failure"
fi
# SATA2 PCI-ID13 (SIL:1095)
grep "$PCI_SATA2" /proc/pci >/dev/null
if [ $? -ne 0 ]; then
miconapl -b -a boot_device_error "Chip Error E19SATA2 Failure"
fi
# USB PCI-ID14 (NEC:1033)
grep "$PCI_USB" /proc/pci >/dev/null
if [ $? -ne 0 ]; then
miconapl -b -a boot_device_error "Chip Error E20USB Failure"
fi
}

CheckDevices()
{
echo "CheckDevices"
#pci_check
#rtc_check
}

# set the system time from the hardware clock
hwclock -s
date

## Setup Micon communication port and send flash-boot complete message.
miconapl -b -a boot_flash_ok
### miconapl -a led_set_cpu_mcon off
### miconapl -a led_set_on_off off
### miconapl -a led_set_brink off
### miconapl -a fan_set_speed full
CheckDevices

echo "linuxrc:choose operation (timeout 4[s])"
echo -n " 1:RamRoot other:HddRoot ? "
## timeout is 4[s]
ANSWER=`/usr/local/bin/keyinput -t 4`
case "$ANSWER" in
1) RamdiskRoot ;;
9) CommandMdode ;;
*)
HddRoot
;;
esac

cat /etc/mtab

umount /sys
umount /proc
umount -a
exit 0

root@LS-GL216:/media/sdb1#
root@LS-GL216:/media/sdb1# cat etc/fstab
proc /proc proc defaults 0 0
devpts /dev/pts devpts gid=4,mode=620 0 0
root@LS-GL216:/media/sdb1# cat etc/passwd
root:x:0:0:root:/root:/bin/sh
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
ftp:x:14:50:FTP User:/home:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
admin:x:52:52:Linux User,,,:/home:/bin/sh
sshd:x:74:74:Linux User,,,:/var/empty/sshd:/sbin/nologin
nobody:x:99:99:Linux User,,,:/home:/bin/sh
guest:x:20:21:Linux User,,,:/home:/bin/sh
root@LS-GL216:/media/sdb1# cat etc/inittab
::sysinit:/etc/init.d/rcS
::respawn:/sbin/getty -L ttyS0 115200 vt100

::restart:/sbin/init
::shutdown:/etc/init.d/rcDown
::shutdown:/bin/umount -r /