64b87c
From 70b7ec9492f950bcfb6f390c58ad6e3e2b8fda9c Mon Sep 17 00:00:00 2001
64b87c
From: Fabian Deutsch <fabiand@fedoraproject.org>
64b87c
Date: Thu, 19 Feb 2015 10:09:14 +0100
64b87c
Subject: [PATCH] dmsquash: Add squashfs support to rd.live.fsimg
64b87c
64b87c
Previously rd.live.fsimg only supported filesystems residing in
64b87c
(compressed) archives.
64b87c
Now rd.live.fsimg can also be used when a squashfs image is used.
64b87c
This is achieved by extracting the rootfs image from the squashfs and
64b87c
then continue with the default routines for rd.live.fsimg.
64b87c
In addition some code duplication got removed and some documentation
64b87c
got added.
64b87c
64b87c
Signed-off-by: Fabian Deutsch <fabiand@fedoraproject.org>
64b87c
(cherry picked from commit b0472eac111268e2cae783097d0eccc1986e1762)
64b87c
---
49e6a8
 dracut.cmdline.7.asc                          |  9 +++
49e6a8
 .../90dmsquash-live/dmsquash-live-root.sh     | 64 ++++++++++---------
64b87c
 2 files changed, 42 insertions(+), 31 deletions(-)
64b87c
64b87c
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
1755ca
index 0c3bc295..1e89bd50 100644
64b87c
--- a/dracut.cmdline.7.asc
64b87c
+++ b/dracut.cmdline.7.asc
64b87c
@@ -802,6 +802,10 @@ Enables debug output from the live boot process.
64b87c
 Specifies the directory within the squashfs where the ext3fs.img or rootfs.img
64b87c
 can be found.  By default, this is __LiveOS__.
64b87c
 
64b87c
+**rd.live.ram=**1::
64b87c
+Copy the complete image to RAM and use this for booting. This is useful
64b87c
+when the image resides on i.e. a DVD which needs to be ejected later on.
64b87c
+
64b87c
 **rd.live.overlay.thin=**1::
64b87c
 Enables the usage of thin snapshots instead of classic dm snapshots.
64b87c
 The advantage of thin snapshots is, that they support discards, and will free
64b87c
@@ -814,6 +818,11 @@ Enables writable filesystem support.  The system will boot with a fully
64b87c
 writable filesystem without snapshots __(see notes above about available live boot options)__.
64b87c
 You can use the **rootflags** option to set mount options for the live
64b87c
 filesystem as well __(see documentation about rootflags in the **Standard** section above)__.
64b87c
+This implies that the whole image is copied to RAM before the boot continues.
64b87c
++
64b87c
+NOTE: There must be enough free RAM available to hold the complete image.
64b87c
++
64b87c
+This method is very suitable for diskless boots.
64b87c
 
64b87c
 
64b87c
 Plymouth Boot Splash
