#! /bin/sh ############################################################################## # # Yoshinori OKUJI # Alexandre Boeglin # # Copyright (C) 2003,2004 Nexedi SARL # # This program is Free Software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ?See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ?02111-1307, USA. # ############################################################################## MODULES="%(modules)s" BOOT_PARTITION="%(boot_partition)s" BOOT_DEVICE="%(boot_device)s" COMPRESSION="%(compression)s" for module in $MODULES; do echo Inserting /lib/$module.ko... insmod /lib/$module.ko done # mount proc and sys echo Mounting /proc filesystem mount -t proc /proc /proc echo Mounting sysfs mount -t sysfs none /sys # start udev echo starting udev udevstart echo -n /sbin/hotplug > /proc/sys/kernel/hotplug # wait until the compact flash device becomes ready. while true; do #echo /dev/* #sfdisk -R $BOOT_DEVICE >/dev/null 2>&1 && break test -e $BOOT_DEVICE && break echo Re-reading $BOOT_DEVICE failed. Retrying... sleep 1 done # wait until the partition is ready while true; do test -e $BOOT_PARTITION && break echo Re-reading $BOOT_PARTITION failed. Retrying... sleep 1 done # Wait 5 seconds to make sure USB stuff is ready sleep 5 if test "x$COMPRESSION" = xyes; then #echo Create tmpfs root filesystem mount -n -t tmpfs none /sysroot/ # create necessary directories echo Populate rootfs with rw directories cd /sysroot mkdir boot dev initrd mnt opt proc sys tmp chmod 1777 tmp mkdir mnt/cf mnt/squashfs # mount the compact fash on /sysroot/mnt/cf which allow to use the squashfs echo Mount media partition mount -o defaults,ro $BOOT_PARTITION /sysroot/mnt/cf # Populate dev with dev nodes echo Copy device nodes to rootfs dev cp -ax /dev/* dev/ # if the default boot partition is wrong (may happen when multiple usb # keys are plugged in at boot time), try every scsi device and look for # a base.sqh file #if test ! -f /sysroot/mnt/cf/base.sqh; then # echo Root image not present on $BOOT_PARTITION # umount /sysroot/mnt/cf # for scsi_device in /dev/scsi/host*/bus*/target*/lun*; do # echo Available device : $scsi_device # done # for scsi_device in /dev/scsi/host*/bus*/target*/lun*; do # scsi_disc=$scsi_device/disc # scsi_part=$scsi_device/part1 # # while true; do # sfdisk -R $scsi_disc >/dev/null 2>&1 && break # echo Re-reading $scsi_disc failed. Retrying... # sleep 1 # done # # if test ! -e $scsi_part; then # echo No first partition on $scsi_disc # continue # fi # # mount -t vfat $scsi_part /sysroot/mnt/cf # if test ! -f /sysroot/mnt/cf/base.sqh; then # echo Root image not found on $scsi_part # umount /sysroot/mnt/cf # else # echo Root image found on $scsi_part # break # fi # done #fi # detect if a remote upgrade has been done. if test -f /sysroot/mnt/cf/base.new; then echo Install upgrade mount -o remount,rw /sysroot/mnt/cf mv -f /sysroot/mnt/cf/base.new /sysroot/mnt/cf/base.sqh mount -o remount,ro /sysroot/mnt/cf fi # mount the squashfs echo Mount ro loop file mount -o ro,loop -t squashfs /sysroot/mnt/cf/base.sqh /sysroot/mnt/squashfs # copy /etc, /root, /var on the ramdisk (so in read/write) echo Copy rw directories into rootfs cp -a /sysroot/mnt/squashfs/etc /sysroot/ cp -a /sysroot/mnt/squashfs/var /sysroot/ cp -a /sysroot/mnt/squashfs/root /sysroot/ cp -a /sysroot/mnt/squashfs/home /sysroot/ # create /fastboot so as not to verify the filesystem at boot time cp /dev/null /sysroot/fastboot # copy config files on the ramdisk, if config.tgz is present. if test -f /sysroot/mnt/cf/config.tgz; then echo Install custom config.tgz files tar -xzvpf /sysroot/mnt/cf/config.tgz -C /sysroot/ fi # Remove garbage, if any. These can be, when the machine crashes while # running rsync. echo Remove garbage if any for i in /sysroot/mnt/cf/.*; do if test $i != /sysroot/mnt/cf/. -a $i != /sysroot/mnt/cf/..; then rm -f $i fi done # echo /dev/* # link the other directories from squashfs echo Create links to ro directories ln -s /mnt/squashfs/bin /sysroot ln -s /mnt/squashfs/sbin /sysroot ln -s /mnt/squashfs/lib /sysroot ln -s /mnt/squashfs/usr /sysroot # Really necessary? echo Mount dev-state as tmpfs mount -t tmpfs none /sysroot/mnt/squashfs/lib/dev-state else mount -o defaults --ro $BOOT_PARTITION /sysroot fi # do a "pivot_root" so as to change the place of / pivot_root /sysroot /sysroot/initrd # mount /proc mount -t proc none /proc # allow to justify that / is really / echo 0x0100 > /proc/sys/kernel/real-root-dev # umount some filesystems umount /proc # Why ? umount /initrd/sys umount /initrd/proc echo Initrd finished