From 1ba79ed1eb5e2a52bdf226b0bbeaa3917f048778 Mon Sep 17 00:00:00 2001 From: Jan Blunck Date: Tue, 3 Sep 2013 11:22:00 +0200 Subject: [PATCH] Add support for persistence-storage type "directory". This adds support for mounting a plain writable directory as the persistence storage layer. The $PERSISTENCE_PATH and the persistence-label are taken into account when searching for the persistence.conf file. --- components/9990-misc-helpers.sh | 58 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/components/9990-misc-helpers.sh b/components/9990-misc-helpers.sh index 2515ea1..2a3e6ad 100755 --- a/components/9990-misc-helpers.sh +++ b/components/9990-misc-helpers.sh @@ -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 @@ -908,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 @@ -1013,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 -- 2.1.4