64b87c
diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh
1755ca
index 12354f42..64abc0be 100755
64b87c
--- a/modules.d/90dmsquash-live/dmsquash-live-root.sh
64b87c
+++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh
64b87c
@@ -148,6 +148,7 @@ do_live_overlay() {
64b87c
         base=$BASE_LOOPDEV
64b87c
         over=$OVERLAY_LOOPDEV
64b87c
     fi
64b87c
+
64b87c
     if [ -n "$thin_snapshot" ]; then
64b87c
         modprobe dm_thin_pool
64b87c
         mkdir /run/initramfs/thin-overlay
64b87c
@@ -199,29 +200,6 @@ if [ -n "$OSMINSQFS" ]; then
64b87c
     umount -l /run/initramfs/squashfs.osmin
64b87c
 fi
64b87c
 
64b87c
-# we might have an embedded fs image to use as rootfs (uncompressed live)
64b87c
-if [ -e /run/initramfs/live/${live_dir}/ext3fs.img ]; then
64b87c
-    FSIMG="/run/initramfs/live/${live_dir}/ext3fs.img"
64b87c
-elif [ -e /run/initramfs/live/${live_dir}/rootfs.img ]; then
64b87c
-    FSIMG="/run/initramfs/live/${live_dir}/rootfs.img"
64b87c
-fi
64b87c
-
64b87c
-if [ -n "$FSIMG" ] ; then
64b87c
-    BASE_LOOPDEV=$( losetup -f )
64b87c
-
64b87c
-    if [ -n "$writable_fsimg" ] ; then
64b87c
-        # mount the provided fileysstem read/write
64b87c
-        echo "Unpacking live filesystem (may take some time)"
64b87c
-        unpack_archive $FSIMG /run/initramfs/fsimg/
64b87c
-        losetup $BASE_LOOPDEV /run/initramfs/fsimg/rootfs.img
64b87c
-        echo "0 $( blockdev --getsize $BASE_LOOPDEV ) linear $BASE_LOOPDEV 0" | dmsetup create live-rw
64b87c
-    else
64b87c
-        # mount the filesystem read-only and add a dm snapshot for writes
64b87c
-        losetup -r $BASE_LOOPDEV $FSIMG
64b87c
-        do_live_from_base_loop
64b87c
-    fi
64b87c
-fi
64b87c
-
64b87c
 # we might have an embedded fs image on squashfs (compressed live)
64b87c
 if [ -e /run/initramfs/live/${live_dir}/${squash_image} ]; then
64b87c
     SQUASHED="/run/initramfs/live/${live_dir}/${squash_image}"
64b87c
@@ -242,18 +220,42 @@ if [ -e "$SQUASHED" ] ; then
64b87c
     mkdir -m 0755 -p /run/initramfs/squashfs
64b87c
     mount -n -t squashfs -o ro $SQUASHED_LOOPDEV /run/initramfs/squashfs
64b87c
 
64b87c
-    BASE_LOOPDEV=$( losetup -f )
64b87c
-    if [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then
64b87c
-        losetup -r $BASE_LOOPDEV /run/initramfs/squashfs/LiveOS/ext3fs.img
64b87c
-    elif [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then
64b87c
-        losetup -r $BASE_LOOPDEV /run/initramfs/squashfs/LiveOS/rootfs.img
64b87c
-    fi
64b87c
+fi
64b87c
+
64b87c
+# we might have an embedded fs image to use as rootfs (uncompressed live)
64b87c
+if [ -e /run/initramfs/live/${live_dir}/ext3fs.img ]; then
64b87c
+    FSIMG="/run/initramfs/live/${live_dir}/ext3fs.img"
64b87c
+elif [ -e /run/initramfs/live/${live_dir}/rootfs.img ]; then
64b87c
+    FSIMG="/run/initramfs/live/${live_dir}/rootfs.img"
64b87c
+elif [ -f /run/initramfs/squashfs/LiveOS/ext3fs.img ]; then
64b87c
+    FSIMG="/run/initramfs/squashfs/LiveOS/ext3fs.img"
64b87c
+elif [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then
64b87c
+    FSIMG="/run/initramfs/squashfs/LiveOS/rootfs.img"
64b87c
+fi
64b87c
 
64b87c
-    umount -l /run/initramfs/squashfs
64b87c
+if [ -n "$FSIMG" ] ; then
64b87c
+    BASE_LOOPDEV=$( losetup -f )
64b87c
 
64b87c
-    do_live_from_base_loop
64b87c
+    if [ -n "$writable_fsimg" ] ; then
64b87c
+        # mount the provided fileysstem read/write
64b87c
+        echo "Unpacking live filesystem (may take some time)"
64b87c
+        mkdir /run/initramfs/fsimg/
64b87c
+        if [ -n "$SQUASHED" ]; then
64b87c
+            cp -v $FSIMG /run/initramfs/fsimg/rootfs.img
64b87c
+        else
64b87c
+            unpack_archive $FSIMG /run/initramfs/fsimg/
64b87c
+        fi
64b87c
+        losetup $BASE_LOOPDEV /run/initramfs/fsimg/rootfs.img
64b87c
+        echo "0 $( blockdev --getsize $BASE_LOOPDEV ) linear $BASE_LOOPDEV 0" | dmsetup create live-rw
64b87c
+    else
64b87c
+        # mount the filesystem read-only and add a dm snapshot for writes
64b87c
+        losetup -r $BASE_LOOPDEV $FSIMG
64b87c
+        do_live_from_base_loop
64b87c
+    fi
64b87c
 fi
64b87c
 
64b87c
+[ -e "$SQUASHED" ] && umount -l /run/initramfs/squashfs
64b87c
+
64b87c
 if [ -b "$OSMIN_LOOPDEV" ]; then
64b87c
     # set up the devicemapper snapshot device, which will merge
64b87c
     # the normal live fs image, and the delta, into a minimzied fs image