Blame 0009-dmsquash-Add-squashfs-support-to-rd.live.fsimg.patch

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