Fixed some snapshot related debug messages.
[live-boot-grml.git] / scripts / live
index 3e604f6..169ffb4 100755 (executable)
@@ -51,14 +51,11 @@ Arguments ()
                case "${ARGUMENT}" in
                        skipconfig)
                                NOACCESSIBILITY="Yes"
-                               NOAUTOLOGIN="Yes"
-                               NOCONSOLEKEYBOARD="Yes"
                                NOFASTBOOT="Yes"
                                NOFSTAB="Yes"
                                NONETWORKING="Yes"
-                               NOXAUTOCONFIG="Yes"
 
-                               export NOACCESSIBILITY NOAUTOLOGIN NOCONSOLEKEYBOARD NOFASTBOOT NOFSTAB NONETWORKING NOXAUTOCONFIG
+                               export NOACCESSIBILITY NOFASTBOOT NOFSTAB NONETWORKING
                                ;;
 
                        access=*)
@@ -91,12 +88,8 @@ Arguments ()
 
                        ethdevice=*)
                                DEVICE="${ARGUMENT#ethdevice=}"
-                               export DEVICE
-                               ;;
-
-                       ethdevice=*)
-                               ETHDEVICE="${ARGUMENT#ethdevice=}"
-                               export ETHDEVICE
+                               ETHDEVICE="${DEVICE}"
+                               export DEVICE ETHDEVICE
                                ;;
 
                        ethdevice-timeout=*)
@@ -122,6 +115,19 @@ Arguments ()
                        httpfs=*)
                                HTTPFS="${ARGUMENT#httpfs=}"
                                export HTTPFS
+                                ;;
+
+                       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=*)
@@ -150,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
@@ -230,16 +211,6 @@ Arguments ()
                                export NOACCESSIBILITY
                                ;;
 
-                       noautologin)
-                               NOAUTOLOGIN="Yes"
-                               export NOAUTOLOGIN
-                               ;;
-
-                       noconsolekeyboard)
-                               NOCONSOLEKEYBOARD="Yes"
-                               export NOCONSOLEKEYBOARD
-                               ;;
-
                        nofastboot)
                                NOFASTBOOT="Yes"
                                export NOFASTBOOT
@@ -260,11 +231,6 @@ Arguments ()
                                export SWAPON
                                ;;
 
-                       noxautoconfig)
-                               NOXAUTOCONFIG="Yes"
-                               export NOXAUTOCONFIG
-                               ;;
-
                        persistent)
                                PERSISTENT="Yes"
                                export PERSISTENT
@@ -368,21 +334,6 @@ Arguments ()
                                UNIONTYPE="${ARGUMENT#union=}"
                                export UNIONTYPE
                                ;;
-
-                       xdebconf)
-                               XDEBCONF="Yes"
-                               export XDEBCONF
-                               ;;
-
-                       xdriver=*)
-                               XDRIVER="${ARGUMENT#xdriver=}"
-                               export XDRIVER
-                               ;;
-
-                       xvideomode=*)
-                               XVIDEOMODE="${ARGUMENT#xvideomode=}"
-                               export XVIDEOMODE
-                               ;;
                esac
        done
 
@@ -511,7 +462,7 @@ is_nice_device ()
 {
        sysfs_path="${1#/sys}"
 
-       if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
+       if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci|)"
        then
                return 0
        elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$'
@@ -619,7 +570,7 @@ copy_live_to ()
        return 0
 }
 
-do_netmount ()
+do_netsetup ()
 {
        modprobe -q af_packet # For DHCP
 
@@ -683,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 && \
@@ -692,6 +664,11 @@ 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
@@ -727,6 +704,54 @@ 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
@@ -776,6 +801,7 @@ 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"
@@ -870,6 +896,8 @@ do_snap_copy ()
 
        if [ -b "${fromdev}" ]
        then
+               log_success_msg "Copying snapshot ${fromdev} to ${todir}..."
+
                # look for free mem
                if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]
                then
@@ -907,9 +935,8 @@ do_snap_copy ()
 
                return 0
        else
