X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=scripts%2Flive;h=a17eb423fca132f0aaf03c8ca6f956766eaef797;hb=52dcef518bdb95605670b8dc12257057bf7a2dc0;hp=7acf0d9a7f06a4950577aa1dacb271678dc7b4d1;hpb=a606391b56012c067ae44b20690df5ae39dbc052;p=live-boot-grml.git diff --git a/scripts/live b/scripts/live index 7acf0d9..a17eb42 100755 --- a/scripts/live +++ b/scripts/live @@ -8,6 +8,7 @@ echo "/root/lib" >> /etc/ld.so.conf echo "/root/usr/lib" >> /etc/ld.so.conf mountpoint="/live/image" +alt_mountpoint="/media" LIVE_MEDIA_PATH="live" root_persistence="live-rw" @@ -33,9 +34,6 @@ then touch /etc/mtab fi -[ -f /etc/live.conf ] && . /etc/live.conf -export USERNAME USERFULLNAME HOSTNAME - . /scripts/live-helpers if [ ! -f /live.vars ] @@ -53,31 +51,11 @@ Arguments () 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 NOFASTBOOT NOFSTAB NONETWORKING ;; access=*) @@ -97,14 +75,21 @@ Arguments () set -x ;; - ethdevice=*) - DEVICE="${ARGUMENT#ethdevice=}" - export DEVICE + dhcp) + # Force dhcp even while netbooting + # Use for debugging in case somebody works on fixing dhclient + DHCP="Force"; + export DHCP + ;; + + nodhcp) + unset DHCP ;; ethdevice=*) - ETHDEVICE="${ARGUMENT#ethdevice=}" - export ETHDEVICE + DEVICE="${ARGUMENT#ethdevice=}" + ETHDEVICE="${DEVICE}" + export DEVICE ETHDEVICE ;; ethdevice-timeout=*) @@ -122,11 +107,6 @@ Arguments () export FORCEPERSISTENTFSCK ;; - hook=*) - HOOK="${ARGUMENT#hook=}" - export HOOK - ;; - ftpfs=*) FTPFS="${ARGUMENT#ftpfs=}" export FTPFS @@ -135,12 +115,19 @@ Arguments () httpfs=*) HTTPFS="${ARGUMENT#httpfs=}" export HTTPFS - ;; + ;; - hostname=*) - HOSTNAME="${ARGUMENT#hostname=}" - LIVECONF="changed" - export HOSTNAME LIVECONF + iscsi=*) + ISCSI="${ARGUMENT#iscsi=}" + #ip:port - separated by ; + ISCSI_PORTAL="${ISCSI%;*}" + if echo "${ISCSI_PORTAL}" | grep -q , ; then + ISCSI_SERVER="${ISCSI_PORTAL%,*}" + ISCSI_PORT="${ISCSI_PORTAL#*,}" + fi + #target name + ISCSI_TARGET="${ISCSI#*;}" + export ISCSI ISCSI_PORTAL ISCSI_TARGET ISCSI_SERVER ISCSI_PORT ;; isofrom=*|fromiso=*) @@ -148,18 +135,6 @@ Arguments () export FROMISO ;; - username=*) - USERNAME="${ARGUMENT#username=}" - LIVECONF="changed" - export USERNAME LIVECONF - ;; - - userfullname=*) - USERFULLNAME="${ARGUMENT#userfullname=}" - LIVECONF="changed" - export USERFULLNAME LIVECONF - ;; - ignore_uuid) IGNORE_UUID="Yes" export IGNORE_UUID @@ -181,31 +156,6 @@ Arguments () export STATICIP ;; - keyb=*|kbd-chooser/method=*) - KBD="${ARGUMENT#*=}" - export KBD - ;; - - klayout=*|console-setup/layoutcode=*) - KLAYOUT="${ARGUMENT#*=}" - export KLAYOUT - ;; - - kvariant=*|console-setup/variantcode=*) - KVARIANT="${ARGUMENT#*=}" - export KVARIANT - ;; - - kmodel=*|console-setup/modelcode=*) - KMODEL="${ARGUMENT#*=}" - export KMODEL - ;; - - koptions=*) - KOPTIONS="${ARGUMENT#koptions=}" - export KOPTIONS - ;; - live-getty) LIVE_GETTY="1" export LIVE_GETTY @@ -236,17 +186,6 @@ Arguments () export LIVE_MEDIA_TIMEOUT ;; - language=*|debian-installer/language=*) - language=${x#debian-installer/language=} - locale="$(lang2locale "$language")" - set_locale="true" - ;; - - locale=*|debian-installer/locale=*) - LOCALE="${ARGUMENT#*=}" - export LOCALE - ;; - module=*) MODULE="${ARGUMENT#module=}" export MODULE @@ -272,31 +211,6 @@ Arguments () export NOACCESSIBILITY ;; - noapparmor) - NOAPPARMOR="Yes" - export NOAPPARMOR - ;; - - noaptcdrom) - NOAPTCDROM="Yes" - export NOAPTCDROM - ;; - - noautologin) - NOAUTOLOGIN="Yes" - export NOAUTOLOGIN - ;; - - noxautologin) - NOXAUTOLOGIN="Yes" - export NOXAUTOLOGIN - ;; - - noconsolekeyboard) - NOCONSOLEKEYBOARD="Yes" - export NOCONSOLEKEYBOARD - ;; - nofastboot) NOFASTBOOT="Yes" export NOFASTBOOT @@ -307,81 +221,16 @@ 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 - ;; - nonetworking) NONETWORKING="Yes" 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 - ;; - - noxscreensaver) - NOXSCREENSAVER="Yes" - export NOXSCREENSAVER - ;; - persistent) PERSISTENT="Yes" export PERSISTENT @@ -428,25 +277,6 @@ Arguments () export NOPRESEED ;; - url=*) - URL_LOCATION="${ARGUMENT#url=}" - - mount -o bind /sys /root/sys - mount -o bind /proc /root/proc - mount -o bind /dev /root/dev - - mkdir -p /root/var/run/network - [ "${NETBOOT}" ] || chroot /root dhclient eth0 - chroot /root wget -P /tmp "${URL_LOCATION}" - [ "${NETBOOT}" ] || chroot /root ifconfig eth0 down - - umount /root/sys - umount /root/proc - umount /root/dev - - LOCATIONS="/tmp/$(basename ${URL_LOCATION}) ${LOCATIONS}" - ;; - */*=*) question="${ARGUMENT%%=*}" value="${ARGUMENT#*=}" @@ -464,21 +294,6 @@ Arguments () export SILENT ;; - textonly) - TEXTONLY="Yes" - export TEXTONLY - ;; - - timezone=*) - TIMEZONE="${ARGUMENT#timezone=}" - export TIMEZONE - ;; - - notimezone) - NOTIMEZONE="Yes" - export NOTIMEZONE - ;; - todisk=*) TODISK="${ARGUMENT#todisk=}" export TODISK @@ -519,26 +334,6 @@ Arguments () UNIONTYPE="${ARGUMENT#union=}" export UNIONTYPE ;; - - utc=*) - UTC="${ARGUMENT#utc=}" - export UTC - ;; - - xdebconf) - XDEBCONF="Yes" - export XDEBCONF - ;; - - xdriver=*) - XDRIVER="${ARGUMENT#xdriver=}" - export XDRIVER - ;; - - xvideomode=*) - XVIDEOMODE="${ARGUMENT#xvideomode=}" - export XVIDEOMODE - ;; esac done @@ -775,10 +570,8 @@ copy_live_to () return 0 } -do_netmount () +do_netsetup () { - rc=1 - modprobe -q af_packet # For DHCP udevadm trigger @@ -841,6 +634,27 @@ do_netmount () [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME} export HOSTNAME + if [ -n "${DEVICE}" ] + then + HWADDR="$(cat /sys/class/net/${DEVICE}/address)" + fi + + if [ ! -e "/etc/resolv.conf" ] + then + echo "Creating /etc/resolv.conf" + + if [ -n "${DNSDOMAIN}" ] + then + echo "domain ${DNSDOMAIN}" > /etc/resolv.conf + echo "search ${DNSDOMAIN}" > /etc/resolv.conf + fi + + for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1} + do + echo "nameserver $i" >> /etc/resolv.conf + done + fi + # Check if we have a network device at all if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \ ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \ @@ -850,16 +664,23 @@ do_netmount () then panic "No supported network device found, maybe a non-mainline driver is required." fi +} + +do_netmount() +{ + do_netsetup if [ "${NFSROOT}" = "auto" ] then NFSROOT=${ROOTSERVER}:${ROOTPATH} fi - if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount + rc=1 + + if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) then - rc=0 - return ${rc} + do_httpmount + return $? fi if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ] @@ -883,22 +704,76 @@ do_netmount () return ${rc} } +do_iscsi() +{ + do_netsetup + #modprobe ib_iser + modprobe iscsi_tcp + local debugopt="" + [ "${DEBUG}" == "Yes" ] && debugopt="-d 8" + #FIXME this name is supposed to be unique - some date + ifconfig hash? + ISCSI_INITIATORNAME="iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)" + export ISCSI_INITIATORNAME + if [ -n "${ISCSI_SERVER}" ] ; then + iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_SERVER}" -p "${ISCSI_PORT}" + else + iscsistart $debugopt -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -g 1 -a "${ISCSI_PORTAL}" -p 3260 + fi + if [ $? != 0 ] + then + panic "Failed to log into iscsi target" + fi + local host="$(ls -d /sys/class/scsi_host/host*/device/iscsi_host:host* \ + /sys/class/scsi_host/host*/device/iscsi_host/host* | sed -e 's:/device.*::' -e 's:.*host::')" + if [ -n "${host}" ] + then + local devices="" + local i=0 + while [ -z "${devices}" -a $i -lt 60 ] + do + sleep 1 + devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* \ + /sys/class/scsi_device/${host}*/device/block/* | sed -e 's!.*[:/]!!')" + i=$(expr $i + 1) + echo -ne $i\\r + done + for dev in $devices + do + if check_dev "null" "/dev/$dev" + then + NETBOOT="iscsi" + export NETBOOT + return 0; + fi + done + panic "Failed to locate a live device on iSCSI devices (tried: $devices)." + else + panic "Failed to locate iSCSI host in /sys" + fi +} + do_httpmount () { rc=1 - dest="${mountpoint}/${LIVE_MEDIA_PATH}" - mount -t ramfs ram "${mountpoint}" - mkdir -p "${dest}" for webfile in HTTPFS FTPFS FETCH do - url="$(eval echo \"\$\{${webfile}\}\")" - extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')" + local url="$(eval echo \"\$\{${webfile}\}\")" + local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')" if [ -n "$url" ] then case "${extension}" in - squashfs|tgz|tar) + iso|squashfs|tgz|tar) + if [ "${extension}" = "iso" ] + then + mkdir -p "${alt_mountpoint}" + dest="${alt_mountpoint}" + else + local dest="${mountpoint}/${LIVE_MEDIA_PATH}" + mount -t ramfs ram "${mountpoint}" + mkdir -p "${dest}" + fi if [ "${webfile}" = "FETCH" ] then case "$url" in @@ -926,9 +801,16 @@ do_httpmount () fi modprobe fuse $FUSE_MOUNT "${url}" "${dest}" + ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )" fi [ ${?} -eq 0 ] && rc=0 [ "${extension}" = "tgz" ] && live_dest="ram" + if [ "${extension}" = "iso" ] + then + isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '') + mount -t iso9660 "${isoloop}" "${mountpoint}" + rc=${?} + fi break ;; @@ -941,7 +823,15 @@ do_httpmount () if [ ${rc} != 0 ] then - umount "${mountpoint}" + if [ -d "${alt_mountpoint}" ] + then + umount "${alt_mountpoint}" + rmdir "${alt_mountpoint}" + fi + umount "${mountpoint}" + elif [ "${webfile}" != "FETCH" ] ; then + NETBOOT="${webfile}" + export NETBOOT fi return ${rc} @@ -1070,7 +960,7 @@ find_snap () try_snap () { # copy the contents of previously found snapshot to ${snap_mount} - # and remember the device and filename for resync on exit in live-initramfs.init + # and remember the device and filename for resync on exit in live-boot.init snapdata="${1}" snap_mount="${2}" @@ -1083,19 +973,20 @@ try_snap () snapback="$(echo ${snapdata} | cut -f2 -d ' ')" snapfile="$(echo ${snapdata} | cut -f3 -d ' ')" - RES="" if ! try_mount "${snapdev}" "${snapback}" "ro" then break fi + RES="0" + if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)' then # squashfs, jffs2 or ext2/ext3/ext4 snapshot dev=$(get_backing_device "${snapback}/${snapfile}") do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" - RES=$? + RES="$?" else # cpio.gz snapshot @@ -1111,9 +1002,12 @@ try_snap () 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) + cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null + RES="$?" + + if [ "${RES}" != "0" ] then - log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | cpio $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\"" + log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\"" fi fi @@ -1714,6 +1608,7 @@ find_livefs () fi done elif [ "${fstype}" = "squashfs" -o \ + "${fstype}" = "btrfs" -o \ "${fstype}" = "ext2" -o \ "${fstype}" = "ext3" -o \ "${fstype}" = "ext4" -o \ @@ -1721,7 +1616,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 @@ -1815,11 +1710,28 @@ mountroot () panic "Unable to find a live file system on the network" fi else - if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ] + if [ -n "${ISCSI_PORTAL}" ] + then + do_iscsi && livefs_root="${mountpoint}" + elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ] then # Do a local boot from hd livefs_root=${ROOT} else + if [ -x /usr/bin/memdiskfind ] + then + MEMDISK=$(/usr/bin/memdiskfind) + + if [ $? -eq 0 ] + then + # We found a memdisk, set up phram + modprobe phram phram=memdisk,${MEMDISK} + + # Load mtdblock, the memdisk will be /dev/mtdblock0 + modprobe mtdblock + fi + fi + # Scan local devices for the image i=0 while [ "$i" -lt 60 ] @@ -1880,6 +1792,11 @@ mountroot () mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}" fi + + if [ -n "${ROOT_PID}" ] ; then + echo "${ROOT_PID}" > "${rootmnt}"/live/root.pid + fi + log_end_msg # unionfs-fuse needs /dev to be bind-mounted for the duration of @@ -1889,27 +1806,12 @@ mountroot () mount -n -o bind /dev "${rootmnt}/dev" fi - # Open up two fifo's fd's for debconf-communicate to use. Speeds up - # the live-initramfs process considerably. - log_begin_msg "Creating debconf-communicate fifo mechanism" - mkfifo /tmp/debconf-in.fifo - mkfifo /tmp/debconf-out.fifo - - chroot /root debconf-communicate -fnoninteractive live-initramfs > /tmp/debconf-out.fifo < /tmp/debconf-in.fifo & - - # Save the PID so it can be killed later. - DEBCONF_COMMUNICATE_PID="$!" - - if [ ! -p /tmp/debconf-in.fifo ] || [ ! -p /tmp/debconf-out.fifo ] + # Move to the new root filesystem so that programs there can get at it. + if [ ! -d /root/live/image ] then - log_warning_msg "failed to setup debconf-communicate channel" + mkdir -p /root/live/image + mount --move /live/image /root/live/image fi - log_end_msg - - # Order matters! - # These file descriptors must stay open until we're finished with - # debconf-communicate. - exec 4/tmp/debconf-in.fifo maybe_break live-bottom log_begin_msg "Running /scripts/live-bottom\n" @@ -1922,17 +1824,8 @@ mountroot () umount "${rootmnt}/dev" fi - # Close the fd's associated with debconf-communicate - exec 3>&- 4<&- - rm -f /tmp/debconf-in.fifo - rm -f /tmp/debconf-out.fifo - 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 }