Rev 1 | Blame | Last modification | View Log | Download | RSS feed
#!/bin/ash
#
# Original version from http://www.linux-live.org/
#
# modified by Urs Beyerle, PSI
# - to allow LiveCD mounted over NFS
# - add support for LiveCD on SATA devices
export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin
. liblinuxlive
echolog "mounting /proc and /sys filesystems"
mount -t proc proc /proc
mount -t sysfs sysfs /sys
# setup DEBUGCMD variable. If debug boot option is present, call debug()
# function several times during script's execution
if [ "`cmdline_parameter debug`" ]; then DEBUGCMD="debug"; else DEBUGCMD=""; fi
$DEBUGCMD
# I have to set these variables very carefully
UNION=/union
MEMORY=/memory
#MOUNTDIR=mnt
MOUNTDIR=livecd
CHANGES=$MEMORY/changes
COPY2RAM=$MEMORY/copy2ram
IMAGES=$MEMORY/images
INITRAMDISK=$MOUNTDIR/live
# set NFSROOT if nfsroot= in boot parameter
NFSROOT="`cmdline_value nfsroot`"
# we need cdrom support, isofs support, unionfs support, etc
modprobe_essential_modules
setup_dma
$DEBUGCMD
# load network modules, if NFSROOT is set
echolog "check for nfsroot"
if [ "$NFSROOT" != "" ]; then
echolog "nfsroot: $NFSROOT"
# mii maybe need by NIC
echolog "load module mii"
modprobe_module mii
# detecting network card
PCITABLE=/bin/pcitable
NICS=`lspci -n | awk '/Class 0200/ {print $4}' | tr ':' ' ' \
| while read x y ; do grep "0x$x.*0x$y" $PCITABLE \
| awk '$3 !~ /"unknown"/ {print $3}' | tr -d '"' ; done`
echolog "Found network card(s): $NICS"
if [ -n "$NICS" ]; then
echo $NICS | while read nic ; do
echo "Loading module $nic"
modprobe_module $nic
done
else
echo "ERROR: No network card detected!"
echo "Type in your network card driver (e.g. tg3, e1000). "
echo "Or ask your system administrator for help."
echo -n "Network card driver: "
read nic
echo "Loading module $nic"
modprobe_module $nic
fi
fi
$DEBUGCMD
# get DHCP lease
if [ "$NFSROOT" != "" ]; then
# create /dev/urandom (needed by udhcpc)
mknod /dev/urandom c 1 9
echolog "Try to get DHCP lease on eth0"
udhcpc --now --quit --interface=eth0 --script=/bin/udhcpc.script
if [ $? -ne 0 ]; then
echo "ERROR: couldn't get DHCP lease, trying again"
udhcpc --now --quit --interface=eth0 --script=/bin/udhcpc.script
if [ $? -ne 0 ]; then
echo "ERROR: couldn't get DHCP lease, trying eth1"
udhcpc --now --quit --interface=eth1 --script=/bin/udhcpc.script
if [ $? -ne 0 ]; then
echo "ERROR: couldn't get DHCP lease, trying again eth1"
udhcpc --now --quit --interface=eth1 --script=/bin/udhcpc.script
if [ $? -ne 0 ]; then
echo "ERROR: can't get DHCP lease on eth0 and eth1"
fi
fi
fi
fi
fi
$DEBUGCMD
# we need nfs modules loaded, if NFSROOT is set
if [ "$NFSROOT" != "" ]; then
modprobe_nfs_modules
fi
$DEBUGCMD
# $UNION will be used as a root directory, livecd modules will be added soon.
echolog "setup union on $UNION"
mkdir -p $UNION
mkdir -p $MEMORY
CHANGESDEV="`cmdline_value changes`"
if [ "$CHANGESDEV" != "" ]; then
echo "mounting $CHANGESDEV to $MEMORY"
mount_device $CHANGESDEV $MEMORY
else false; fi
# mount tmpfs only in the case when changes= boot parameter was empty
# or we were not able to mount the storage device
if [ $? -ne 0 ]; then mount -t tmpfs -o "size=80%" tmpfs $MEMORY; fi
mkdir -p $CHANGES
mkdir -p $COPY2RAM
mkdir -p $IMAGES
mount -t unionfs -o dirs=$CHANGES=rw unionfs $UNION
if [ $? -ne 0 ]; then fatal "can't setup union in /union directory"; fi
$DEBUGCMD
# try to find livecd data directory. If not found, try modprobing
# USB and SATA kernel modules and repeat the find procedure again
echolog "looking for data modules"
DATA="`find_live_data_dir $MOUNTDIR`";
# if [ "$DATA" = "" ]; then modprobe_usb_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fi
if [ "$DATA" = "" ]; then modprobe_usb_sata_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fi
if [ "$DATA" = "" ]; then fatal "Data for LiveCD not found. Are you using SCSI?"; fi
echolog "LiveCD found in: $DATA"
$DEBUGCMD
# If toram or copy2ram boot parameter is present, copy all .mo modules to RAM.
# (skip modules from /optional/ which are not listed in load= boot option)
# Finaly modify DATA variable so it will point to correct directory
if [ "`cmdline_parameter toram`" != "" -o "`cmdline_parameter copy2ram`" != "" ]; then
echolog "copying modules to RAM, this may take some time"
copy_to_ram $DATA $COPY2RAM
cd_autoeject 1
umount $DATA 2>/dev/null
if [ $? -ne 0 ]; then umount `dirname $DATA` 2>/dev/null; fi
DATA=$COPY2RAM
cd_autoeject 0
fi
mkdir -p $UNION/boot
mount -o bind $DATA $UNION/boot
$DEBUGCMD
# DATA contains path to the base directory of all .mo images which need
# to be mounted and inserted into live filesystem. Do it now.
echolog "inserting all modules and creating live filesystem"
union_insert_modules $UNION $DATA $IMAGES
$DEBUGCMD
echo "copying rootchanges"
copy_rootchanges $DATA $UNION
$DEBUGCMD
echo "creating /etc/fstab"
activate_fstab $UNION
# More likely these directories aren't there.
# Even if they are, this won't hurt.
mkdir -p $UNION/proc
mkdir -p $UNION/sys
mkdir -p $UNION/tmp
mkdir -p $UNION/dev
$DEBUGCMD
# Union contains all the files and directories unioned from all modules.
# Change root directory to it, and move initrd's root to /livecd/live/initramdisk
# Finaly execute /sbin/init to start the distribution.
echolog "changing root directory..."
cd $UNION
mkdir -p $INITRAMDISK
umount /sys # we won't need it anymore
if [ ! -e $UNION/dev/console ]; then mknod $UNION/dev/console c 5 1; fi
if [ -x $UNION/usr/sbin/chroot ];
then CHROOT=/usr/sbin/chroot
else CHROOT=/usr/bin/chroot
fi
echolog "End of linux live scripts"
# pure magic ;-)
cat $UNION/bin/true >/dev/null
$DEBUGCMD
pivot_root . $INITRAMDISK
exec $CHROOT . sbin/init <dev/console >dev/console 2>&1; fi
header "ERROR!"
echolog "You are not supposed to be here, something went wrong!"
echolog "Even Ctrl+Alt+Del won't help you in kernel panic."