Subversion Repositories livecd

Rev

Rev 84 | 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

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

# I have to set these variables very carefully
UNION=/union
MEMORY=/memory
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/aufs support, etc
modprobe_essential_modules

# disable DMA if nodma parameter is used
setup_dma

$DEBUGCMD

# if NFSROOT is set:
echolog "check for nfsroot"
if [ "$NFSROOT" != "" ]; then

   # load network modules, if NFSROOT is set
   echolog "nfsroot: $NFSROOT"
   load_network_modules

   $DEBUGCMD

   # get DHCP lease
   echolog "get DHCP lease"
   get_dhcp_lease
   
   $DEBUGCMD

    # we need nfs modules loaded, if NFSROOT is set
    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=$RAMSIZE" tmpfs $MEMORY; fi

mkdir -p $CHANGES
mkdir -p $COPY2RAM
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"
DATA="`find_live_data_dir $MOUNTDIR`";
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
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

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."