#! /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 # wait until the compact flash device becomes ready. while true; do sfdisk -R $BOOT_DEVICE >/dev/null 2>&1 && break echo Re-reading $BOOT_DEVICE failed. Retrying... sleep 1 done # mount all the points that are in /etc/fstab mount -a if test "x$COMPRESSION" = xyes; then mount -n -t tmpfs none /sysroot/ # create necessary directories cd /sysroot mkdir boot dev initrd mnt opt proc tmp chmod 1777 tmp mkdir mnt/cf mnt/squashfs # mount the compact fash on /sysroot/mnt/cf which allow to use the squashfs mount -t vfat $BOOT_PARTITION /sysroot/mnt/cf # 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 mv -f /sysroot/mnt/cf/base.new /sysroot/mnt/cf/base.sqh fi # mount the squashfs 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) 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 tar -xzvpf /sysroot/mnt/cf/config.tgz -C /sysroot/ fi # Remove garbage, if any. These can be, when the machine crashes while # running rsync. 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 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? 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 devfs and /proc mount -t devfs none /dev mount -t proc none /proc # allow to justify that / is really / echo 0x100 > /proc/sys/kernel/real-root-dev # umount some filesystems umount /proc umount /initrd/proc