| 1 | beyerle@PS | 1 | #!/bin/ash
 | 
        
           |  |  | 2 | #
 | 
        
           |  |  | 3 | # Original version from http://www.linux-live.org/
 | 
        
           |  |  | 4 | #
 | 
        
           | 169 | beyerle@PS | 5 | # modified by Urs Beyerle
 | 
        
           | 1 | beyerle@PS | 6 | # - to allow LiveCD mounted over NFS
 | 
        
           |  |  | 7 | # - add support for LiveCD on SATA devices
 | 
        
           | 160 | beyerle@PS | 8 | # - to allow LiveCD mounted over CIFS
 | 
        
           | 1 | beyerle@PS | 9 |   | 
        
           |  |  | 10 | export PATH=.:/:/usr/sbin:/usr/bin:/sbin:/bin
 | 
        
           |  |  | 11 | . liblinuxlive
 | 
        
           |  |  | 12 |   | 
        
           |  |  | 13 |   | 
        
           |  |  | 14 | echolog "mounting /proc and /sys filesystems"
 | 
        
           |  |  | 15 | mount -t proc proc /proc
 | 
        
           |  |  | 16 | mount -t sysfs sysfs /sys
 | 
        
           | 36 | beyerle@PS | 17 | ln -sf /proc/mounts /etc/mtab # this allows us to use umount -a
 | 
        
           | 1 | beyerle@PS | 18 |   | 
        
           |  |  | 19 | # setup DEBUGCMD variable. If debug boot option is present, call debug()
 | 
        
           |  |  | 20 | # function several times during script's execution
 | 
        
           |  |  | 21 | if [ "`cmdline_parameter debug`" ]; then DEBUGCMD="debug"; else DEBUGCMD=""; fi
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 | $DEBUGCMD
 | 
        
           |  |  | 24 |   | 
        
           | 36 | beyerle@PS | 25 | # amount of RAM to store changes
 | 
        
           |  |  | 26 | RAMSIZE="`cmdline_value ramsize`"
 | 
        
           |  |  | 27 | if [ "$RAMSIZE" = "" ]; then RAMSIZE="70%"; fi
 | 
        
           |  |  | 28 |   | 
        
           | 241 | beyerleu | 29 | # Set these variables very carefully
 | 
        
           | 1 | beyerle@PS | 30 | UNION=/union
 | 
        
           |  |  | 31 | MEMORY=/memory
 | 
        
           |  |  | 32 | MOUNTDIR=livecd
 | 
        
           | 204 | beyerleu | 33 | CHANGES=$MEMORY/SL53changes
 | 
        
           | 1 | beyerle@PS | 34 | COPY2RAM=$MEMORY/copy2ram
 | 
        
           |  |  | 35 | IMAGES=$MEMORY/images
 | 
        
           |  |  | 36 | INITRAMDISK=$MOUNTDIR/live
 | 
        
           |  |  | 37 |   | 
        
           | 185 | beyerle@PS | 38 | # set NFSROOT and NFSOPTS 
 | 
        
           | 1 | beyerle@PS | 39 | NFSROOT="`cmdline_value nfsroot`"
 | 
        
           | 161 | beyerle@PS | 40 | NFSOPTS="`cmdline_value nfsopts`"
 | 
        
           | 241 | beyerleu | 41 | if [ "$NFSOPTS" = "" ]; then NFSOPTS="nolock,ro,rsize=8192,wsize=8192,hard,intr"; fi
 | 
        
           | 1 | beyerle@PS | 42 |   | 
        
           | 161 | beyerle@PS | 43 | # set CIFSROOT and CIFSOPTS
 | 
        
           | 160 | beyerle@PS | 44 | CIFSROOT="`cmdline_value cifsroot`"
 | 
        
           | 161 | beyerle@PS | 45 | CIFSOPTS="`cmdline_value cifsopts`"
 | 
        
           | 160 | beyerle@PS | 46 |   | 
        
           | 241 | beyerleu | 47 | # set DHCPDELAY (in seconds)
 | 
        
           |  |  | 48 | DHCPDELAY="`cmdline_value dhcpdelay`"
 | 
        
           |  |  | 49 | if [ "$DHCPDELAY" = "" ]; then DHCPDELAY=8; fi
 | 
        
           |  |  | 50 |   | 
        
           | 37 | beyerle@PS | 51 | # we need cdrom support, isofs support, unionfs/aufs support, etc
 | 
        
           | 1 | beyerle@PS | 52 | modprobe_essential_modules
 | 
        
           | 84 | beyerle@PS | 53 |   | 
        
           |  |  | 54 | # disable DMA if nodma parameter is used
 | 
        
           | 1 | beyerle@PS | 55 | setup_dma
 | 
        
           |  |  | 56 |   | 
        
           |  |  | 57 | $DEBUGCMD
 | 
        
           |  |  | 58 |   | 
        
           | 36 | beyerle@PS | 59 | # if NFSROOT is set:
 | 
        
           | 160 | beyerle@PS | 60 | echolog "check for nfsroot or cifsroot"
 | 
        
           | 1 | beyerle@PS | 61 | if [ "$NFSROOT" != "" ]; then
 | 
        
           | 36 | beyerle@PS | 62 |   | 
        
           | 160 | beyerle@PS | 63 |    echolog "nfsroot: $NFSROOT"
 | 
        
           |  |  | 64 |    $DEBUGCMD
 | 
        
           | 36 | beyerle@PS | 65 |    load_network_modules
 | 
        
           |  |  | 66 |    $DEBUGCMD
 | 
        
           | 150 | beyerle@PS | 67 |    get_dhcp_lease
 | 
        
           | 36 | beyerle@PS | 68 |    $DEBUGCMD
 | 
        
           | 163 | beyerle@PS | 69 |    modprobe_nfs_modules
 | 
        
           | 1 | beyerle@PS | 70 |   | 
        
           | 160 | beyerle@PS | 71 | # if CIFSROOT is set
 | 
        
           |  |  | 72 | elif [ "$CIFSROOT" != "" ]; then
 | 
        
           |  |  | 73 |   | 
        
           |  |  | 74 |    echolog "cifsroot: $CIFSROOT"
 | 
        
           |  |  | 75 |    $DEBUGCMD
 | 
        
           |  |  | 76 |    load_network_modules
 | 
        
           |  |  | 77 |    $DEBUGCMD
 | 
        
           |  |  | 78 |    get_dhcp_lease
 | 
        
           |  |  | 79 |    $DEBUGCMD
 | 
        
           | 163 | beyerle@PS | 80 |    modprobe_cifs_modules
 | 
        
           | 160 | beyerle@PS | 81 |   | 
        
           | 1 | beyerle@PS | 82 | fi
 | 
        
           |  |  | 83 |   | 
        
           |  |  | 84 | $DEBUGCMD
 | 
        
           |  |  | 85 |   | 
        
           |  |  | 86 | # $UNION will be used as a root directory, livecd modules will be added soon.
 | 
        
           |  |  | 87 | echolog "setup union on $UNION"
 | 
        
           |  |  | 88 | mkdir -p $UNION
 | 
        
           |  |  | 89 | mkdir -p $MEMORY
 | 
        
           |  |  | 90 |   | 
        
           | 170 | beyerle@PS | 91 | # looking for changes= parameter
 | 
        
           |  |  | 92 | CHANGESVAL="`cmdline_value changes`"
 | 
        
           |  |  | 93 | if [ "$CHANGESVAL" != "" ]; then 
 | 
        
           |  |  | 94 |     # disable kernel warnings
 | 
        
           |  |  | 95 |     PRINTK=`cat /proc/sys/kernel/printk`
 | 
        
           |  |  | 96 |     echo "0" >/proc/sys/kernel/printk
 | 
        
           |  |  | 97 |     find_changes
 | 
        
           |  |  | 98 |     # enable kernel warnings
 | 
        
           |  |  | 99 |     echo "$PRINTK" >/proc/sys/kernel/printk
 | 
        
           |  |  | 100 | fi
 | 
        
           | 173 | beyerle@PS | 101 | mkdir -p $MEMORY
 | 
        
           | 1 | beyerle@PS | 102 |   | 
        
           | 170 | beyerle@PS | 103 | $DEBUGCMD
 | 
        
           |  |  | 104 |   | 
        
           | 1 | beyerle@PS | 105 | # mount tmpfs only in the case when changes= boot parameter was empty
 | 
        
           | 170 | beyerle@PS | 106 | if [ "$CHANGESVAL" = "" ]; then 
 | 
        
           |  |  | 107 |     echolog "mount tmpfs"
 | 
        
           |  |  | 108 |     mount -t tmpfs -o "size=$RAMSIZE" tmpfs $MEMORY
 | 
        
           |  |  | 109 |     $DEBUGCMD
 | 
        
           |  |  | 110 | fi
 | 
        
           | 1 | beyerle@PS | 111 |   | 
        
           |  |  | 112 | mkdir -p $CHANGES
 | 
        
           |  |  | 113 | mkdir -p $COPY2RAM
 | 
        
           | 173 | beyerle@PS | 114 | rm -rf $IMAGES
 | 
        
           | 1 | beyerle@PS | 115 | mkdir -p $IMAGES
 | 
        
           |  |  | 116 |   | 
        
           | 37 | beyerle@PS | 117 | # mount unionfs or aufs
 | 
        
           |  |  | 118 | lsmod | grep -q ^unionfs
 | 
        
           |  |  | 119 | if [ $? -eq 0 ]; then  
 | 
        
           |  |  | 120 |     mount -t unionfs -o dirs=$CHANGES=rw unionfs $UNION
 | 
        
           | 48 | beyerle@PS | 121 |     if [ $? -ne 0 ]; then fatal "can't setup union in $UNION directory"; fi
 | 
        
           | 100 | beyerle@PS | 122 |     echolog "unionfs mounted"
 | 
        
           | 37 | beyerle@PS | 123 | else
 | 
        
           |  |  | 124 |     mount -t aufs -o br:$CHANGES=rw aufs $UNION
 | 
        
           | 48 | beyerle@PS | 125 |     if [ $? -ne 0 ]; then fatal "can't setup union (aufs) in $UNION directory"; fi
 | 
        
           | 100 | beyerle@PS | 126 |     echolog "aufs mounted"
 | 
        
           | 37 | beyerle@PS | 127 | fi
 | 
        
           |  |  | 128 |   | 
        
           | 1 | beyerle@PS | 129 | $DEBUGCMD
 | 
        
           |  |  | 130 |   | 
        
           |  |  | 131 | # try to find livecd data directory. If not found, try modprobing
 | 
        
           |  |  | 132 | # USB and SATA kernel modules and repeat the find procedure again
 | 
        
           |  |  | 133 | echolog "looking for data modules"
 | 
        
           | 170 | beyerle@PS | 134 |   | 
        
           |  |  | 135 | # disable kernel warnings
 | 
        
           |  |  | 136 | PRINTK=`cat /proc/sys/kernel/printk`
 | 
        
           |  |  | 137 | echo "0" >/proc/sys/kernel/printk
 | 
        
           |  |  | 138 | DATA="`find_live_data_dir $MOUNTDIR`"
 | 
        
           |  |  | 139 | # enable kernel warnings
 | 
        
           |  |  | 140 | echo "$PRINTK" >/proc/sys/kernel/printk
 | 
        
           |  |  | 141 |   | 
        
           | 1 | beyerle@PS | 142 | if [ "$DATA" = "" ]; then modprobe_usb_sata_modules; DATA="`find_live_data_dir $MOUNTDIR`"; fi
 | 
        
           | 126 | beyerle@PS | 143 | if [ "$DATA" = "" ]; then fatal "Data for LiveCD not found."; fi
 | 
        
           | 1 | beyerle@PS | 144 | echolog "LiveCD found in: $DATA"
 | 
        
           |  |  | 145 |   | 
        
           |  |  | 146 | $DEBUGCMD
 | 
        
           |  |  | 147 |   | 
        
           |  |  | 148 | # If toram or copy2ram boot parameter is present, copy all .mo modules to RAM.
 | 
        
           |  |  | 149 | # (skip modules from /optional/ which are not listed in load= boot option)
 | 
        
           |  |  | 150 | # Finaly modify DATA variable so it will point to correct directory
 | 
        
           |  |  | 151 | if [ "`cmdline_parameter toram`" != "" -o "`cmdline_parameter copy2ram`" != "" ]; then
 | 
        
           |  |  | 152 |    echolog "copying modules to RAM, this may take some time"
 | 
        
           |  |  | 153 |    copy_to_ram $DATA $COPY2RAM
 | 
        
           |  |  | 154 |    cd_autoeject 1
 | 
        
           |  |  | 155 |    umount $DATA 2>/dev/null
 | 
        
           |  |  | 156 |    if [ $? -ne 0 ]; then umount `dirname $DATA` 2>/dev/null; fi
 | 
        
           |  |  | 157 |    DATA=$COPY2RAM
 | 
        
           |  |  | 158 |    cd_autoeject 0
 | 
        
           |  |  | 159 | fi
 | 
        
           |  |  | 160 |   | 
        
           |  |  | 161 | mkdir -p $UNION/boot
 | 
        
           |  |  | 162 | mount -o bind $DATA $UNION/boot
 | 
        
           |  |  | 163 |   | 
        
           |  |  | 164 | $DEBUGCMD
 | 
        
           |  |  | 165 |   | 
        
           |  |  | 166 | # DATA contains path to the base directory of all .mo images which need
 | 
        
           |  |  | 167 | # to be mounted and inserted into live filesystem. Do it now.
 | 
        
           |  |  | 168 | echolog "inserting all modules and creating live filesystem"
 | 
        
           |  |  | 169 | union_insert_modules $UNION $DATA $IMAGES
 | 
        
           |  |  | 170 |   | 
        
           |  |  | 171 | $DEBUGCMD
 | 
        
           |  |  | 172 |   | 
        
           |  |  | 173 | echo "copying rootchanges"
 | 
        
           |  |  | 174 | copy_rootchanges $DATA $UNION
 | 
        
           |  |  | 175 |   | 
        
           |  |  | 176 | $DEBUGCMD
 | 
        
           |  |  | 177 |   | 
        
           |  |  | 178 | echo "creating /etc/fstab"
 | 
        
           |  |  | 179 | activate_fstab $UNION
 | 
        
           |  |  | 180 |   | 
        
           |  |  | 181 | # More likely these directories aren't there.
 | 
        
           |  |  | 182 | # Even if they are, this won't hurt.
 | 
        
           |  |  | 183 | mkdir -p $UNION/proc
 | 
        
           |  |  | 184 | mkdir -p $UNION/sys
 | 
        
           |  |  | 185 | mkdir -p $UNION/tmp
 | 
        
           | 36 | beyerle@PS | 186 | chmod 1777 $UNION/tmp
 | 
        
           | 1 | beyerle@PS | 187 | mkdir -p $UNION/dev
 | 
        
           | 36 | beyerle@PS | 188 | mkdir -p $UNION/initrd
 | 
        
           | 1 | beyerle@PS | 189 |   | 
        
           |  |  | 190 | $DEBUGCMD
 | 
        
           |  |  | 191 |   | 
        
           | 48 | beyerle@PS | 192 | # no X? (set runlevel to 3)
 | 
        
           |  |  | 193 | if [ "`cmdline_parameter nox`" ]; then
 | 
        
           |  |  | 194 |   echo "set runlevel to 3"
 | 
        
           | 64 | beyerle@PS | 195 |   sed -i "s/id:.:initdefault:/id:3:initdefault:/" $UNION/etc/inittab
 | 
        
           | 48 | beyerle@PS | 196 | fi
 | 
        
           |  |  | 197 |   | 
        
           |  |  | 198 | $DEBUGCMD
 | 
        
           |  |  | 199 |   | 
        
           | 1 | beyerle@PS | 200 | # Union contains all the files and directories unioned from all modules.
 | 
        
           |  |  | 201 | # Change root directory to it, and move initrd's root to /livecd/live/initramdisk
 | 
        
           |  |  | 202 | # Finaly execute /sbin/init to start the distribution.
 | 
        
           |  |  | 203 | echolog "changing root directory..."
 | 
        
           |  |  | 204 | cd $UNION
 | 
        
           |  |  | 205 | mkdir -p $INITRAMDISK
 | 
        
           |  |  | 206 |   | 
        
           |  |  | 207 | umount /sys # we won't need it anymore
 | 
        
           |  |  | 208 |   | 
        
           | 160 | beyerle@PS | 209 | # if [ ! -e $UNION/dev/console ]; then mknod $UNION/dev/console c 5 1; fi
 | 
        
           |  |  | 210 |   | 
        
           |  |  | 211 | # Copy all dev files (found by mdev) to unioned dev directory
 | 
        
           |  |  | 212 | # so at least disk devices exist (your Linux may need them).
 | 
        
           |  |  | 213 | # Two exceptions, do not copy pty* and tty* devs.
 | 
        
           |  |  | 214 | if [ ! -e /dev/console ]; then mknod /dev/console c 5 1; fi
 | 
        
           |  |  | 215 | cp -fdR /dev . 2>/dev/null
 | 
        
           |  |  | 216 |   | 
        
           | 1 | beyerle@PS | 217 | if [ -x $UNION/usr/sbin/chroot ];
 | 
        
           |  |  | 218 |   then CHROOT=/usr/sbin/chroot
 | 
        
           |  |  | 219 |   else CHROOT=/usr/bin/chroot
 | 
        
           |  |  | 220 | fi
 | 
        
           |  |  | 221 |   | 
        
           |  |  | 222 | echolog "End of linux live scripts"
 | 
        
           |  |  | 223 |   | 
        
           |  |  | 224 | # pure magic ;-)
 | 
        
           |  |  | 225 | cat $UNION/bin/true >/dev/null
 | 
        
           |  |  | 226 |   | 
        
           |  |  | 227 | $DEBUGCMD
 | 
        
           |  |  | 228 |   | 
        
           |  |  | 229 | pivot_root . $INITRAMDISK
 | 
        
           | 36 | beyerle@PS | 230 | exec $CHROOT . sbin/init <dev/console >dev/console 2>&1
 | 
        
           | 1 | beyerle@PS | 231 |   | 
        
           |  |  | 232 | header "ERROR!"
 | 
        
           |  |  | 233 | echolog "You are not supposed to be here, something went wrong!"
 | 
        
           |  |  | 234 | echolog "Even Ctrl+Alt+Del won't help you in kernel panic."
 | 
        
           | 209 | beyerleu | 235 | echolog "Try to boot with 'linux failsafe' or 'linux all_generic_ide'"
 | 
        
           | 1 | beyerle@PS | 236 |   |