Harald Hoyer 9d5d75
From 789668deb3e6f8584ffab964d2204ddcb75f0a06 Mon Sep 17 00:00:00 2001
Harald Hoyer 9d5d75
From: Frederick Grose <fgrose@sugarlabs.org>
Harald Hoyer 9d5d75
Date: Mon, 20 Aug 2018 09:47:50 -0400
Harald Hoyer 9d5d75
Subject: [PATCH] dmsquash-live: Support a flattened squashfs.img
Harald Hoyer 9d5d75
Harald Hoyer 9d5d75
A simplified root filesystem structure may be provided for OverlayFS
Harald Hoyer 9d5d75
overlays by squashing the root filesystem directly instead of squashing
Harald Hoyer 9d5d75
an embedded image file at /LiveOS/rootfs.img.  Detect and configure
Harald Hoyer 9d5d75
such a squashed root filesystem for live booting.
Harald Hoyer 9d5d75
Harald Hoyer 9d5d75
For OverlayFS boots, avoid the read-only Device-mapper linear device
Harald Hoyer 9d5d75
  at /dev/mapper/live-base.
Harald Hoyer 9d5d75
Create a consistent device link at /dev/live-base for the read-only
Harald Hoyer 9d5d75
  base loop device for all overlayed live root filesystems.
Harald Hoyer 9d5d75
Consistently provide a link at /dev/root for wait_for_dev.
Harald Hoyer 9d5d75
Harald Hoyer 9d5d75
Update documentation.
Harald Hoyer 9d5d75
---
Harald Hoyer 9d5d75
 dracut.cmdline.7.asc                            | 126 +++++++++++++++---------
Harald Hoyer 9d5d75
 modules.d/90dmsquash-live/dmsquash-live-root.sh |  51 ++++++----
Harald Hoyer 9d5d75
 2 files changed, 110 insertions(+), 67 deletions(-)
Harald Hoyer 9d5d75
Harald Hoyer 9d5d75
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
Harald Hoyer 9d5d75
index df633e5d..882035af 100644
Harald Hoyer 9d5d75
--- a/dracut.cmdline.7.asc
Harald Hoyer 9d5d75
+++ b/dracut.cmdline.7.asc
Harald Hoyer 9d5d75
@@ -838,23 +838,24 @@ Booting live images
Harald Hoyer 9d5d75
 Dracut offers multiple options for live booted images:
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 =====================
Harald Hoyer 9d5d75
-SquashFS with read-only filesystem image::: The system will boot with a read
Harald Hoyer 9d5d75
-only filesystem from the SquashFS and apply a writable device-mapper snapshot
Harald Hoyer 9d5d75
-over the read only filesystem.  Using this method ensures a relatively fast
Harald Hoyer 9d5d75
-boot and lower RAM usage. Users **must be careful** to avoid writing too many
Harald Hoyer 9d5d75
-blocks to the snapshot volume.  Once the blocks of the snapshot overlay are
Harald Hoyer 9d5d75
-exhausted, the root filesystem becomes read only and may cause application
Harald Hoyer 9d5d75
-failures.  The overlay file is marked 'Overflow', and a difficult recovery is
Harald Hoyer 9d5d75
-required to repair and enlarge the overlay offline.  Non-persistent overlays
Harald Hoyer 9d5d75
-are sparse files in RAM that only consume content space as required blocks are
Harald Hoyer 9d5d75
-allocated.  They default to an apparent size of 32 GiB in RAM.  The size can be
Harald Hoyer 9d5d75
-adjusted with the **rd.live.overlay.size=** kernel command line option.
Harald Hoyer 9d5d75
+SquashFS with read-only filesystem image::: The system will boot with a
Harald Hoyer 9d5d75
+read-only filesystem from the SquashFS and apply a writable Device-mapper
Harald Hoyer 9d5d75
+snapshot or an OverlayFS overlay mount for the read-only base filesystem.  This
Harald Hoyer 9d5d75
+method ensures a relatively fast boot and lower RAM usage. Users **must be
Harald Hoyer 9d5d75
+careful** to avoid writing too many blocks to a snapshot volume.  Once the
Harald Hoyer 9d5d75
+blocks of the snapshot overlay are exhausted, the root filesystem becomes
Harald Hoyer 9d5d75
+read-only and may cause application failures.  The snapshot overlay file is
Harald Hoyer 9d5d75
+marked 'Overflow', and a difficult recovery is required to repair and enlarge
Harald Hoyer 9d5d75
+the overlay offline.  Non-persistent overlays are sparse files in RAM that only
Harald Hoyer 9d5d75
+consume content space as required blocks are allocated.  They default to an
Harald Hoyer 9d5d75
+apparent size of 32 GiB in RAM.  The size can be adjusted with the
Harald Hoyer 9d5d75
+**rd.live.overlay.size=** kernel command line option.
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
-The filesystem structure is expected to be:
Harald Hoyer 9d5d75
+The filesystem structure is traditionally expected to be:
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 [listing]
Harald Hoyer 9d5d75
 --
