Adding upstream version 3.0~a28.
[live-boot-grml.git] / scripts / live
index e248937..83114a2 100755 (executable)
@@ -11,8 +11,6 @@ mountpoint="/live/image"
 alt_mountpoint="/media"
 LIVE_MEDIA_PATH="live"
 
-USERNAME="user"
-USERFULLNAME="Live user"
 HOSTNAME="host"
 
 mkdir -p "${mountpoint}"
@@ -342,7 +340,7 @@ do_netsetup ()
        done
 
        # 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
+       # an endless loop; if 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"
@@ -355,7 +353,7 @@ do_netsetup ()
                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
+               # IP address, if so let's use the device 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"
@@ -801,7 +799,7 @@ try_snap ()
                return 1
        fi
 
-       if [ -z ${PERSISTENT_READONLY} ]
+       if [ -z ${PERSISTENCE_READONLY} ]
        then
                echo "export ${snap_type}SNAP=${snap_relpath}:${snapdev}:${snapfile}" >> snapshot.conf # for resync on reboot/halt
        fi
@@ -954,10 +952,14 @@ setup_unionfs ()
                log_end_msg
        fi
 
-       mkdir -p /cow
+       # tmpfs file systems
+       touch /etc/fstab
+       mkdir -p /live
+       mount -t tmpfs tmpfs /live
+       mkdir -p /live/overlay
 
-       # Looking for persistent devices or files
-       if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
+       # Looking for persistence devices or files
+       if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
        then
 
                if [ -z "${QUICKUSBMODULES}" ]
@@ -987,7 +989,7 @@ setup_unionfs ()
                        done
                fi
 
-               case "${PERSISTENT_MEDIA}" in
+               case "${PERSISTENCE_MEDIA}" in
                        removable)
                                whitelistdev="$(removable_dev)"
                                ;;
@@ -999,21 +1001,20 @@ setup_unionfs ()
                                ;;
                esac
 
-               if echo ${PERSISTENT_METHOD} | grep -qe "\<overlay\>"
+               if is_in_comma_sep_list overlay ${PERSISTENCE_METHOD}
                then
-                       overlays="${root_overlay_label} ${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}"
+                       overlays="${old_root_overlay_label} ${old_home_overlay_label} ${custom_overlay_label}"
                fi
 
-               if echo ${PERSISTENT_METHOD} | grep -qe "\<snapshot\>"
+               if is_in_comma_sep_list snapshot ${PERSISTENCE_METHOD}
                then
                        snapshots="${root_snapshot_label} ${home_snapshot_label}"
                fi
 
                local root_snapdata=""
-               local home_snapshot_label=""
-               local root_overlay_label=""
+               local home_snapdata=""
                local overlay_devices=""
-               for media in $(find_persistent_media "${overlays}" "${snapshots}" "${whitelistdev}")
+               for media in $(find_persistence_media "${overlays}" "${snapshots}" "${whitelistdev}")
                do
                        media="$(echo ${media} | tr ":" " ")"
                        case ${media} in
@@ -1032,16 +1033,14 @@ setup_unionfs ()
                                                home_snapdata="${media#*=}"
                                        fi
                                        ;;
-                               ${root_overlay_label}=*|${old_root_overlay_label}=*)
-                                       if [ -z "${root_overlay_device}" ]
-                                       then
-                                               device="${media#*=}"
-                                               root_overlay_device="${device}"
-                                       fi
+                               ${old_root_overlay_label}=*)
+                                       device="${media#*=}"
+                                       fix_backwards_compatibility ${device} / union
+                                       overlay_devices="${overlay_devices} ${device}"
                                        ;;
                                ${old_home_overlay_label}=*)
                                        device="${media#*=}"
-                                       fix_home_rw_compatibility ${device}
+                                       fix_backwards_compatibility ${device} /home bind
                                        overlay_devices="${overlay_devices} ${device}"
                                        ;;
                                ${custom_overlay_label}=*)