-               return 1
-
                log_warning_msg "Unable to find the snapshot ${snap_type} medium"
+               return 1
        fi
 }
 
@@ -939,6 +966,16 @@ try_snap ()
        snapdata="${1}"
        snap_mount="${2}"
        snap_type="${3}"
+       snap_relpath="${4}"
+
+       if [ -z "${snap_relpath}" ]
+       then
+               # root snapshot, default usage
+               snap_relpath="/"
+       else
+               # relative snapshot (actually used just for "/home" snapshots)
+               snap_mount="${2}${snap_relpath}"
+       fi
 
        if [ -n "${snapdata}" ] && [ ! -b "${snapdata}" ]
        then
@@ -947,19 +984,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
 
@@ -975,9 +1013,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
 
@@ -1005,7 +1046,7 @@ try_snap ()
 
                if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
                then
-                       log_warning_msg "Impossible to include the ${snap_type} Snapshot"
+                       log_warning_msg "Impossible to include the ${snap_type} Snapshot (i)"
                        return 1
                else
                        if [ -n "${snapfile}" ]
@@ -1015,11 +1056,11 @@ try_snap ()
                        fi
                fi
        else
-               log_warning_msg "Impossible to include the ${snap_type} Snapshot"
+               log_warning_msg "Impossible to include the ${snap_type} Snapshot (o)"
                return 1
        fi
 
-       echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
+       echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
        return 0
 }
 
@@ -1357,7 +1398,7 @@ setup_unionfs ()
                # Look for other snapshots to copy in
                try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
                # This second type should be removed when snapshot grow smarter
-               try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
+               try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
        fi
 
        if [ -n "${SHOWMOUNTS}" ]
@@ -1578,6 +1619,7 @@ find_livefs ()
                                fi
                        done
                elif [ "${fstype}" = "squashfs" -o \
+                       "${fstype}" = "btrfs" -o \
                        "${fstype}" = "ext2" -o \
                        "${fstype}" = "ext3" -o \
                        "${fstype}" = "ext4" -o \
@@ -1595,16 +1637,6 @@ find_livefs ()
        return 1
 }
 
-set_usplash_timeout ()
-{
-       if [ -x /sbin/usplash_write ]
-       then
-               /sbin/usplash_write "TIMEOUT 120"
-       else if [ -x /sbin/splashy_update ] ; then
-               /sbin/splashy_update "TIMEOUT 120"
-       fi ; fi
-}
-
 integrity_check ()
 {
        media_mountpoint="${1}"
@@ -1631,14 +1663,6 @@ 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
@@ -1657,9 +1681,6 @@ mountroot ()
 
        Arguments
 
-       set_usplash_timeout
-       start_usplash_pulse
-
        maybe_break live-premount
        log_begin_msg "Running /scripts/live-premount"
        run_scripts /scripts/live-premount
@@ -1668,8 +1689,6 @@ mountroot ()
        # Needed here too because some things (*cough* udev *cough*)
        # changes the timeout
 
-       set_usplash_timeout
-
        if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
        then
                if do_netmount
@@ -1679,11 +1698,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 ]
@@ -1744,6 +1780,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
@@ -1760,6 +1801,24 @@ mountroot ()
                mount --move /live/image /root/live/image
        fi
 
+       # aufs2 in kernel versions around 2.6.33 has a regression:
+       # directories can't be accessed when read for the first the time,
+       # causing a failure for example when accessing /var/lib/fai
+       # when booting FAI, this simple workaround solves it
+       ls /root/* >/dev/null 2>&1
+
+       # copy snapshot configuration if exists
+       if [ -f snapshot.conf ]
+       then
+               log_begin_msg "Copying snapshot.conf to ${rootmnt}/etc/live/boot.d"
+               if [ ! -d "${rootmnt}/etc/live/boot.d" ]
+               then
+                       mkdir -p "${rootmnt}/etc/live/boot.d"
+               fi
+               cp snapshot.conf "${rootmnt}/etc/live/boot.d/"
+               log_end_msg
+       fi
+
        maybe_break live-bottom
        log_begin_msg "Running /scripts/live-bottom\n"