Merge remote-tracking branch 'upstream/master'
[live-boot-grml.git] / components / 9990-misc-helpers.sh
index 6522682..ef3688e 100755 (executable)
@@ -131,6 +131,7 @@ is_nice_device ()
 
 check_dev ()
 {
+       local force fix
        sysdev="${1}"
        devname="${2}"
        skip_uuid_check="${3}"
@@ -155,15 +156,32 @@ check_dev ()
 
                if [ "$ISO_DEVICE" = "/" ]
                then
-                       echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
+                       # not a block device, check if it's an iso file, for
+                       # example an ISO when booting on an ONIE system
+                       if echo "${FROMISO}" | grep -q "\.iso$"
+                       then
+                               fs_type=$(get_fstype "${FROMISO}")
+                               if is_supported_fs ${fs_type}
+                               then
+                                       mkdir /run/live/fromiso
+                                       mount -t $fs_type "${FROMISO}" /run/live/fromiso
+                                       if [ "$?" != 0 ]
+                                       then
+                                               echo "Warning: unable to mount ${FROMISO}." >>/boot.log
+                                       fi
+                                       devname="/run/live/fromiso"
+                               fi
+                       else
+                               echo "Warning: device for bootoption fromiso= ($FROMISO) not found.">>/boot.log
+                       fi
                else
                        fs_type=$(get_fstype "${ISO_DEVICE}")
                        if is_supported_fs ${fs_type}
                        then
-                               mkdir /live/fromiso
-                               mount -t $fs_type "$ISO_DEVICE" /live/fromiso
+                               mkdir /run/live/fromiso
+                               mount -t $fs_type "$ISO_DEVICE" /run/live/fromiso
                                ISO_NAME="$(echo $FROMISO | sed "s|$ISO_DEVICE||")"
-                               loopdevname=$(setup_loop "/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
+                               loopdevname=$(setup_loop "/run/live/fromiso/${ISO_NAME}" "loop" "/sys/block/loop*" "" '')
                                devname="${loopdevname}"
                        else
                                echo "Warning: unable to mount $ISO_DEVICE." >>/boot.log
@@ -231,6 +249,33 @@ check_dev ()
        then
                devuid=$(blkid -o value -s UUID "$devname")
                [ -n "$devuid" ] && grep -qs "\<$devuid\>" /var/lib/live/boot/devices-already-tried-to-mount && continue
+
+               for _PARAMETER in ${LIVE_BOOT_CMDLINE}
+               do
+                       case "${_PARAMETER}" in
+                               forcefsck)
+                                       FORCEFSCK="true"
+                                       ;;
+                       esac
+               done
+
+               if [ "${PERSISTENCE_FSCK}" = "true" ] ||  [ "${PERSISTENCE_FSCK}" = "yes" ] || [ "${FORCEFSCK}" = "true" ]
+               then
+                       force=""
+                       if [ "$FORCEFSCK" = "true" ]
+                       then
+                               force="-f"
+                       fi
+
+                       fix="-a"
+                       if [ "$FSCKFIX" = "true" ] || [ "$FSCKFIX" = "yes" ]
+                       then
+                               fix="-y"
+                       fi
+
+                       fsck $fix $force ${devname} >> fsck.log 2>&1
+               fi
+
                mount -t ${fstype} -o ro,noatime "${devname}" ${mountpoint} || continue
                [ -n "$devuid" ] && echo "$devuid" >> /var/lib/live/boot/devices-already-tried-to-mount
 
@@ -239,9 +284,9 @@ check_dev ()
                        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 "")
+                               mkdir -p /run/live/findiso
+                               mount -t ${fstype} -o ro,noatime "${devname}" /run/live/findiso
+                               loopdevname=$(setup_loop "/run/live/findiso/${FINDISO}" "loop" "/sys/block/loop*" 0 "")
                                devname="${loopdevname}"
                                mount -t iso9660 -o ro,noatime "${devname}" ${mountpoint}
                        else
@@ -726,7 +771,7 @@ mount_persistence_media ()
 
        # get_custom_mounts() might call this with a directory path instead
        # of a block device path. This means we have found sub-directory path
-       # underneath /lib/live/mounts/persistence, so we're done
+       # underneath /run/live/persistence, so we're done
        if [ -d "${device}" ]
        then
                echo "${device}"
@@ -738,7 +783,7 @@ mount_persistence_media ()
                return 1
        fi
 
-       backing="/live/persistence/$(basename ${device})"
+       backing="/run/live/persistence/$(basename ${device})"
 
        mkdir -p "${backing}"
        old_backing="$(where_is_mounted ${device})"
@@ -1049,7 +1094,7 @@ find_persistence_media ()
        # in one union together.
        #
        black_listed_devices=""