Harald Hoyer 9d5d75
-squashfs.img          |  Squashfs from LiveCD .iso downloaded via network
Harald Hoyer 9d5d75
+squashfs.img          |  SquashFS from LiveCD .iso
Harald Hoyer 9d5d75
    !(mount)
Harald Hoyer 9d5d75
    /LiveOS
Harald Hoyer 9d5d75
        |- rootfs.img  |  Filesystem image to mount read-only
Harald Hoyer 9d5d75
@@ -865,21 +866,35 @@ squashfs.img          |  Squashfs from LiveCD .iso downloaded via network
Harald Hoyer 9d5d75
             ...       |
Harald Hoyer 9d5d75
 --
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
-Dracut uses this method of live booting by default.  No additional command line
Harald Hoyer 9d5d75
-options are required other than **root=live:<URL>** to specify the location
Harald Hoyer 9d5d75
-of your squashed filesystem.
Harald Hoyer 9d5d75
+For OverlayFS mount overlays, the filesystem structure may also be a direct
Harald Hoyer 9d5d75
+compression of the root filesystem:
Harald Hoyer 9d5d75
++
Harald Hoyer 9d5d75
+[listing]
Harald Hoyer 9d5d75
+--
Harald Hoyer 9d5d75
+squashfs.img          |  SquashFS from LiveCD .iso
Harald Hoyer 9d5d75
+   !(mount)
Harald Hoyer 9d5d75
+   /bin               |  Live filesystem
Harald Hoyer 9d5d75
+   /boot              |
Harald Hoyer 9d5d75
+   /dev               |
Harald Hoyer 9d5d75
+   ...                |
Harald Hoyer 9d5d75
+--
Harald Hoyer 9d5d75
++
Harald Hoyer 9d5d75
+Dracut uses one of the overlay methods of live booting by default.  No
Harald Hoyer 9d5d75
+additional command line options are required other than **root=live:<URL>** to
Harald Hoyer 9d5d75
+specify the location of your squashed filesystem.
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 - The compressed SquashFS image can be copied during boot to RAM at
Harald Hoyer 9d5d75
 `/run/initramfs/squashed.img` by using the **rd.live.ram=1** option.
Harald Hoyer 9d5d75
-- A device with a persistent overlay can be booted read only by using the
Harald Hoyer 9d5d75
+- A device with a persistent overlay can be booted read-only by using the
Harald Hoyer 9d5d75
 **rd.live.overlay.readonly** option on the kernel command line.  This will
Harald Hoyer 9d5d75
-cause a temporary, writable overlay to be stacked over a read-only snapshot
Harald Hoyer 9d5d75
-of the root filesystem.
Harald Hoyer 9d5d75
+either cause a temporary, writable overlay to be stacked over a read-only
Harald Hoyer 9d5d75
+snapshot of the root filesystem or the OverlayFS mount will use an additional
Harald Hoyer 9d5d75
+lower layer with the root filesystem.
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 Uncompressed live filesystem image:::
Harald Hoyer 9d5d75
 When the live system was installed with the '--skipcompress' option of the
Harald Hoyer 9d5d75
 __livecd-iso-to-disk__ installation script for Live USB devices, the root
