Rev 161 | 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 devices# - to allow LiveCD mounted over CIFSexport PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin. liblinuxliveecholog "mounting /proc and /sys filesystems"mount -t proc proc /procmount -t sysfs sysfs /sysln -sf /proc/mounts /etc/mtab # this allows us to use umount -a# 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# amount of RAM to store changesRAMSIZE="`cmdline_value ramsize`"if [ "$RAMSIZE" = "" ]; then RAMSIZE="70%"; fi# I have to set these variables very carefullyUNION=/unionMEMORY=/memoryMOUNTDIR=livecdCHANGES=$MEMORY/changesCOPY2RAM=$MEMORY/copy2ramIMAGES=$MEMORY/imagesINITRAMDISK=$MOUNTDIR/live# set NFSROOT and NFSOPTNFSROOT="`cmdline_value nfsroot`"NFSOPTS="`cmdline_value nfsopts`"if [ "$NFSOPTS" = "" ]; thenNFSOPTS=nolock,ro,rsize=8192,wsize=8192,hard,intrfi# set CIFSROOT and CIFSOPTSCIFSROOT="`cmdline_value cifsroot`"CIFSOPTS="`cmdline_value cifsopts`"# we need cdrom support, isofs support, unionfs/aufs support, etcmodprobe_essential_modules# disable DMA if nodma parameter is usedsetup_dma$DEBUGCMD# if NFSROOT is set:echolog "check for nfsroot or cifsroot"if [ "$NFSROOT" != "" ]; thenecholog "nfsroot: $NFSROOT"$DEBUGCMDload_network_modules$DEBUGCMDget_dhcp_lease$DEBUGCMDmodprobe_nfs_modules# if CIFSROOT is setelif [ "$CIFSROOT" != "" ]; thenecholog "cifsroot: $CIFSROOT"$DEBUGCMDload_network_modules$DEBUGCMDget_dhcp_lease$DEBUGCMDmodprobe_cifs_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"# we may need usb and sata supportmodprobe_usb_sata_modulesmount_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=$RAMSIZE" tmpfs $MEMORY; fimkdir -p $CHANGESmkdir -p $COPY2RAMmkdir -p $IMAGES# mount unionfs or aufslsmod | grep -q ^unionfsif [ $? -eq 0 ]; thenmount -t unionfs -o dirs=$CHANGES=rw unionfs $UNIONif [ $? -ne 0 ]; then fatal "can't setup union in $UNION directory"; fiecholog "unionfs mounted"elsemount -t aufs -o br:$CHANGES=rw aufs $UNIONif [ $? -ne 0 ]; then fatal "can't setup union (aufs) in $UNION directory"; fiecholog "aufs mounted"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_sata_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fiif [ "$DATA" = "" ]; then fatal "Data for LiveCD not found."; 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/tmpchmod 1777 $UNION/tmpmkdir -p $UNION/devmkdir -p $UNION/initrd$DEBUGCMD# no X? (set runlevel to 3)if [ "`cmdline_parameter nox`" ]; thenecho "set runlevel to 3"sed -i "s/id:.:initdefault:/id:3:initdefault:/" $UNION/etc/inittabfi$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 anymore# if [ ! -e $UNION/dev/console ]; then mknod $UNION/dev/console c 5 1; fi# Copy all dev files (found by mdev) to unioned dev directory# so at least disk devices exist (your Linux may need them).# Two exceptions, do not copy pty* and tty* devs.if [ ! -e /dev/console ]; then mknod /dev/console c 5 1; ficp -fdR /dev . 2>/dev/nullif [ -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>&1header "ERROR!"echolog "You are not supposed to be here, something went wrong!"echolog "Even Ctrl+Alt+Del won't help you in kernel panic."