X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=components%2F9990-misc-helpers.sh;h=c656f2380618c922b1c5aee8673cb7f576ae5ba2;hb=130f0d741827ba9fef3a02cc25e4ea3b619a4352;hp=c502d599bf1bac57c00f8293e5603da31c430343;hpb=608d41f64972697b7389678d63d1391daa2fab42;p=live-boot-grml.git diff --git a/components/9990-misc-helpers.sh b/components/9990-misc-helpers.sh index c502d59..c656f23 100755 --- a/components/9990-misc-helpers.sh +++ b/components/9990-misc-helpers.sh @@ -76,7 +76,7 @@ is_nice_device () { sysfs_path="${1#/sys}" - if udevadm test-builtin path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-[^-]*-(ide|sas|scsi|usb|virtio)|platform-sata_mv|platform-orion-ehci|platform-mmc|platform-mxsdhci)" + if udevadm info --query=all --path="${sysfs_path}" | egrep -q "DEVTYPE=disk" then return 0 elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$' @@ -161,7 +161,7 @@ check_dev () # Adding lvm support if [ -x /scripts/local-top/lvm2 ] then - ROOT="$device" resume="" /scripts/local-top/lvm2 + ROOT="$device" resume="" /scripts/local-top/lvm2 >>/boot.log fi ;; @@ -169,10 +169,10 @@ check_dev () # Adding raid support if [ -x /scripts/local-top/mdadm ] then - cp /conf/conf.d/md /conf/conf.d/md.orig + [ -r /conf/conf.d/md ] && cp /conf/conf.d/md /conf/conf.d/md.orig echo "MD_DEVS=$device " >> /conf/conf.d/md - /scripts/local-top/mdadm - mv /conf/conf.d/md.orig /conf/conf.d/md + /scripts/local-top/mdadm >>/boot.log + [ -r /conf/conf.d/md.orig ] && mv /conf/conf.d/md.orig /conf/conf.d/md fi ;; esac @@ -684,8 +684,9 @@ try_mount () } # Try to mount $device to the place expected by live-boot. If $device -# is already mounted somewhere, move it to the expected place. If -# we're only probing $device (to check if it has custom persistence) +# is already mounted somewhere, move it to the expected place. If $device +# ends with a "/" this is a directory path. +# If we're only probing $device (to check if it has custom persistence) # $probe should be set, which suppresses warnings upon failure. On # success, print the mount point for $device. mount_persistence_media () @@ -694,6 +695,15 @@ mount_persistence_media () device=${1} probe=${2} + # 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 + if [ -d "${device}" ] + then + echo "${device}" + return 0 + fi + if [ ! -b "${device}" ] then return 1 @@ -722,15 +732,24 @@ mount_persistence_media () fi elif [ "${backing}" != "${old_backing}" ] then - if mount --move ${old_backing} ${backing} >/dev/null + if ! mount --move ${old_backing} ${backing} >/dev/null then - echo ${backing} - return 0 - else [ -z "${probe}" ] && log_warning_msg "Failed to move persistence media ${device}" rmdir "${backing}" return 1 fi + mount_opts="rw,noatime" + if [ -n "${PERSISTENCE_READONLY}" ] + then + mount_opts="ro,noatime" + fi + if ! mount -o "remount,${mount_opts}" "${backing}" >/dev/null + then + log_warning_msg "Failed to remount persistence media ${device} writable" + # Don't unmount or rmdir the new mountpoint in this case + fi + echo ${backing} + return 0 else # This means that $device has already been mounted on # the place expected by live-boot, so we're done. @@ -899,6 +918,39 @@ probe_for_file_name () fi } +probe_for_directory_name () +{ + local overlays dev ret backing + overlays="${1}" + dev="${2}" + + ret="" + backing="$(mount_persistence_media ${dev} probe)" + if [ -z "${backing}" ] + then + return + fi + + for label in ${overlays} + do + path=${backing}/${PERSISTENCE_PATH}/${label} + if [ -d "${path}" ] + then + # in this case the "device" ends with a "/" + ret="${ret} ${label}=${backing}/${PERSISTENCE_PATH}/${label%%/}/" + fi + done + + if [ -n "${ret}" ] + then + echo ${ret} + else + # unmount and remove mountpoint + umount ${backing} > /dev/null 2>&1 || true + rmdir ${backing} > /dev/null 2>&1 || true + fi +} + find_persistence_media () { # Scans devices for overlays, and returns a whitespace @@ -923,7 +975,17 @@ find_persistence_media () white_listed_devices="${2}" ret="" - black_listed_devices="$(what_is_mounted_on /live/medium) $(what_is_mounted_on /live/findiso) $(what_is_mounted_on /live/fromiso)" + # + # The devices that are hosting the actual live rootfs should not be + # used for persistence storage since otherwise you might mount a + # parent directory on top of a sub-directory of the same filesystem + # in one union together. + # + black_listed_devices="" + for d in /live/rootfs/* /live/findiso /live/fromiso + do + black_listed_devices="${black_listed_devices} $(what_is_mounted_on d)" + done for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}") do @@ -994,6 +1056,17 @@ find_persistence_media () fi fi + # Probe for directory with matching name on mounted partition + if is_in_comma_sep_list directory ${PERSISTENCE_STORAGE} + then + result=$(probe_for_directory_name "${overlays}" ${dev}) + if [ -n "${result}" ] + then + ret="${ret} ${result}" + continue + fi + fi + # Close luks device if it isn't used if [ -z "${result}" ] && [ -n "${luks_device}" ] && is_active_luks_mapping "${luks_device}" then