Harald Hoyer 9d5d75
-filesystem image, `rootfs.img`, is expanded on installation and no SquashFS
Harald Hoyer 9d5d75
+filesystem image, __rootfs.img__, is expanded on installation and no SquashFS
Harald Hoyer 9d5d75
 is involved during boot.
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 - If **rd.live.ram=1** is used in this situation, the full, uncompressed
Harald Hoyer 9d5d75
@@ -887,12 +902,12 @@ root filesystem is copied during boot to `/run/initramfs/rootfs.img` in the
Harald Hoyer 9d5d75
 `/run` tmpfs.
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 - If **rd.live.overlay=none** is provided as a kernel command line option,
Harald Hoyer 9d5d75
-a writable, linear device-mapper target is created on boot with no overlay.
Harald Hoyer 9d5d75
+a writable, linear Device-mapper target is created on boot with no overlay.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
-writable filesystem image:::
Harald Hoyer 9d5d75
+Writable filesystem image:::
Harald Hoyer 9d5d75
 The system will retrieve a compressed filesystem image, extract it to
Harald Hoyer 9d5d75
 `/run/initramfs/fsimg/rootfs.img`, connect it to a loop device, create a
Harald Hoyer 9d5d75
-writable, linear device-mapper target at `/dev/mapper/live-rw`, and mount that
Harald Hoyer 9d5d75
+writable, linear Device-mapper target at `/dev/mapper/live-rw`, and mount that
Harald Hoyer 9d5d75
 as a writable volume at `/`.  More RAM is required during boot but the live
Harald Hoyer 9d5d75
 filesystem is easier to manage if it becomes full.  Users can make a filesystem
Harald Hoyer 9d5d75
 image of any size and that size will be maintained when the system boots. There
Harald Hoyer 9d5d75
@@ -902,7 +917,7 @@ The filesystem structure is expected to be:
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 [listing]
Harald Hoyer 9d5d75
 --
Harald Hoyer 9d5d75
-rootfs.tgz            |  Compressed tarball containing fileystem image
Harald Hoyer 9d5d75
+rootfs.tgz            |  Compressed tarball containing filesystem image
Harald Hoyer 9d5d75
    !(unpack)
Harald Hoyer 9d5d75
    /rootfs.img        |  Filesystem image at /run/initramfs/fsimg/
Harald Hoyer 9d5d75
       !(mount)
Harald Hoyer 9d5d75
@@ -930,11 +945,11 @@ NOTE: There must be enough free RAM available to hold the complete image.
Harald Hoyer 9d5d75
 This method is very suitable for diskless boots.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **root=**live:__<url>__::
Harald Hoyer 9d5d75
-Boots a live image retrieved from __<url>__.  Requires dracut 'livenet' module.
Harald Hoyer 9d5d75
-Valid handlers: __http, https, ftp, torrent, tftp__.
Harald Hoyer 9d5d75
+Boots a live image retrieved from __<url>__.  Requires the dracut 'livenet'
Harald Hoyer 9d5d75
+module.  Valid handlers: __http, https, ftp, torrent, tftp__.
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 [listing]
Harald Hoyer 9d5d75
-.Example
Harald Hoyer 9d5d75
+.Examples
Harald Hoyer 9d5d75
 --
Harald Hoyer 9d5d75
 root=live:http://example.com/liveboot.img
Harald Hoyer 9d5d75
 root=live:ftp://ftp.example.com/liveboot.img
Harald Hoyer 9d5d75
@@ -946,7 +961,7 @@ Enables debug output from the live boot process.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **rd.live.dir=**__<path>__::
Harald Hoyer 9d5d75
 Specifies the directory within the boot device where the squashfs.img or
Harald Hoyer 9d5d75
-rootfs.img can be found.  By default, this is __LiveOS__.
Harald Hoyer 9d5d75
+rootfs.img can be found.  By default, this is `/LiveOS`.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **rd.live.squashimg=**__<filename of SquashFS image>__::
Harald Hoyer 9d5d75
 Specifies the filename for a SquashFS image of the root filesystem.