@@ -1050,27 +1049,7 @@ setup_unionfs ()
                                        ;;
                         esac
                done
-
-               if [ -b "${root_overlay_device}" ]
-               then
-                       PERSISTENCE_IS_ON="1"
-                       export PERSISTENCE_IS_ON
-
-                       cowdevice=${root_overlay_device}
-                       cow_fstype=$(get_fstype "${root_overlay_device}")
-                       if [ -z "${PERSISTENT_READONLY}" ]
-                       then
-                               cow_mountopt="rw,noatime"
-                       else
-                               cow_mountopt="ro,noatime"
-                       fi
-
-                       if [ "${FORCEPERSISTENTFSCK}" = "Yes" ]
-                       then
-                               fsck -y ${cowdevice}
-                       fi
-               fi
-       elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENT}" ]
+       elif [ -n "${NFS_COW}" ] && [ -z "${NOPERSISTENCE}" ]
        then
                # check if there are any nfs options
                if echo ${NFS_COW}|grep -q ','
@@ -1082,7 +1061,7 @@ setup_unionfs ()
                        nfs_cow=${NFS_COW}
                fi
 
-               if [ -n "${PERSISTENT_READONLY}" ]
+               if [ -n "${PERSISTENCE_READONLY}" ]
                then
                        nfs_cow_opts="${nfs_cow_opts},nocto,ro"
                fi
@@ -1106,13 +1085,13 @@ setup_unionfs ()
 
        if [ "${UNIONTYPE}" != "unionmount" ]
        then
-               if [ -n "${PERSISTENT_READONLY}" ]
+               if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
                then
-                       mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/cow"
-                       root_backing="${rootmnt}/live/persistent/$(basename ${cowdevice})-root"
+                       mount -t tmpfs -o rw,noatime,mode=755 tmpfs "/live/overlay"
+                       root_backing="/live/persistence/$(basename ${cowdevice})-root"
                        mkdir -p ${root_backing}
                else
-                       root_backing="/cow"
+                       root_backing="/live/overlay"
                fi
 
                if [ "${cow_fstype}" = "nfs" ]
@@ -1129,15 +1108,15 @@ setup_unionfs ()
 
        rofscount=$(echo ${rofslist} |wc -w)
 
-       # XXX: we now ensure that there can only be one read-only filesystem. Should this be inside the EXPOSED_ROOT if?
-       if [ ${rofscount} -ne 1 ]
-       then
-               panic "only one RO file system supported with exposedroot: ${rofslist}"
-       fi
        rofs=${rofslist%% }
 
        if [ -n "${EXPOSED_ROOT}" ]
        then
+               if [ ${rofscount} -ne 1 ]
+               then
+                       panic "only one RO file system supported with exposedroot: ${rofslist}"
+               fi
+
                mount --bind ${rofs} ${rootmnt} || \
                        panic "bind mount of ${rofs} failed"
 
@@ -1162,16 +1141,15 @@ setup_unionfs ()
                mkdir -p ${unionmountpoint}
                if [ "${UNIONTYPE}" = "unionmount" ]
                then
-                       # FIXME: handle PERSISTENT_READONLY
+                       # FIXME: handle PERSISTENCE_READONLY
                        unionmountopts="-t ${cow_fstype} -o noatime,union,${cow_mountopt} ${cowdevice}"
                        mount_full $unionmountopts "${unionmountpoint}"
                else
-                       cow_dir="/cow${dir}"
+                       cow_dir="/live/overlay${dir}"
                        rofs_dir="${rofs}${dir}"
                        mkdir -p ${cow_dir}
