Rev 243 | Rev 249 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#!/bin/ash
#
# Original version from http://www.linux-live.org/
#
# modified by Urs Beyerle
# - to allow LiveCD mounted over NFS
# - add support for LiveCD on SATA devices
# - to allow LiveCD mounted over CIFS
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
ln -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 execution
if [ "`cmdline_parameter debug`" ]; then DEBUGCMD="debug"; else DEBUGCMD=""; fi
$DEBUGCMD
# amount of RAM to store changes
RAMSIZE="`cmdline_value ramsize`"
if [ "$RAMSIZE" = "" ]; then RAMSIZE="70%"; fi
# Set these variables very carefully
UNION=/union
MEMORY=/memory
MOUNTDIR=livecd
CHANGES=$MEMORY/SL54changes
COPY2RAM=$MEMORY/copy2ram
IMAGES=$MEMORY/images
INITRAMDISK=$MOUNTDIR/live
# set NFSROOT and NFSOPTS
NFSROOT="`cmdline_value nfsroot`"
NFSOPTS="`cmdline_value nfsopts`"
if [ "$NFSOPTS" = "" ]; then NFSOPTS="nolock,ro,rsize=8192,wsize=8192,hard,intr"; fi
# set CIFSROOT and CIFSOPTS
CIFSROOT="`cmdline_value cifsroot`"
CIFSOPTS="`cmdline_value cifsopts`"
# set DHCPDELAY (in seconds)
DHCPDELAY="`cmdline_value dhcpdelay`"
if [ "$DHCPDELAY" = "" ]; then DHCPDELAY=8; fi
# set USBDELAY (in seconds)
USBDELAY="`cmdline_value usbdelay`"
if [ "$USBDELAY" = "" ]; then USBDELAY=8; fi
# we need cdrom support, isofs support, unionfs/aufs support, etc
modprobe_essential_modules
# disable DMA if nodma parameter is used
setup_dma
$DEBUGCMD
# if NFSROOT is set:
echolog "check for nfsroot or cifsroot"
if [ "$NFSROOT" != "" ]; then
echolog "nfsroot: $NFSROOT"
$DEBUGCMD
load_network_modules
$DEBUGCMD
get_dhcp_lease
$DEBUGCMD
modprobe_nfs_modules
# if CIFSROOT is set
elif [ "$CIFSROOT" != "" ]; then
echolog "cifsroot: $CIFSROOT"
$DEBUGCMD
load_network_modules
$DEBUGCMD
get_dhcp_lease
$DEBUGCMD
modprobe_cifs_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
# looking for changes= parameter
CHANGESVAL="`cmdline_value changes`"
if [ "$CHANGESVAL" != "" ]; then
# disable kernel warnings
PRINTK=`cat /proc/sys/kernel/printk`
echo "0" >/proc/sys/kernel/printk
find_changes
# enable kernel warnings
echo "$PRINTK" >/proc/sys/kernel/printk
fi
mkdir -p $MEMORY
$DEBUGCMD
# mount tmpfs only in the case when changes= boot parameter was empty
if [ "$CHANGESVAL" = "" ]; then
echolog "mount tmpfs"
mount -t tmpfs -o "size=$RAMSIZE" tmpfs $MEMORY
$DEBUGCMD
fi
mkdir -p $CHANGES
mkdir -p $COPY2RAM
rm -rf $IMAGES
mkdir -p $IMAGES
# mount unionfs or aufs
lsmod | grep -q ^unionfs
if [ $? -eq 0 ]; then
mount -t unionfs -o dirs=$CHANGES=rw unionfs $UNION
if [ $? -ne 0 ]; then fatal "can't setup union in $UNION directory"; fi
echolog "unionfs mounted"
else
mount -t aufs -o br:$CHANGES=rw aufs $UNION
if [ $? -ne 0 ]; then fatal "can't setup union (aufs) in $UNION directory"; fi
echolog "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 again
echolog "looking for data modules"
# disable kernel warnings
PRINTK=`cat /proc/sys/kernel/printk`
echo "0" >/proc/sys/kernel/printk
DATA="`find_live_data_dir $MOUNTDIR`"
# enable kernel warnings
echo "$PRINTK" >/proc/sys/kernel/printk
if [ "$DATA" = "" ]; then modprobe_usb_sata_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fi
if [ "$DATA" = "" ]; then fatal "Data for LiveCD not found."; 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
chmod 1777 $UNION/tmp
mkdir -p $UNION/dev
mkdir -p $UNION/initrd
$DEBUGCMD
# no X? (set runlevel to 3)
if [ "`cmdline_parameter nox`" ]; then
echo "set runlevel to 3"
sed -i "s/id:.:initdefault:/id:3:initdefault:/" $UNION/etc/inittab
fi
$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
# 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; fi
cp -fdR /dev . 2>/dev/null
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
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."
echolog "Try to boot with 'linux failsafe' or 'linux all_generic_ide'"