Harald Hoyer 9d5d75
@@ -954,35 +969,52 @@ By default, this is __squashfs.img__.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **rd.live.ram=**1::
Harald Hoyer 9d5d75
 Copy the complete image to RAM and use this for booting. This is useful
Harald Hoyer 9d5d75
-when the image resides on, i.e., a DVD which needs to be ejected later on.
Harald Hoyer 9d5d75
+when the image resides on, e.g., a DVD which needs to be ejected later on.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **rd.live.overlay={**__<devspec>__[:__{<pathspec>|auto}__]|__none__}::
Harald Hoyer 9d5d75
-Allow the usage of a permanent overlay.
Harald Hoyer 9d5d75
-- _<devspec>_ specifies the path to a device with a mountable filesystem.
Harald Hoyer 9d5d75
-- _<pathspec>_ is the path to a file within that filesystem, which shall be
Harald Hoyer 9d5d75
+Manage the usage of a permanent overlay.
Harald Hoyer 9d5d75
++
Harald Hoyer 9d5d75
+--
Harald Hoyer 9d5d75
+* _<devspec>_ specifies the path to a device with a mountable filesystem.
Harald Hoyer 9d5d75
+* _<pathspec>_ is the path to a file within that filesystem, which shall be
Harald Hoyer 9d5d75
 used to persist the changes made to the device specified by the
Harald Hoyer 9d5d75
 **root=live:__<url>__** option.
Harald Hoyer 9d5d75
-- _none_ specifies no overlay when an uncompressed live root filesystem is
Harald Hoyer 9d5d75
-available.
Harald Hoyer 9d5d75
-If a persistent overlay is detected at the standard LiveOS path, the overlay &
Harald Hoyer 9d5d75
-overlay type detected (whether Device-mapper or OverlayFS) will be used.
Harald Hoyer 9d5d75
++
Harald Hoyer 9d5d75
+The default _pathspec_, when _auto_ or no _:<pathspec>_ is given, is
Harald Hoyer 9d5d75
+`/<+++rd.live.dir+++>/overlay-<label>-<uuid>`, where _<label>_ is the
Harald Hoyer 9d5d75
+device LABEL, and _<uuid>_ is the device UUID.
Harald Hoyer 9d5d75
+* _none_ (the word itself) specifies that no overlay will be used, such as when
Harald Hoyer 9d5d75
+an uncompressed, writable live root filesystem is available.
Harald Hoyer 9d5d75
++
Harald Hoyer 9d5d75
+If a persistent overlay __is detected__ at the standard LiveOS path, the
Harald Hoyer 9d5d75
+overlay & overlay type detected, whether Device-mapper or OverlayFS, will be
Harald Hoyer 9d5d75
+used.
Harald Hoyer 9d5d75
+--
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 [listing]
Harald Hoyer 9d5d75
-.Example
Harald Hoyer 9d5d75
+.Examples
Harald Hoyer 9d5d75
 --
Harald Hoyer 9d5d75
 rd.live.overlay=/dev/sdb1:persistent-overlay.img
Harald Hoyer 9d5d75
+rd.live.overlay=UUID=99440c1f-8daa-41bf-b965-b7240a8996f4
Harald Hoyer 9d5d75
 --
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **rd.live.overlay.size=**__<size_MiB>__::
Harald Hoyer 9d5d75
-Specifies a non-persistent overlay size in MiB.  The default is _32768_.
Harald Hoyer 9d5d75
+Specifies a non-persistent Device-mapper overlay size in MiB.  The default is
Harald Hoyer 9d5d75
+_32768_.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **rd.live.overlay.readonly=**1::
Harald Hoyer 9d5d75
-Specifies a non-persistent, writable snapshot overlay to be stacked over a
Harald Hoyer 9d5d75
-read-only snapshot of the root filesystem, `/dev/mapper/live-ro`, or a read-
Harald Hoyer 9d5d75
-only loop device of a writable `rootfs.img`.
Harald Hoyer 9d5d75
+This is used to boot with a normally read-write persistent overlay in a
Harald Hoyer 9d5d75
+read-only mode.  With this option, either an additional, non-persistent,
Harald Hoyer 9d5d75
+writable snapshot overlay will be stacked over a read-only snapshot,
Harald Hoyer 9d5d75
+`/dev/mapper/live‑ro`, of the base filesystem with the persistent overlay, or a
Harald Hoyer 9d5d75
+read-only loop device, in the case of a writable __rootfs.img__, or an OverlayFS
Harald Hoyer 9d5d75
+mount will use the persistent overlay directory linked at `/run/overlayfs‑r` as
Harald Hoyer 9d5d75
+an additional lower layer along with the base root filesystem and apply a
Harald Hoyer 9d5d75
+transient, writable upper directory overlay, in order to complete the booted
Harald Hoyer 9d5d75
+root filesystem.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **rd.live.overlay.reset=**1::
Harald Hoyer 9d5d75
-Specifies that a persistent overlay should be reset on boot.  All root
Harald Hoyer 9d5d75
+Specifies that a persistent overlay should be reset on boot.  All previous root
Harald Hoyer 9d5d75
 filesystem changes are vacated by this action.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **rd.live.overlay.thin=**1::
