#! /bin/sh
##############################################################################
#
# Yoshinori OKUJI <yo@nexedi.com>
#
# Copyright (C) 2003 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="%s"
BOOT_PARTITION="%s"
BOOT_DEVICE="%s"
for module in $MODULES; do
echo Inserting /lib/$module.o...
insmod /lib/$module.o
done
# mount all the points that are in /etc/fstab
mount -a
mount -n -t tmpfs none /sysroot/
# create necessary directories
cd /sysroot
mkdir bin boot dev etc initrd lib mnt opt proc sbin tmp usr
chmod 1777 tmp
mkdir mnt/cf
# 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 the compact fash on /sysroot/mnt/cf which allow to use the *.iso and *.tgz
mount -t vfat $BOOT_PARTITION /sysroot/mnt/cf
# copy /etc, /root, /var on the ramdisk (so in read/write)
tar -xzpf /sysroot/mnt/cf/etc.tgz -C /sysroot/
tar -xzpf /sysroot/mnt/cf/var.tgz -C /sysroot/
tar -xzpf /sysroot/mnt/cf/root.tgz -C /sysroot/
tar -xzpf /sysroot/mnt/cf/home.tgz -C /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
# detect if a remote upgrade has been done.
for i in bin sbin lib usr; do
if test -f /sysroot/mnt/cf/$i.new; then
mv -f /sysroot/mnt/cf/$i.new /sysroot/mnt/cf/$i.iso
fi
done
# 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/*
# mount the *.iso
mount -o loop /sysroot/mnt/cf/bin.iso /sysroot/bin
mount -o loop /sysroot/mnt/cf/sbin.iso /sysroot/sbin
mount -o loop /sysroot/mnt/cf/lib.iso /sysroot/lib
mount -o loop /sysroot/mnt/cf/usr.iso /sysroot/usr
# Really necessary?
mount -t tmpfs none /sysroot/lib/dev-state
# 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