Adding upstream version 3.0~a14.
[live-boot-grml.git] / scripts / live
index d34279d..ef87d3c 100755 (executable)
@@ -102,9 +102,9 @@ Arguments ()
                                ;;
 
                        fetch=*)
-                                FETCH="${ARGUMENT#fetch=}"
-                                export FETCH
-                                ;;
+                               FETCH="${ARGUMENT#fetch=}"
+                               export FETCH
+                               ;;
 
                        forcepersistentfsck)
                                FORCEPERSISTENTFSCK="Yes"
@@ -119,7 +119,7 @@ Arguments ()
                        httpfs=*)
                                HTTPFS="${ARGUMENT#httpfs=}"
                                export HTTPFS
-                                ;;
+                               ;;
 
                        iscsi=*)
                                ISCSI="${ARGUMENT#iscsi=}"
@@ -230,6 +230,10 @@ Arguments ()
                                export NONETWORKING
                                ;;
 
+                       ramdisk-size=*)
+                               ramdisk_size="${ARGUMENT#ramdisk-size=}"
+                               ;;
+
                        swapon)
                                SWAPON="Yes"
                                export SWAPON
@@ -266,6 +270,16 @@ Arguments ()
                                export NOPERSISTENT
                                ;;
 
+                       noprompt)
+                               NOPROMPT="Yes"
+                               export NOPROMPT
+                               ;;
+
+                       noprompt=*)
+                               NOPROMPT="${ARGUMENT#noprompt=}"
+                               export NOPROMPT
+                               ;;
+
                        quickusbmodules)
                                QUICKUSBMODULES="Yes"
                                export QUICKUSBMODULES
@@ -325,9 +339,9 @@ Arguments ()
                                ;;
 
                        skipunion)
-                                SKIP_UNION_MOUNTS="Yes"
-                                export SKIP_UNION_MOUNTS
-                                ;;
+                               SKIP_UNION_MOUNTS="Yes"
+                               export SKIP_UNION_MOUNTS
+                               ;;
 
                        root=*)
                                ROOT="${ARGUMENT#root=}"
@@ -475,6 +489,9 @@ is_nice_device ()
        elif echo ${sysfs_path} | grep -q "^/block/dm-"
        then
                return 0
+       elif echo ${sysfs_path} | grep -q "^/block/mtdblock"
+       then
+               return 0
        fi
 
        return 1
@@ -529,6 +546,13 @@ copy_live_to ()
                return 1
        fi
 
+       # Custom ramdisk size
+       if [ -z "${mount_options}" ] && [ -n "${ramdisk_size}" ]
+       then
+               # FIXME: should check for wrong values
+               mount_options="-o size=${ramdisk_size}"
+       fi
+
        # begin copying (or uncompressing)
        mkdir "${copyto}"
        log_begin_msg "mount -t ${fstype} ${mount_options} ${dev} ${copyto}"
@@ -774,7 +798,7 @@ do_iscsi()
        [ "${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
+       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
@@ -957,6 +981,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
@@ -994,9 +1020,8 @@ do_snap_copy ()
 
                return 0
        else
-               return 1
-
                log_warning_msg "Unable to find the snapshot ${snap_type} medium"
+               return 1
        fi
 }
 
@@ -1004,28 +1029,39 @@ 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}"
 }
 
 try_snap ()
 {
-        # copy the contents of previously found snapshot to ${snap_mount}
+       # copy the contents of previously found snapshot to ${snap_mount}
        # and remember the device and filename for resync on exit in live-boot.init
 
        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
@@ -1063,8 +1099,16 @@ try_snap ()
                                cpioargs='--unconditional --make-directories'
                        fi
 
-                       cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | $cpiopath $cpioargs --extract --preserve-modification-time --no-absolute-filenames --sparse 2>/dev/null
-                       RES="$?"
+                       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
@@ -1096,7 +1140,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}" ]
@@ -1106,11 +1150,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
 }
 
@@ -1118,7 +1162,7 @@ setup_unionfs ()
 {
        image_directory="${1}"
        rootmnt="${2}"
-        addimage_directory="${3}"
+       addimage_directory="${3}"
 
        case ${UNIONTYPE} in
                aufs|unionfs)
@@ -1247,9 +1291,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
@@ -1363,6 +1414,9 @@ setup_unionfs ()
                cow_mountopt="rw,noatime,mode=755"
        fi
 
+       if [ "${UNIONTYPE}" != "unionmount" ]
+       then
+
        if [ "${cow_fstype}" = "nfs" ]
        then
                log_begin_msg \
@@ -1373,6 +1427,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)
 
@@ -1417,6 +1472,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}"
                                ;;
@@ -1448,7 +1507,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}" ]
@@ -1508,10 +1567,10 @@ check_dev ()
 
                if [ "$ISO_DEVICE" = "/" ]
                then
-                       echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live.log
+                       echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live-boot.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}"
@@ -1590,8 +1649,7 @@ find_livefs ()
                        do
                                if [ "$(cat ${sysblock}/removable)" = "1" ]
                                then
-                                       if readlink ${sysblock} | grep -q usb ||
-                                          readlink ${sysblock}/device | grep -q usb # linux < 2.6.29
+                                       if readlink ${sysblock} | grep -q usb
                                        then
                                                for dev in $(subdevices "${sysblock}")
                                                do
@@ -1715,15 +1773,15 @@ integrity_check ()
 
 mountroot ()
 {
-        if [ -x /scripts/local-top/cryptroot ]; then
+       if [ -x /scripts/local-top/cryptroot ]; then
            /scripts/local-top/cryptroot
        fi
 
        exec 6>&1
        exec 7>&2
-       exec > live.log
+       exec > live-boot.log
        exec 2>&1
-       tail -f live.log >&7 &
+       tail -f live-boot.log >&7 &
        tailpid="${!}"
 
        # Ensure 'panic' function is overridden
@@ -1857,6 +1915,18 @@ mountroot ()
        # 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"
 
@@ -1871,5 +1941,5 @@ mountroot ()
        exec 1>&6 6>&-
        exec 2>&7 7>&-
        kill ${tailpid}
-       [ -w "${rootmnt}/var/log/" ] && cp live.log "${rootmnt}/var/log/" 2>/dev/null
+       [ -w "${rootmnt}/var/log/" ] && cp live-boot.log "${rootmnt}/var/log/" 2>/dev/null
 }