Simplify mount point handling by using /run/live instead of /lib/live/mount
authorBenjamin Drung <benjamin.drung@profitbricks.com>
Thu, 4 Jan 2018 10:02:32 +0000 (11:02 +0100)
committerRaphaël Hertzog <hertzog@debian.org>
Fri, 23 Feb 2018 17:39:42 +0000 (18:39 +0100)
Currently live-boot mounts following things:

  /lib/live/mount/medium: the live media mounted read-only
  /lib/live/mount/rootfs/filesystem.{squashfs,ext*,...}: the root fs image
  /lib/live/mount/overlay: the copy-on-write content from aufs
  /lib/live/mount/findiso: the loop-mounted iso image when using findiso
  /lib/live/mount/persistence/*: persistent devices with copy-on-write overlay

Some of these mounts are mounted in /live before they are moved to their
correct place. Since the final root filesystem is mounted in /root and
run-init switches to it, special care needs to be taken when moving the
mount points around.

/lib/live/mount/overlay is not accessible any more in the live system:

$ df -h
/dev/loop0 169M  169M     0 100% /lib/live/mount/rootfs/root.squashfs
tmpfs      744M     0  744M   0% /lib/live/mount/overlay
overlay    1,5G 1001M  536M  66% /

The early initramfs stage mounts tmpfs on /run which doesn't need to be
moved once the final root filesystem is in place. The mount points do
not need much space and can live on /run/live without problems. Since
these mount points are run-time variable data, they fit perfectly for
/run and comply with FHS 3.0.

Therefore move /lib/live/mount to /run/live and skip the intermedia
/live mount points. This reduces code and complexity.

See also for the previous larger layout change:
https://lists.debian.org/debian-live/2012/10/msg00021.html

Signed-off-by: Benjamin Drung <benjamin.drung@profitbricks.com>
Closes: #886328

backend/initramfs-tools/live.hook
components/0001-init-vars.sh
components/2010-remove-persistence
components/9990-main.sh
components/9990-misc-helpers.sh
components/9990-overlay.sh

index 068d98e..761849e 100755 (executable)
@@ -8,7 +8,7 @@ set -e
 
 # Reading configuration file from filesystem and live-media
 for _FILE in /etc/live/boot.conf /etc/live/boot/* \
-            /lib/live/mount/media/live/boot.conf /lib/live/mount/media/live/boot/*
+            /run/live/medium/live/boot.conf /run/live/medium/live/boot/*
 do
        if [ -e "${_FILE}" ]
        then
index 7e69956..603cf43 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-mountpoint="/live/medium"
+mountpoint="/run/live/medium"
 alt_mountpoint="/media"
 LIVE_MEDIA_PATH="live"
 HOSTNAME="host"
index 5dcf0c0..717a408 100755 (executable)
@@ -27,5 +27,5 @@ Remove_persistence ()
        esac
 
        # Remove persistence
-       cd /live/overlay && find . -not -name 'persistence.conf' | xargs rm -rf
+       cd /run/live/overlay && find . -not -name 'persistence.conf' | xargs rm -rf
 }
index e5884f9..20e8c0c 100755 (executable)
@@ -128,20 +128,6 @@ Live ()
                mount_images_in_directory "${livefs_root}" "${rootmnt}" "${mac}"
        fi
 
-       # At this point /root should contain the final root filesystem.
-       # Move all mountpoints below /live into /root/lib/live/mount.
-       # This has to be done after mounting the root filesystem to /
-       # otherwise these mount points won't be accessible from the running system.
-       for _MOUNT in $(cat /proc/mounts | cut -f 2 -d " " | grep -e "^/live/")
-       do
-               local newmount
-               newmount="${rootmnt}/lib/live/mount/${_MOUNT#/live/}"
-               mkdir -p "${newmount}"
-               mount -o move "${_MOUNT}" "${newmount}" > /dev/null 2>&1 || \
-               mount -o bind "${_MOUNT}" "${newmount}" > /dev/null || \
-               log_warning_msg "W: failed to move or bindmount ${_MOUNT} to ${newmount}"
-       done
-
        if [ -n "${ROOT_PID}" ]
        then
                echo "${ROOT_PID}" > "${rootmnt}"/lib/live/root.pid
@@ -162,10 +148,10 @@ Live ()
        then
                losetup -d /dev/loop0
 
-               if is_mountpoint /root/lib/live/mount/findiso
+               if is_mountpoint /run/live/findiso
                then
-                       umount /root/lib/live/mount/findiso
-                       rmdir --ignore-fail-on-non-empty /root/lib/live/mount/findiso \
+                       umount /run/live/findiso
+                       rmdir --ignore-fail-on-non-empty /run/live/findiso \
                                >/dev/null 2>&1 || true
                fi
        fi
index fba3d43..e21fced 100755 (executable)
@@ -203,9 +203,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
@@ -703,7 +703,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}"
@@ -715,7 +715,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})"
@@ -1383,9 +1383,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
 
@@ -1575,11 +1575,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
@@ -1587,7 +1587,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}"
@@ -1604,7 +1604,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
index db6a44e..37e8499 100755 (executable)
@@ -15,12 +15,7 @@ setup_unionfs ()
                panic "${UNIONTYPE} not available."
        fi
 
-       # run-init can't deal with images in a subdir, but we're going to
-       # move all of these away before it runs anyway.  No, we're not,
-       # put them in / since move-mounting them into / breaks mono and
-       # some other apps.
-
-       croot="/"
+       croot="/run/live/rootfs"
 
        # Let's just mount the read-only file systems first
        rootfslist=""
@@ -135,8 +130,7 @@ setup_unionfs ()
 
        # tmpfs file systems
        touch /etc/fstab
-       mkdir -p /live/overlay
-       mount -t tmpfs tmpfs /live/overlay
+       mkdir -p /run/live/overlay
 
        # Looking for persistence devices or files
        if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
@@ -246,10 +240,10 @@ setup_unionfs ()
        if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
        then
                mount -t tmpfs -o rw,noatime,mode=755,size=${OVERLAY_SIZE:-50%} tmpfs "/live/overlay"
-               root_backing="/live/persistence/$(basename ${cowdevice})-root"
+               root_backing="/run/live/persistence/$(basename ${cowdevice})-root"
                mkdir -p ${root_backing}
        else
-               root_backing="/live/overlay"
+               root_backing="/run/live/overlay"
        fi
 
        if [ "${cow_fstype}" = "nfs" ]
@@ -290,7 +284,7 @@ setup_unionfs ()
        for dir in ${cow_dirs}; do
                unionmountpoint=$(trim_path "${rootmnt}${dir}")
                mkdir -p ${unionmountpoint}
-               cow_dir=$(trim_path "/live/overlay${dir}")
+               cow_dir=$(trim_path "/run/live/overlay${dir}")
                rootfs_dir="${rootfs}${dir}"
                mkdir -p ${cow_dir}
                if [ -n "${PERSISTENCE_READONLY}" ] && [ "${cowdevice}" != "tmpfs" ]
@@ -313,22 +307,6 @@ setup_unionfs ()
                chmod 1777 "${rootmnt}"/tmp
        fi
 
-       live_rootfs_list=""
-       for d in ${rootfslist}
-       do
-               live_rootfs="/live/rootfs/${d##*/}"
-               live_rootfs_list="${live_rootfs_list} ${live_rootfs}"
-               mkdir -p "${live_rootfs}"
-               case "${d}" in
-                       *.dir)
-                               # do nothing # mount -o bind "${d}" "${live_rootfs}"
-                               ;;
-                       *)
-                               mount -o move "${d}" "${live_rootfs}"
-                               ;;
-               esac
-       done
-
        # Adding custom persistence
        if [ -n "${PERSISTENCE}" ] && [ -z "${NOPERSISTENCE}" ]
        then
@@ -339,7 +317,7 @@ setup_unionfs ()
                # Gather information about custom mounts from devies detected as overlays
                get_custom_mounts ${custom_mounts} ${overlay_devices}
 
-               [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/lib/live/mount/persistence"
+               [ -n "${LIVE_BOOT_DEBUG}" ] && cp ${custom_mounts} "/run/live/persistence"
 
                # Now we do the actual mounting (and symlinking)
                local used_overlays
@@ -356,9 +334,4 @@ setup_unionfs ()
                        fi
                done
        fi
-
-       # ensure that a potentially stray tmpfs gets removed
-       # otherways, initramfs-tools is unable to remove /live
-       # and fails to boot
-       umount /live/overlay > /dev/null 2>&1 || true
 }