Harald Hoyer 9d5d75
@@ -993,25 +1025,25 @@ that memory is given back to the kernel when the filesystem does not claim it
Harald Hoyer 9d5d75
 anymore.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 **rd.live.overlay.overlayfs=**1::
Harald Hoyer 9d5d75
-Enables the use of the **OverlayFS** kernel module, if available, to provide a
Harald Hoyer 9d5d75
+Enables the use of the *OverlayFS* kernel module, if available, to provide a
Harald Hoyer 9d5d75
 copy-on-write union directory for the root filesystem.  OverlayFS overlays are
Harald Hoyer 9d5d75
 directories of the files that have changed on the read-only base (lower)
Harald Hoyer 9d5d75
 filesystem.  The root filesystem is provided through a special overlay type
Harald Hoyer 9d5d75
 mount that merges the lower and upper directories.  If an OverlayFS upper
Harald Hoyer 9d5d75
 directory is not present on the boot device, a tmpfs directory will be created
Harald Hoyer 9d5d75
-at /run/overlayfs to provide temporary storage.  Persistent storage can be
Harald Hoyer 9d5d75
+at `/run/overlayfs` to provide temporary storage.  Persistent storage can be
Harald Hoyer 9d5d75
 provided on vfat or msdos formatted devices by supplying the OverlayFS upper
Harald Hoyer 9d5d75
 directory within an embedded filesystem that supports the creation of trusted.*
Harald Hoyer 9d5d75
 extended attributes and provides a valid d_type in readdir responses, such as
Harald Hoyer 9d5d75
 with ext4 and xfs.  On non-vfat-formatted devices, a persistent OverlayFS
Harald Hoyer 9d5d75
 overlay can extend the available root filesystem storage up to the capacity of
Harald Hoyer 9d5d75
-the LiveOS device.
Harald Hoyer 9d5d75
+the LiveOS disk device.
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 If a persistent overlay is detected at the standard LiveOS path, the overlay &
Harald Hoyer 9d5d75
-overlay type detected (whether OverlayFS or Device-mapper) will be used.
Harald Hoyer 9d5d75
+overlay type detected, whether OverlayFS or Device-mapper, will be used.
Harald Hoyer 9d5d75
 +
Harald Hoyer 9d5d75
 The **rd.live.overlay.readonly** option, which allows a persistent overlayfs to