-                       if [ -n "${PERSISTENT_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
+                       if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
                        then
-                               #mount -t tmpfs -o rw,noatime,mode=755 tmpfs "${cow_dir}"
                                do_union ${unionmountpoint} ${cow_dir} ${root_backing} ${rofs_dir}
                        else
                                do_union ${unionmountpoint} ${cow_dir} ${rofs_dir}
@@ -1182,20 +1160,15 @@ setup_unionfs ()
        # Correct the permissions of /:
        chmod 0755 "${rootmnt}"
 
-       # tmpfs file systems
-       touch /etc/fstab
-       mkdir -p "${rootmnt}/live"
-       mount -t tmpfs tmpfs ${rootmnt}/live
-
        live_rofs_list=""
        # SHOWMOUNTS is necessary for custom mounts with the union option
        # Since we may want to do custom mounts in user-space it's best to always enable SHOWMOUNTS
-       if true #[ -n "${SHOWMOUNTS}" ] || ( [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ] 1)
+       if true #[ -n "${SHOWMOUNTS}" ] || ( [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ] 1)
        then
                # XXX: is the for loop really necessary? rofslist can only contain one item (see above XXX about EXPOSEDROOT) and this is also assumed elsewhere above (see use of $rofs above).
                for d in ${rofslist}
                do
-                       live_rofs="${rootmnt}/live/rofs/${d##*/}"
+                       live_rofs="/live/rofs/${d##*/}"
                        live_rofs_list="${live_rofs_list} ${live_rofs}"
                        mkdir -p "${live_rofs}"
                        case d in
@@ -1216,8 +1189,8 @@ setup_unionfs ()
                done
        fi
 
-       # Adding custom persistent
-       if [ -n "${PERSISTENT}" ] && [ -z "${NOPERSISTENT}" ]
+       # Adding custom persistence
+       if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
        then
                local custom_mounts="/tmp/custom_mounts.list"
                rm -rf ${custom_mounts} 2> /dev/null
@@ -1225,7 +1198,7 @@ setup_unionfs ()
                # Gather information about custom mounts from devies detected as overlays
                get_custom_mounts ${custom_mounts} ${overlay_devices}
 
-               [ -n "${DEBUG}" ] && cp ${custom_mounts} "${rootmnt}/live/persistent"
+               [ -n "${DEBUG}" ] && cp ${custom_mounts} "/live/persistence"
 
                # Now we do the actual mounting (and symlinking)
                local used_overlays=""
@@ -1237,19 +1210,23 @@ setup_unionfs ()
                do
                        if echo ${used_overlays} | grep -qve "^\(.* \)\?${device}\( .*\)\?$"
                        then
-                               close_persistent_media ${overlay}
+                               close_persistence_media ${overlay}
                        fi
                done
 
                # Look for other snapshots to copy in
-               try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
+               [ -n "${root_snapdata}" ] && try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
                # This second type should be removed when snapshot grow smarter
-               try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
+               [ -n "${home_snapdata}" ] && try_snap "${home_snapdata}" "${rootmnt}" "HOME" "/home"
        fi
 
-       # shows cow fs on /cow for use by live-snapshot
-       mkdir -p "${rootmnt}/live/cow"
-       mount -o move /cow "${rootmnt}/live/cow" >/dev/null 2>&1 || mount -o bind /cow "${rootmnt}/live/cow" || log_warning_msg "Unable to move or bind /cow to ${rootmnt}/live/cow"
+       mkdir -p "${rootmnt}/live"
+       mount -o move /live "${rootmnt}/live" >/dev/null 2>&1 || mount -o bind /live "${rootmnt}/live" || log_warning_msg "Unable to move or bind /live to ${rootmnt}/live"
+
+       # shows cow fs on /overlay for use by live-snapshot
+       mkdir -p "${rootmnt}/live/overlay"
+       mount -o move /live/overlay "${rootmnt}/live/overlay" >/dev/null 2>&1 || mount -o bind /overlay "${rootmnt}/live/overlay" || log_warning_msg "Unable to move or bind /overlay to ${rootmnt}/live/overlay"
+
 }
 
 check_dev ()
@@ -1278,18 +1255,18 @@ check_dev ()
 
                if [ "$ISO_DEVICE" = "/" ]
                then
-                       echo "Warning: device for bootoption isofrom= ($FROMISO) not found.">>/live-boot.log
+                       echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
                else
                        fs_type=$(get_fstype "${ISO_DEVICE}")
                        if is_supported_fs ${fs_type}
                        then