-       for d in /live/rootfs/* /live/findiso /live/fromiso
+       for d in /run/live/rootfs/* /run/live/findiso /run/live/fromiso
        do
                black_listed_devices="${black_listed_devices} $(what_is_mounted_on d)"
        done
@@ -1364,7 +1409,7 @@ do_union ()
 
 get_custom_mounts ()
 {
-       # Side-effect: leaves $devices with persistence.conf mounted in /live/persistence
+       # Side-effect: leaves $devices with persistence.conf mounted in /run/live/persistence
        # Side-effect: prints info to file $custom_mounts
 
        local custom_mounts devices bindings links
@@ -1395,7 +1440,7 @@ get_custom_mounts ()
 
                if [ -n "${LIVE_BOOT_DEBUG}" ] && [ -e "${include_list}" ]
                then
-                       cp ${include_list} /live/persistence/${persistence_list}.${device_name}
+                       cp ${include_list} /run/live/persistence/${persistence_list}.${device_name}
                fi
 
                while read dir options # < ${include_list}
@@ -1406,9 +1451,9 @@ get_custom_mounts ()
                                continue
                        fi
 
-                       if trim_path ${dir} | grep -q -e "^[^/]" -e "^/lib" -e "^/lib/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
+                       if trim_path ${dir} | grep -q -e "^[^/]" -e "^/lib" -e "^/run/live\(/.*\)\?$" -e "^/\(.*/\)\?\.\.\?\(/.*\)\?$"
                        then
-                               log_warning_msg "Skipping unsafe custom mount ${dir}: must be an absolute path containing neither the \".\" nor \"..\" special dirs, and cannot be \"/lib\", or \"/lib/live\" or any of its sub-directories."
+                               log_warning_msg "Skipping unsafe custom mount ${dir}: must be an absolute path containing neither the \".\" nor \"..\" special dirs, and cannot be \"/lib\", or \"/run/live\" or any of its sub-directories."
                                continue
                        fi
 
@@ -1580,7 +1625,7 @@ activate_custom_mounts ()
                rootfs_dest_backing=""
                if [ -n "${opt_link}" ] || [ -n "${opt_union}" ]
                then
-                       for d in /live/rootfs/*
+                       for d in /run/live/rootfs/*
                        do
                                if [ -n "${rootmnt}" ]
                                then
@@ -1598,11 +1643,11 @@ activate_custom_mounts ()
                local cow_dir links_source
                if [ -n "${opt_link}" ] && [ -z "${PERSISTENCE_READONLY}" ]
                then
-                       link_files ${source} ${dest} "s|^/live/|/lib/live/mount/|"
+                       link_files ${source} ${dest} ""
                elif [ -n "${opt_link}" ] && [ -n "${PERSISTENCE_READONLY}" ]
                then
-                       mkdir -p ${rootmnt}/lib/live/mount/persistence
-                       links_source=$(mktemp -d ${rootmnt}/lib/live/mount/persistence/links-source-XXXXXX)
+                       mkdir -p /run/live/persistence
+                       links_source=$(mktemp -d /run/live/persistence/links-source-XXXXXX)
                        chown_ref ${source} ${links_source}
                        chmod_ref ${source} ${links_source}
                        # We put the cow dir in the below strange place to
@@ -1610,7 +1655,7 @@ activate_custom_mounts ()
                        # has its own directory and isn't nested with some
                        # other custom mount (if so that mount's files would
                        # be linked, causing breakage.
-                       cow_dir="/live/overlay/lib/live/mount/persistence/$(basename ${links_source})"
+                       cow_dir="/run/live/overlay/run/live/persistence/$(basename ${links_source})"
                        mkdir -p ${cow_dir}
                        chown_ref "${source}" "${cow_dir}"
                        chmod_ref "${source}" "${cow_dir}"
@@ -1627,7 +1672,7 @@ activate_custom_mounts ()
                        # bind-mount and union mount are handled the same
                        # in read-only mode, but note that rootfs_dest_backing
                        # is non-empty (and necessary) only for unions
-                       cow_dir="/live/overlay/${dest}"
+                       cow_dir="/run/live/overlay/${dest}"
                        if [ -e "${cow_dir}" ] && [ -z "${opt_link}" ]
                        then
                                # If an earlier custom mount has files here
@@ -1638,6 +1683,13 @@ activate_custom_mounts ()
                        mkdir -p ${cow_dir}
                        chown_ref "${source}" "${cow_dir}"
                        chmod_ref "${source}" "${cow_dir}"
+                       if [ "${UNIONTYPE}" = "overlay" ]
+                       then
+                               # When we use overlay we add the "/rw" postfix to our source when using it
+                               # as upper layer. Therefore we also have to add it here when using it as
+                               # the lower layer.
+                               source="${source}/rw"
+                       fi
                        do_union ${dest} ${cow_dir} ${source} ${rootfs_dest_backing}
                fi