Harald Hoyer 9d5d75
-be mounted read only through a higher level transient overlay directory, has
Harald Hoyer 9d5d75
+be mounted read-only through a higher level transient overlay directory, has
Harald Hoyer 9d5d75
 been implemented through the multiple lower layers feature of OverlayFS.
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh
Harald Hoyer 9d5d75
index ac603408..0c5e010e 100755
Harald Hoyer 9d5d75
--- a/modules.d/90dmsquash-live/dmsquash-live-root.sh
Harald Hoyer 9d5d75
+++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh
Harald Hoyer 9d5d75
@@ -250,13 +250,11 @@ do_live_overlay() {
Harald Hoyer 9d5d75
         echo 0 $sz snapshot $base $over PO 8 | dmsetup create live-rw
Harald Hoyer 9d5d75
     fi
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
-    # Create a device that always points to a ro base image
Harald Hoyer 9d5d75
-    if [ -n "$overlayfs" ]; then
Harald Hoyer 9d5d75
-        BASE_LOOPDUP=$(losetup -f --show -r $BASE_LOOPDEV)
Harald Hoyer 9d5d75
-        echo 0 $sz linear $BASE_LOOPDUP 0 | dmsetup create --readonly live-base
Harald Hoyer 9d5d75
-    else
Harald Hoyer 9d5d75
+    # Create a device for the ro base of overlayed file systems.
Harald Hoyer 9d5d75
+    if [ -z "$overlayfs" ]; then
Harald Hoyer 9d5d75
         echo 0 $sz linear $BASE_LOOPDEV 0 | dmsetup create --readonly live-base
Harald Hoyer 9d5d75
     fi
Harald Hoyer 9d5d75
+    ln -s $BASE_LOOPDEV /dev/live-base
Harald Hoyer 9d5d75
 }
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 # we might have a genMinInstDelta delta file for anaconda to take advantage of
Harald Hoyer 9d5d75
@@ -291,10 +289,21 @@ if [ -e "$SQUASHED" ]; then
Harald Hoyer 9d5d75
     mkdir -m 0755 -p /run/initramfs/squashfs
