Fixing fromiso= on Squeeze.
[live-boot-grml.git] / scripts / live
index d35fb08..d79beed 100755 (executable)
@@ -88,12 +88,8 @@ Arguments ()
 
                        ethdevice=*)
                                DEVICE="${ARGUMENT#ethdevice=}"
-                               export DEVICE
-                               ;;
-
-                       ethdevice=*)
-                               ETHDEVICE="${ARGUMENT#ethdevice=}"
-                               export ETHDEVICE
+                               ETHDEVICE="${DEVICE}"
+                               export DEVICE ETHDEVICE
                                ;;
 
                        ethdevice-timeout=*)
@@ -466,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]$'
@@ -643,6 +639,22 @@ do_netsetup ()
                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 && \
@@ -789,7 +801,7 @@ do_httpmount ()
                                                fi
                                                modprobe fuse
                                                $FUSE_MOUNT "${url}" "${dest}"
-                                               FUSE_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
+                                               ROOT_PID="$(minips h -C "$FUSE_MOUNT" | { read x y ; echo "$x" ; } )"
                                        fi
                                        [ ${?} -eq 0 ] && rc=0
                                        [ "${extension}" = "tgz" ] && live_dest="ram"
@@ -820,9 +832,6 @@ do_httpmount ()
        elif [ "${webfile}"  != "FETCH" ] ; then
                NETBOOT="${webfile}"
                export NETBOOT
-               if [ -n "${FUSE_PID}" ] ; then
-                       echo "${FUSE_PID}" > ${mountpoint}/root.pid
-               fi
        fi
 
        return ${rc}
@@ -887,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
@@ -924,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
 }
 
@@ -934,16 +944,17 @@ find_snap ()
 {
        # Look for ${snap_label}.* in block devices
        snap_label="${1}"
+       black_listed_devices="${2}"
 
        if [ "${PERSISTENT}" != "nofiles" ]
        then
                # search for image files
-               snapdata=$(find_files "${PERSISTENT_PATH}${snap_label}.squashfs ${PERSISTENT_PATH}${snap_label}.cpio.gz ${PERSISTENT_PATH}${snap_label}.ext2 ${PERSISTENT_PATH}${snap_label}.ext3 ${PERSISTENT_PATH}${snap_label}.ext4 ${PERSISTENT_PATH}${snap_label}.jffs2")
+               snapdata=$(find_files "${PERSISTENT_PATH}${snap_label}.squashfs ${PERSISTENT_PATH}${snap_label}.cpio.gz ${PERSISTENT_PATH}${snap_label}.ext2 ${PERSISTENT_PATH}${snap_label}.ext3 ${PERSISTENT_PATH}${snap_label}.ext4 ${PERSISTENT_PATH}${snap_label}.jffs2" "${black_listed_devices}")
        fi
 
        if [ -z "${snapdata}" ]
        then
-               snapdata=$(find_cow_device "${snap_label}")
+               snapdata=$(find_cow_device "${snap_label}" "${black_listed_devices}")
        fi
        echo "${snapdata}"
 }
@@ -956,6 +967,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
@@ -964,19 +985,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
 
@@ -992,7 +1014,18 @@ try_snap ()
                                cpioargs='--unconditional --make-directories'
                        fi
 
-                       if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null)
+                       if [ -s "${snapback}/${snapfile}" ]
+                       then
+                               BEFOREDIR="$(pwd)"
+                               cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
+                               RES="$?"
+                               cd "${BEFOREDIR}"
+                       else
+                               log_warning_msg "${snapback}/${snapfile} is empty, adding it for sync on reboot."
+                               RES="0"
+                       fi
+
+                       if [ "${RES}" != "0" ]
                        then
                                log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse\""
                        fi
@@ -1022,7 +1055,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}" ]
@@ -1032,11 +1065,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
 }
 
@@ -1173,9 +1206,16 @@ setup_unionfs ()
                                        log_warning_msg "Unknown file system type on ${backdev} (${image}), assuming ${fstype}."
                                fi
 
-                               mkdir -p "${croot}/${imagename}"
-                               log_begin_msg "Mounting \"${image}\" on \"${croot}${imagename}\" via \"${backdev}\""
-                               mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount ${backdev} (${image}) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
+                               if [ "${UNIONTYPE}" != "unionmount" ]
+                               then
+                                       mpoint="${croot}/${imagename}"
+                                       rofsstring="${mpoint}=${roopt}:${rofsstring}" && rofslist="${mpoint} ${rofslist}"
+                               else
+                                       mpoint="${rootmnt}"
+                               fi
+                               mkdir -p "${mpoint}"
+                               log_begin_msg "Mounting \"${image}\" on \"${mpoint}\" via \"${backdev}\""
+                               mount -t "${fstype}" -o ro,noatime "${backdev}" "${mpoint}" || panic "Can not mount ${backdev} (${image}) on ${mpoint}"
                                log_end_msg
                        fi
                done
@@ -1289,6 +1329,9 @@ setup_unionfs ()
                cow_mountopt="rw,noatime,mode=755"
        fi
 
+       if [ "${UNIONTYPE}" != "unionmount" ]
+       then
+
        if [ "${cow_fstype}" = "nfs" ]
        then
                log_begin_msg \
@@ -1299,6 +1342,7 @@ setup_unionfs ()
                mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || \
                        panic "Can not mount ${cowdevice} (o: ${cow_fstype}) on /cow"
        fi
+       fi
 
        rofscount=$(echo ${rofslist} |wc -w)
 
@@ -1343,6 +1387,10 @@ setup_unionfs ()
                                pidof unionfs-fuse >> /dev/.initramfs/varrun/sendsigs.omit || true
                                ;;
 
+                       unionmount)
+                               mount_full -t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice} "${rootmnt}" || panic "${UNIONTYPE} ${cowdevice} on ${rootmnt} failed with option noatime,union,${cow_mountopt}"
+                               ;;
+
                        *)
                                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}"
                                ;;
@@ -1374,7 +1422,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}" ]
@@ -1437,7 +1485,7 @@ check_dev ()
                        echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
                else
                        mkdir /isofrom
-                       mount "$ISO_DEVICE" /isofrom
+                       mount -t auto "$ISO_DEVICE" /isofrom
                        ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
                        loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
                        devname="${loopdevname}"
@@ -1595,6 +1643,7 @@ find_livefs ()
                                fi
                        done
                elif [ "${fstype}" = "squashfs" -o \
+                       "${fstype}" = "btrfs" -o \
                        "${fstype}" = "ext2" -o \
                        "${fstype}" = "ext3" -o \
                        "${fstype}" = "ext4" -o \
@@ -1612,16 +1661,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}"
@@ -1648,14 +1687,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
@@ -1674,9 +1705,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
@@ -1685,8 +1713,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
@@ -1778,6 +1804,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
@@ -1794,6 +1825,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"