-                               mkdir /isofrom
-                               mount -t $fs_type "$ISO_DEVICE" /isofrom
+                               mkdir /live/fromiso
+                               mount -t $fs_type "$ISO_DEVICE" /live/fromiso
                                ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
-                               loopdevname=$(setup_loop "/isofrom/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
+                               loopdevname=$(setup_loop "/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
                                devname="${loopdevname}"
                        else
-                               echo "Warning: unable to mount $ISO_DEVICE." >>/live-boot.log
+                               echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log
                        fi
                fi
        fi
@@ -1357,6 +1334,21 @@ check_dev ()
                mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
                [ -n "$devuid" ] && echo "$devuid" >> $tried
 
+               if [ -n "${FINDISO}" ]
+               then
+                       if [ -f ${mountpoint}/${FINDISO} ]
+                       then
+                               umount ${mountpoint}
+                               mkdir -p /live/findiso
+                               mount -t ${fstype} -o ro,noatime "${devname}" /live/findiso
+                               loopdevname=$(setup_loop "/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
+                               devname="${loopdevname}"
+                               mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint}
+                       else
+                               umount ${mountpoint}
+                       fi
+               fi
+
                if is_live_path ${mountpoint} && \
                        ([ "${skip_uuid_check}" ] || matches_uuid ${mountpoint})
                then
@@ -1507,9 +1499,9 @@ mountroot ()
 
        exec 6>&1
        exec 7>&2
-       exec > live-boot.log
+       exec > boot.log
        exec 2>&1
-       tail -f live-boot.log >&7 &
+       tail -f boot.log >&7 &
        tailpid="${!}"
 
        # Ensure 'panic' function is overridden
@@ -1603,8 +1595,14 @@ mountroot ()
        # rid of it when running from RAM
        if [ -n "$FROMISO" ] && [ "${TORAM}" ]
        then
-         losetup -d /dev/loop0
-         grep -q /isofrom /proc/mounts && umount /isofrom
+               losetup -d /dev/loop0
+
+               if is_mountpoint /live/fromiso
+               then
+                       umount /live/fromiso
+                       rmdir --ignore-fail-on-non-empty /live/fromiso \
+                               >/dev/null 2>&1 || true
+               fi
        fi
 
        if [ -n "${MODULETORAMFILE}" ] || [ -n "${PLAIN_ROOT}" ]
@@ -1643,6 +1641,28 @@ mountroot ()
        # when booting FAI, this simple workaround solves it
        ls /root/* >/dev/null 2>&1
 
+       # Move findiso directory to the new root filesystem so that programs there can get at it.
+       if [ -d /live/findiso ] && [ ! -d /root/live/findiso ]
+       then
+               mkdir -p /root/live/findiso
+               mount -n --move /live/findiso /root/live/findiso
+       fi
+
+       # if we do not unmount the ISO we can't run "fsck /dev/ice" later on
+       # because the mountpoint is left behind in /proc/mounts, so let's get
+       # rid of it when running from RAM
+       if [ -n "$FINDISO" ] && [ "${TORAM}" ]
+       then
+               losetup -d /dev/loop0
+
+               if is_mountpoint /root/live/findiso
+               then
+                       umount /root/live/findiso
+                       rmdir --ignore-fail-on-non-empty /root/live/findiso \
+                               >/dev/null 2>&1 || true
+               fi
+       fi
+
        # copy snapshot configuration if exists
        if [ -f snapshot.conf ]
        then
@@ -1676,5 +1696,5 @@ mountroot ()
        exec 1>&6 6>&-
        exec 2>&7 7>&-
        kill ${tailpid}
-       [ -w "${rootmnt}/var/log/" ] && cp live-boot.log "${rootmnt}/var/log/" 2>/dev/null
+       [ -w "${rootmnt}/var/log/" ] && mkdir -p /var/log/live && cp boot.log "${rootmnt}/var/log/live" 2>/dev/null
 }