Harald Hoyer 9d5d75
     mount -n -t squashfs -o ro $SQUASHED_LOOPDEV /run/initramfs/squashfs
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
-    if [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then
Harald Hoyer 9d5d75
-        FSIMG="/run/initramfs/squashfs/LiveOS/rootfs.img"
Harald Hoyer 9d5d75
-    elif [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then
Harald Hoyer 9d5d75
-        FSIMG="/run/initramfs/squashfs/LiveOS/ext3fs.img"
Harald Hoyer 9d5d75
+    if [ -d /run/initramfs/squashfs/LiveOS ]; then
Harald Hoyer 9d5d75
+        if [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then
Harald Hoyer 9d5d75
+            FSIMG="/run/initramfs/squashfs/LiveOS/rootfs.img"
Harald Hoyer 9d5d75
+        elif [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then
Harald Hoyer 9d5d75
+            FSIMG="/run/initramfs/squashfs/LiveOS/ext3fs.img"
Harald Hoyer 9d5d75
+        fi
Harald Hoyer 9d5d75
+    elif [ -d /run/initramfs/squashfs/proc ]; then
Harald Hoyer 9d5d75
+        FSIMG=$SQUASHED
Harald Hoyer 9d5d75
+        if [ -z "$overlayfs" ]; then
Harald Hoyer 9d5d75
+            overlayfs="yes"
Harald Hoyer 9d5d75
+            [ -n "$DRACUT_SYSTEMD" ] && reloadsysrootmountunit="yes"
Harald Hoyer 9d5d75
+        fi
Harald Hoyer 9d5d75
+    else
Harald Hoyer 9d5d75
+        die "Failed to find a root filesystem in $SQUASHED."
Harald Hoyer 9d5d75
+        exit 1
Harald Hoyer 9d5d75
     fi
Harald Hoyer 9d5d75
 else
Harald Hoyer 9d5d75
     # we might have an embedded fs image to use as rootfs (uncompressed live)
Harald Hoyer 9d5d75
@@ -312,8 +321,8 @@ else
Harald Hoyer 9d5d75
     fi
Harald Hoyer 9d5d75
 fi
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
-if [ -n "$FSIMG" ] ; then
Harald Hoyer 9d5d75
-    if [ -n "$writable_fsimg" ] ; then
Harald Hoyer 9d5d75
+if [ -n "$FSIMG" ]; then
Harald Hoyer 9d5d75
+    if [ -n "$writable_fsimg" ]; then
Harald Hoyer 9d5d75
         # mount the provided filesystem read/write
Harald Hoyer 9d5d75
         echo "Unpacking live filesystem (may take some time)" > /dev/kmsg
Harald Hoyer 9d5d75
         mkdir -m 0755 /run/initramfs/fsimg/
Harald Hoyer 9d5d75
@@ -336,9 +345,13 @@ if [ -n "$FSIMG" ] ; then
Harald Hoyer 9d5d75
             setup=yes
Harald Hoyer 9d5d75
         fi
Harald Hoyer 9d5d75
     fi
Harald Hoyer 9d5d75
-    BASE_LOOPDEV=$(losetup -f --show $opt $FSIMG)
Harald Hoyer 9d5d75
-    sz=$(blockdev --getsz $BASE_LOOPDEV)
Harald Hoyer 9d5d75
-    if [ "$setup" == rw ]; then
Harald Hoyer 9d5d75
+    if [ "$FSIMG" = "$SQUASHED" ]; then
Harald Hoyer 9d5d75
+        BASE_LOOPDEV=$SQUASHED_LOOPDEV
Harald Hoyer 9d5d75
+    else
Harald Hoyer 9d5d75
+        BASE_LOOPDEV=$(losetup -f --show $opt $FSIMG)
Harald Hoyer 9d5d75
+        sz=$(blockdev --getsz $BASE_LOOPDEV)
Harald Hoyer 9d5d75
+    fi
Harald Hoyer 9d5d75
+    if [ "$setup" = rw ]; then
Harald Hoyer 9d5d75
         echo 0 $sz linear $BASE_LOOPDEV 0 | dmsetup create live-rw
Harald Hoyer 9d5d75
     else
Harald Hoyer 9d5d75
         # Add a DM snapshot or OverlayFS for writes.
Harald Hoyer 9d5d75
@@ -346,8 +359,6 @@ if [ -n "$FSIMG" ] ; then
Harald Hoyer 9d5d75
     fi
Harald Hoyer 9d5d75
 fi
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
-[ -e "$SQUASHED" ] && [ -z "$overlayfs" ] && umount -l /run/initramfs/squashfs
Harald Hoyer 9d5d75
-
Harald Hoyer 9d5d75
 if [ -b "$OSMIN_LOOPDEV" ]; then
Harald Hoyer 9d5d75
     # set up the devicemapper snapshot device, which will merge
Harald Hoyer 9d5d75
     # the normal live fs image, and the delta, into a minimzied fs image
Harald Hoyer 9d5d75
@@ -380,17 +391,17 @@ if [ -n "$overlayfs" ]; then
Harald Hoyer 9d5d75
         'lowerdir=/run/rootfsbase,upperdir=/run/overlayfs,workdir=/run/ovlwork' \
Harald Hoyer 9d5d75
         "$NEWROOT" > $hookdir/mount/01-$$-live.sh
Harald Hoyer 9d5d75
     fi
Harald Hoyer 9d5d75
-    _dev=/run/rootfsbase
Harald Hoyer 9d5d75
 else
Harald Hoyer 9d5d75
-    _dev=/dev/mapper/live-rw
Harald Hoyer 9d5d75
     if [ -z "$DRACUT_SYSTEMD" ]; then
Harald Hoyer 9d5d75
         [ -n "$ROOTFLAGS" ] && ROOTFLAGS="-o $ROOTFLAGS"
Harald Hoyer 9d5d75
         printf 'mount %s /dev/mapper/live-rw %s\n' "$ROOTFLAGS" "$NEWROOT" > $hookdir/mount/01-$$-live.sh
Harald Hoyer 9d5d75
     fi
Harald Hoyer 9d5d75
-    ln -s $BASE_LOOPDEV /run/rootfsbase
Harald Hoyer 9d5d75
 fi
Harald Hoyer 9d5d75
-ln -s $_dev /dev/root
Harald Hoyer 9d5d75
+[ -e "$SQUASHED" ] && umount -l /run/initramfs/squashfs
Harald Hoyer 9d5d75
+
Harald Hoyer 9d5d75
+ln -s null /dev/root
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 need_shutdown
Harald Hoyer 9d5d75
 
Harald Hoyer 9d5d75
 exit 0
Harald Hoyer 9d5d75
+
Harald Hoyer 9d5d75