X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=scripts%2Flive;h=4169c9044b1c520917dc0ea8a14ec8e48535bb77;hb=e66f79476042794195978ee641aa7ea0d9ca6e0a;hp=e17f66ff17ed6605080a5496731d6407132f98be;hpb=77d2a350cab73c2764cf7f226c8f635ac4138fd4;p=live-boot-grml.git diff --git a/scripts/live b/scripts/live index e17f66f..4169c90 100755 --- a/scripts/live +++ b/scripts/live @@ -20,6 +20,7 @@ USERFULLNAME="Live user" HOSTNAME="host" mkdir -p "${mountpoint}" +tried="/tmp/tried" # Create /etc/mtab for debug purpose and future syncs if [ ! -d /etc ] @@ -45,37 +46,26 @@ fi Arguments () { PRESEEDS="" + LOCATIONS="" for ARGUMENT in $(cat /proc/cmdline) do case "${ARGUMENT}" in skipconfig) NOACCESSIBILITY="Yes" - NOAPPARMOR="Yes" NOAPTCDROM="Yes" NOAUTOLOGIN="Yes" NOCONSOLEKEYBOARD="Yes" NOFASTBOOT="Yes" NOFSTAB="Yes" - NOGNOMEPANEL="Yes" NOHOSTS="Yes" - NOJOCKEY="Yes" - NOKPERSONALIZER="Yes" - NOLANGUAGESELECTOR="Yes" NOLOCALES="Yes" NONETWORKING="Yes" - NOPOLKITCONF="Yes" - NOPOWERMANAGEMENT="Yes" - NOPROGRAMCRASHES="Yes" - NOSUDO="Yes" NOTIMEZONE="Yes" - NOUPDATENOTIFIER="Yes" - NOUSER="Yes" NOXAUTOCONFIG="Yes" NOXAUTOLOGIN="Yes" - NOXSCREENSAVER="Yes" - export NOACCESSIBILITY NOAPPARMOR NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOGNOMEPANEL NOHOSTS NOJOCKEY NOKPERSONALIZER NOLANGUAGESELECTOR NOLOCALES NONETWORKING NOPOLKITCONF NOPOWERMANAGEMENT NOPROGRAMCRASHES NOSUDO NOTIMEZONE NOUPDATENOTIFIER NOUSER NOXAUTOCONFIG NOXAUTOLOGIN NOXSCREENSAVER + export NOACCESSIBILITY NOAPTCDROM NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NOHOSTS NOLOCALES NONETWORKING NOTIMEZONE NOXAUTOCONFIG NOXAUTOLOGIN ;; access=*) @@ -100,6 +90,16 @@ Arguments () export DEVICE ;; + ethdevice=*) + ETHDEVICE="${ARGUMENT#ethdevice=}" + export ETHDEVICE + ;; + + ethdevice-timeout=*) + ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}" + export ETHDEV_TIMEOUT + ;; + fetch=*) FETCH="${ARGUMENT#fetch=}" export FETCH @@ -110,11 +110,6 @@ Arguments () export FORCEPERSISTENTFSCK ;; - hook=*) - HOOK="${ARGUMENT#hook=}" - export HOOK - ;; - ftpfs=*) FTPFS="${ARGUMENT#ftpfs=}" export FTPFS @@ -125,12 +120,6 @@ Arguments () export HTTPFS ;; - hostname=*) - HOSTNAME="${ARGUMENT#hostname=}" - LIVECONF="changed" - export HOSTNAME LIVECONF - ;; - isofrom=*|fromiso=*) FROMISO="${ARGUMENT#*=}" export FROMISO @@ -260,11 +249,6 @@ Arguments () export NOACCESSIBILITY ;; - noapparmor) - NOAPPARMOR="Yes" - export NOAPPARMOR - ;; - noaptcdrom) NOAPTCDROM="Yes" export NOAPTCDROM @@ -295,26 +279,11 @@ Arguments () export NOFSTAB ;; - nognomepanel) - NOGNOMEPANEL="Yes" - export NOGNOMEPANEL - ;; - nohosts) NOHOSTS="Yes" export NOHOSTS ;; - nokpersonalizer) - NOKPERSONALIZER="Yes" - export NOKPERSONALIZER - ;; - - nolanguageselector) - NOLANGUAGESELECTOR="Yes" - export NOLANGUAGESELECTOR - ;; - nolocales) NOLOCALES="Yes" export NOLOCALES @@ -325,41 +294,11 @@ Arguments () export NONETWORKING ;; - nopowermanagement) - NOPOWERMANAGEMENT="Yes" - export NOPOWERMANAGEMENT - ;; - - noprogramcrashes) - NOPROGRAMCRASHES="Yes" - export NOPROGRAMCRASHES - ;; - - nojockey) - NOJOCKEY="Yes" - export NOJOCKEY - ;; - - nosudo) - NOSUDO="Yes" - export NOSUDO - ;; - swapon) SWAPON="Yes" export SWAPON ;; - noupdatenotifier) - NOUPDATENOTIFIER="Yes" - export NOUPDATENOTIFIER - ;; - - nouser) - NOUSER="Yes" - export NOUSER - ;; - noxautoconfig) NOXAUTOCONFIG="Yes" export NOXAUTOCONFIG @@ -401,9 +340,14 @@ Arguments () export NOPERSISTENT ;; + quickusbmodules) + QUICKUSBMODULES="Yes" + export QUICKUSBMODULES + ;; + preseed/file=*|file=*) - LOCATION="${ARGUMENT#*=}" - export LOCATION + LOCATIONS="${ARGUMENT#*=} ${LOCATIONS}" + export LOCATIONS ;; nopreseed) @@ -412,7 +356,7 @@ Arguments () ;; url=*) - location="${ARGUMENT#url=}" + URL_LOCATION="${ARGUMENT#url=}" mount -o bind /sys /root/sys mount -o bind /proc /root/proc @@ -420,14 +364,14 @@ Arguments () mkdir -p /root/var/run/network [ "${NETBOOT}" ] || chroot /root dhclient eth0 - chroot /root wget -P /tmp "${location}" + chroot /root wget -P /tmp "${URL_LOCATION}" [ "${NETBOOT}" ] || chroot /root ifconfig eth0 down umount /root/sys umount /root/proc umount /root/dev - LOCATION="/tmp/$(basename "${location}")" + LOCATIONS="/tmp/$(basename ${URL_LOCATION}) ${LOCATIONS}" ;; */*=*) @@ -503,11 +447,6 @@ Arguments () export UNIONTYPE ;; - utc=*) - UTC="${ARGUMENT#utc=}" - export UTC - ;; - xdebconf) XDEBCONF="Yes" export XDEBCONF @@ -650,12 +589,15 @@ is_nice_device () { sysfs_path="${1#/sys}" - if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-|platform-mmc)" + if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)" then return 0 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$' then return 0 + elif echo ${sysfs_path} | grep -q "^/block/dm-" + then + return 0 fi return 1 @@ -685,7 +627,7 @@ copy_live_to () if [ "${copytodev}" = "ram" ] then # copying to ram: - freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\/dev/console # "cp -a" from busybox also copies hidden files else mkdir -p ${copyto}/${LIVE_MEDIA_PATH} - cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} # "cp -a" from busybox also copies hidden files + cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/* ${copyto}/${LIVE_MEDIA_PATH} + if [ -e ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ] + then + cp -a ${copyfrom}/${LIVE_MEDIA_PATH}/.disk ${copyto} + fi fi fi @@ -757,18 +703,59 @@ do_netmount () modprobe -q af_packet # For DHCP - if [ -x /sbin/udevadm ] + udevadm trigger + udevadm settle + + if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \ + [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ] then - # lenny - udevadm trigger - udevadm settle - else - # etch - udevtrigger - udevsettle + + # if ethdevice was not specified on the kernel command line + # make sure we try to get a working network configuration + # for *every* present network device (except for loopback of course) + if [ -z "$ETHDEVICE" ] ; then + echo "If you want to boot from a specific device use bootoption ethdevice=..." + for device in /sys/class/net/*; do + dev=${device##*/} ; + if [ "$dev" != "lo" ] ; then + ETHDEVICE="$ETHDEVICE $dev" + fi + done fi + # split args of ethdevice=eth0,eth1 into "eth0 eth1" + for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do + devlist="$devlist $device" + done + + [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15 + echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration." + + # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into + # an endless loop; iff execution fails give it two further tries, that's + # why we use '$devlist $devlist $devlist' for the other for loop + for dev in $devlist $devlist $devlist ; do + echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev" + ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config & + jobid=$! + sleep "$ETHDEV_TIMEOUT" ; sleep 1 + if [ -r /proc/"$jobid"/status ] ; then + echo "Killing job $jobid for device $dev as ipconfig ran into recursion..." + kill -9 $jobid + fi + + # if configuration of device worked we should have an assigned + # IP address, iff so let's use the according as $DEVICE for later usage + # simple and primitive approach which seems to work fine + if ifconfig $dev | grep -q 'inet.*addr:' ; then + export DEVICE="$dev" + break + fi + done + + else ipconfig ${DEVICE} | tee /netboot.config + fi # source relevant ipconfig output OLDHOSTNAME=${HOSTNAME} @@ -777,7 +764,8 @@ do_netmount () export HOSTNAME # Check if we have a network device at all - if ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \ + if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \ + ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \ ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \ ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \ ! ls /sys/class/net/ra0 > /dev/null 2>&1 @@ -946,7 +934,7 @@ do_snap_copy () todev=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts) freespace=$(df -k | awk '/'${todev}'/{print $4}') else - freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\ /dev/null 2>&1 - RES=$? - if [ "${RES}" != "0" ] + + # Unfortunately klibc's cpio is incompatible with the + # rest of the world; everything else requires -u -d, + # while klibc doesn't implement them. Try to detect + # whether it's in use. + cpiopath="$(which cpio)" || true + if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath" then - log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories\"" + cpioargs= + else + cpioargs='--unconditional --make-directories' + fi + + if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null) + then + log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\"" fi - cd "${OLDPWD}" fi umount "${snapback}" || log_warning_msg "failure to \"umount ${snapback}\"" @@ -1080,7 +1077,7 @@ try_snap () return 1 fi - echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt + echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt return 0 } @@ -1089,7 +1086,25 @@ setup_unionfs () image_directory="${1}" rootmnt="${2}" addimage_directory="${3}" - modprobe -q -b ${UNIONTYPE} + + case ${UNIONTYPE} in + aufs|unionfs) + modprobe -q -b ${UNIONTYPE} + + if ! cut -f2 /proc/filesystems | grep -q "^${UNIONTYPE}\$" && [ -x /bin/unionfs-fuse ] + then + echo "${UNIONTYPE} not available, falling back to unionfs-fuse." + echo "This might be really slow." + + UNIONTYPE="unionfs-fuse" + fi + ;; + esac + + if [ "${UNIONTYPE}" = unionfs-fuse ] + then + modprobe fuse + fi # run-init can't deal with images in a subdir, but we're going to # move all of these away before it runs anyway. No, we're not, @@ -1101,15 +1116,14 @@ setup_unionfs () # Let's just mount the read-only file systems first rofsstring="" rofslist="" - minor_kernel_version=$(uname -r|cut -c 5-|sed 's/[^0-9].*//') - if [ "${NETBOOT}" = "nfs" ] && [ "${minor_kernel_version}" -lt 22 ] - then - # go aroung a bug in nfs-unionfs locking for unionfs <= 1.4 - roopt="nfsro" - elif [ "${UNIONTYPE}" = "aufs" ] + if [ "${UNIONTYPE}" = "aufs" ] then roopt="rr" + noxino_opt="noxino," + elif [ "${UNIONTYPE}" = "unionfs-fuse" ] + then + roopt="RO" else roopt="ro" fi @@ -1223,37 +1237,32 @@ setup_unionfs () # Looking for "${root_persistence}" device or file if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ] then - # Load USB modules - num_block=$(ls -l /sys/block | wc -l) - for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage - do - modprobe -q -b ${module} - done - - if [ -x /sbin/udevadm ] + if [ -z "${QUICKUSBMODULES}" ] then - # lenny + # Load USB modules + num_block=$(ls -l /sys/block | wc -l) + for module in sd_mod uhci-hcd ehci-hcd ohci-hcd usb-storage + do + modprobe -q -b ${module} + done + udevadm trigger udevadm settle - else - # etch - udevtrigger - udevsettle - fi - # For some reason, udevsettle does not block in this scenario, - # so we sleep for a little while. - # - # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591 - for timeout in 5 4 3 2 1 - do - sleep 1 + # For some reason, udevsettle does not block in this scenario, + # so we sleep for a little while. + # + # See https://bugs.launchpad.net/ubuntu/+source/casper/+bug/84591 + for timeout in 5 4 3 2 1 + do + sleep 1 - if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ] - then - break - fi - done + if [ $(ls -l /sys/block | wc -l) -gt ${num_block} ] + then + break + fi + done + fi # search for label and files (this could be hugely optimized) cowprobe=$(find_cow_device "${root_persistence}") @@ -1354,16 +1363,31 @@ setup_unionfs () for dir in ${cow_dirs}; do mkdir -p /cow${dir} - mount -t ${UNIONTYPE} \ - -o rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro \ - ${UNIONTYPE} "${rootmnt}${dir}" || \ - panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option \ - rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro" + + case "${UNIONTYPE}" in + unionfs-fuse) + (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${exposedrootfs}${dir} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow=RW:${exposedrootfs}${dir}") + mkdir -p /dev/.initramfs/varrun + pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true + ;; + + *) + mount -t ${UNIONTYPE} -o rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro ${UNIONTYPE} "${rootmnt}${dir}" || panic "mount ${UNIONTYPE} on ${rootmnt}${dir} failed with option rw,noatime,dirs=/cow${dir}=rw:${exposedrootfs}${dir}=ro" + ;; + esac done else - mount -t ${UNIONTYPE} -o noatime,dirs=/cow=rw:${rofsstring} \ - ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on \ - ${rootmnt} failed with option noatime,dirs=/cow=rw:${rofsstring}" + case "${UNIONTYPE}" in + unionfs-fuse) + (ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow=RW:${rofsstring} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option cow,noinitgroups,default_permissions,allow_other,use_ino,suid=/cow:RW:${rofsstring}") + mkdir -p /dev/.initramfs/varrun + pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true + ;; + + *) + mount -t ${UNIONTYPE} -o noatime,${noxino_opt}dirs=/cow=rw:${rofsstring} ${UNIONTYPE} "${rootmnt}" || panic "mount ${UNIONTYPE} on ${rootmnt} failed with option noatime,${noxino_opt}dirs=/cow=rw:${rofsstring}" + ;; + esac fi # Correct the permissions of /: @@ -1406,7 +1430,15 @@ setup_unionfs () ;; *) - mount -o move "${d}" "${rootmnt}/live/${d##*/}" + case "${UNIONTYPE}" in + unionfs-fuse) + mount -o bind "${d}" "${rootmnt}/live/${d##*/}" + ;; + + *) + mount -o move "${d}" "${rootmnt}/live/${d##*/}" + ;; + esac ;; esac done @@ -1426,12 +1458,31 @@ check_dev () # support for fromiso=.../isofrom=.... if [ -n "$FROMISO" ] then - mkdir /isofrom - ISO_DEVICE="$(echo $FROMISO | sed 's|\(/dev/[a-z]*[0-9]*\).*|\1|')" - mount "$ISO_DEVICE" /isofrom - ISO_NAME="$(echo $FROMISO | sed 's|/dev/[a-z]*[0-9]*/||')" - loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '') - devname="${loopdevname}" + ISO_DEVICE=$(dirname $FROMISO) + if ! [ -b $ISO_DEVICE ] + then + # to support unusual device names like /dev/cciss/c0d0p1 + # as well we have to identify the block device name, let's + # do that for up to 15 levels + i=15 + while [ -n "$ISO_DEVICE" ] && [ "$i" -gt 0 ] + do + ISO_DEVICE=$(dirname ${ISO_DEVICE}) + [ -b "$ISO_DEVICE" ] && break + i=$(($i -1)) + done + fi + + if [ "$ISO_DEVICE" = "/" ] + then + echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log + else + mkdir /isofrom + mount "$ISO_DEVICE" /isofrom + ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")" + loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '') + devname="${loopdevname}" + fi fi if [ -z "${devname}" ] @@ -1451,6 +1502,7 @@ check_dev () umount $mountpoint fi fi + [ -e "$devname" ] || continue if [ -n "${LIVE_MEDIA_OFFSET}" ] then @@ -1462,7 +1514,10 @@ check_dev () if is_supported_fs ${fstype} then + devuid=$(blkid -o value -s UUID "$devname") + [ -n "$devuid" ] && grep -qs "\<$devuid\>" $tried && continue mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue + [ -n "$devuid" ] && echo "$devuid" >> $tried if is_live_path ${mountpoint} && \ ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint}) @@ -1515,6 +1570,7 @@ find_livefs () fi fi done + return 1 ;; removable) @@ -1531,6 +1587,7 @@ find_livefs () done fi done + return 1 ;; *) @@ -1545,9 +1602,22 @@ find_livefs () esac # or do the scan of block devices - for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)") + # prefer removable devices over non-removable devices, so scan them first + for sysblock in $(echo /sys/block/* | tr ' ' '\n' | egrep -v "/(loop|ram|dm-|fd)") + do + if [ "$(cat ${sysblock}/removable)" = "1" ] + then + removable_devices_to_scan="$removable_devices_to_scan $sysblock" + else + nonremovable_devices_to_scan="$nonremovable_devices_to_scan $sysblock" + fi + done + devices_to_scan="$removable_devices_to_scan $nonremovable_devices_to_scan" + + for sysblock in $devices_to_scan do devname=$(sys2dev "${sysblock}") + [ -e "$devname" ] || continue fstype=$(get_fstype "${devname}") if /lib/udev/cdrom_id ${devname} > /dev/null @@ -1573,7 +1643,7 @@ find_livefs () then # This is an ugly hack situation, the block device has # an image directly on it. It's hopefully - # live-initramfs, so take it and run with it. + # live-boot, so take it and run with it. ln -s "${devname}" "${devname}.${fstype}" echo "${devname}.${fstype}" return 0 @@ -1619,6 +1689,14 @@ integrity_check () fi } +start_usplash_pulse () +{ + if [ -x /sbin/usplash_write ] + then + /sbin/usplash_write "PULSELOGO" + fi +} + mountroot () { if [ -x /scripts/local-top/cryptroot ]; then @@ -1638,6 +1716,7 @@ mountroot () Arguments set_usplash_timeout + start_usplash_pulse maybe_break live-premount log_begin_msg "Running /scripts/live-premount" @@ -1725,14 +1804,37 @@ mountroot () log_end_msg + # unionfs-fuse needs /dev to be bind-mounted for the duration of + # live-bottom; udev's init script will take care of things after that + if [ "${UNIONTYPE}" = unionfs-fuse ] + then + mount -n -o bind /dev "${rootmnt}/dev" + fi + + # Move to the new root filesystem so that programs there can get at it. + if [ ! -d /root/live/image ] + then + mkdir -p /root/live/image + mount --move /live/image /root/live/image + fi + maybe_break live-bottom log_begin_msg "Running /scripts/live-bottom\n" run_scripts /scripts/live-bottom log_end_msg + if [ "${UNIONFS}" = unionfs-fuse ] + then + umount "${rootmnt}/dev" + fi + exec 1>&6 6>&- exec 2>&7 7>&- kill ${tailpid} [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null + if [ -f /etc/live.conf ] + then + cp /etc/live.conf "${rootmnt}/etc/" + fi }