Go to most recent revision | 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 devicesexport PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin. liblinuxliveecholog "mounting /proc and /sys filesystems"mount -t proc proc /procmount -t sysfs sysfs /sys# setup DEBUGCMD variable. If debug boot option is present, call debug()# function several times during script's executionif [ "`cmdline_parameter debug`" ]; then DEBUGCMD="debug"; else DEBUGCMD=""; fi$DEBUGCMD# I have to set these variables very carefullyUNION=/unionMEMORY=/memory#MOUNTDIR=mntMOUNTDIR=livecdCHANGES=$MEMORY/changesCOPY2RAM=$MEMORY/copy2ramIMAGES=$MEMORY/imagesINITRAMDISK=$MOUNTDIR/live# set NFSROOT if nfsroot= in boot parameterNFSROOT="`cmdline_value nfsroot`"# we need cdrom support, isofs support, unionfs support, etcmodprobe_essential_modulessetup_dma$DEBUGCMD# load network modules, if NFSROOT is setecholog "check for nfsroot"if [ "$NFSROOT" != "" ]; thenecholog "nfsroot: $NFSROOT"# mii maybe need by NICecholog "load module mii"modprobe_module mii# detecting network cardPCITABLE=/bin/pcitableNICS=`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" ]; thenecho $NICS | while read nic ; doecho "Loading module $nic"modprobe_module $nicdoneelseecho "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 nicecho "Loading module $nic"modprobe_module $nicfifi$DEBUGCMD# get DHCP leaseif [ "$NFSROOT" != "" ]; then# create /dev/urandom (needed by udhcpc)mknod /dev/urandom c 1 9echolog "Try to get DHCP lease on eth0"udhcpc --now --quit --interface=eth0 --script=/bin/udhcpc.scriptif [ $? -ne 0 ]; thenecho "ERROR: couldn't get DHCP lease, trying again"udhcpc --now --quit --interface=eth0 --script=/bin/udhcpc.scriptif [ $? -ne 0 ]; thenecho "ERROR: couldn't get DHCP lease, trying eth1"udhcpc --now --quit --interface=eth1 --script=/bin/udhcpc.scriptif [ $? -ne 0 ]; thenecho "ERROR: couldn't get DHCP lease, trying again eth1"udhcpc --now --quit --interface=eth1 --script=/bin/udhcpc.scriptif [ $? -ne 0 ]; thenecho "ERROR: can't get DHCP lease on eth0 and eth1"fififififi$DEBUGCMD# we need nfs modules loaded, if NFSROOT is setif [ "$NFSROOT" != "" ]; thenmodprobe_nfs_modulesfi$DEBUGCMD# $UNION will be used as a root directory, livecd modules will be added soon.echolog "setup union on $UNION"mkdir -p $UNIONmkdir -p $MEMORYCHANGESDEV="`cmdline_value changes`"if [ "$CHANGESDEV" != "" ]; thenecho "mounting $CHANGESDEV to $MEMORY"mount_device $CHANGESDEV $MEMORYelse false; fi# mount tmpfs only in the case when changes= boot parameter was empty# or we were not able to mount the storage deviceif [ $? -ne 0 ]; then mount -t tmpfs -o "size=80%" tmpfs $MEMORY; fimkdir -p $CHANGESmkdir -p $COPY2RAMmkdir -p $IMAGESmount -t unionfs -o dirs=$CHANGES=rw unionfs $UNIONif [ $? -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 againecholog "looking for data modules"DATA="`find_live_data_dir $MOUNTDIR`";# if [ "$DATA" = "" ]; then modprobe_usb_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fiif [ "$DATA" = "" ]; then modprobe_usb_sata_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fiif [ "$DATA" = "" ]; then fatal "Data for LiveCD not found. Are you using SCSI?"; fiecholog "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 directoryif [ "`cmdline_parameter toram`" != "" -o "`cmdline_parameter copy2ram`" != "" ]; thenecholog "copying modules to RAM, this may take some time"copy_to_ram $DATA $COPY2RAMcd_autoeject 1umount $DATA 2>/dev/nullif [ $? -ne 0 ]; then umount `dirname $DATA` 2>/dev/null; fiDATA=$COPY2RAMcd_autoeject 0fimkdir -p $UNION/bootmount -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$DEBUGCMDecho "copying rootchanges"copy_rootchanges $DATA $UNION$DEBUGCMDecho "creating /etc/fstab"activate_fstab $UNION# More likely these directories aren't there.# Even if they are, this won't hurt.mkdir -p $UNION/procmkdir -p $UNION/sysmkdir -p $UNION/tmpmkdir -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 $UNIONmkdir -p $INITRAMDISKumount /sys # we won't need it anymoreif [ ! -e $UNION/dev/console ]; then mknod $UNION/dev/console c 5 1; fiif [ -x $UNION/usr/sbin/chroot ];then CHROOT=/usr/sbin/chrootelse CHROOT=/usr/bin/chrootfiecholog "End of linux live scripts"# pure magic ;-)cat $UNION/bin/true >/dev/null$DEBUGCMDpivot_root . $INITRAMDISKexec $CHROOT . sbin/init <dev/console >dev/console 2>&1; fiheader "ERROR!"echolog "You are not supposed to be here, something went wrong!"echolog "Even Ctrl+Alt+Del won't help you in kernel panic."