Blame SOURCES/0259-Adding-support-for-read-write-filesystem-images.patch

64b87c
From b9c6d2b2afa94dcba7129390edb7b1a2eaf2c31c Mon Sep 17 00:00:00 2001
64b87c
From: Major Hayden <major@mhtx.net>
64b87c
Date: Mon, 4 Aug 2014 10:27:36 -0500
64b87c
Subject: [PATCH] Adding support for read/write filesystem images
64b87c
64b87c
A user can provide a filesystem image (rootfs.img) inside a compressed
64b87c
tarball and that filesystem image will be mounted read/write.  This provides
64b87c
some benefits over a device mapper snapshot overlay, especially when the
64b87c
live system becomes full.  The boot command line simple needs
64b87c
"rd.writable.fsimg" added to utilize this feature.
64b87c
64b87c
Additional documentation for this option as well as other live boot
64b87c
options is included.
64b87c
64b87c
Signed-off-by: Major Hayden <major@mhtx.net>
64b87c
(cherry picked from commit 504c0a8feca7d7ef470e4483a68cbaf9cb7df2bf)
64b87c
---
64b87c
 dracut.cmdline.7.asc                            | 82 ++++++++++++++++++++++++-
64b87c
 modules.d/90dmsquash-live/dmsquash-live-root.sh | 16 ++++-
64b87c
 modules.d/90dmsquash-live/module-setup.sh       |  2 +-
64b87c
 3 files changed, 96 insertions(+), 4 deletions(-)
64b87c
64b87c
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
1755ca
index bce86084..0493dcd8 100644
64b87c
--- a/dracut.cmdline.7.asc
64b87c
+++ b/dracut.cmdline.7.asc
64b87c
@@ -729,10 +729,90 @@ rd.znet=qeth,0.0.0600,0.0.0601,0.0.0602,layer2=1,portname=foo
64b87c
 rd.znet=ctc,0.0.0600,0.0.0601,protocol=bar
64b87c
 --
64b87c
 
64b87c
+Booting live images
64b87c
+~~~~~~~~~~~~~~~~~~~
64b87c
+Dracut offers multiple options for live booted images:
64b87c
+
64b87c
+=====================
64b87c
+squashfs with read-only filesystem image::: The system will boot with a read
64b87c
+only filesystem from the squashfs and apply a writable device mapper snapshot
64b87c
+over the read only filesystem.  Using this method ensures a relatively fast
64b87c
+boot and lower RAM usage. Users **must be careful** to avoid writing too many
64b87c
+blocks to the snapshot volume.  Once the blocks of the snapshot are exhaused,
64b87c
+the live filesystem becomes unusable and requires a reboot.
64b87c
++
64b87c
+The filesystem structure is expected to be:
64b87c
++
64b87c
+[listing]
64b87c
+--
64b87c
+squashfs.img          |  Squashfs downloaded via network
64b87c
+   !(mount)
64b87c
+   /LiveOS
64b87c
+       |- ext3fs.img  |  Filesystem image to mount read-only
64b87c
+            !(mount)
64b87c
+            /bin      |  Live filesystem
64b87c
+            /boot     |
64b87c
+            /dev      |
64b87c
+            ...       |
64b87c
+--
64b87c
++
64b87c
+Dracut uses this method of live booting by default.  No additional command line
64b87c
+options are required other than **root=live:<URL>** to specify the location
64b87c
+of your squashed filesystem.
64b87c
++
64b87c
+writable filesystem image::: The system will retrieve a compressed filesystem
64b87c
+image, connect it to a loopback device, and mount it as a writable volume.  More
64b87c
+RAM is required during boot but the live filesystem is easier to manage if it
64b87c
+becomes full.  Users can make a filesystem image of any size and that size will
64b87c
+be maintained when the system boots.
64b87c
++
64b87c
+The filesystem structure is expected to be:
64b87c
++
64b87c
+[listing]
64b87c
+--
64b87c
+rootfs.tgz            |  Compressed tarball containing fileystem image
64b87c
+   !(unpack)
64b87c
+   /rootfs.img        |  Filesystem image
64b87c
+      !(mount)
64b87c
+      /bin            |  Live filesystem
64b87c
+      /boot           |
64b87c
+      /dev            |
64b87c
+      ...             |
64b87c
+--
64b87c
++
64b87c
+To use this boot option, ensure that **rd.writable_fsimg=1** is in your kernel
64b87c
+command line and add the **root=live:<URL>** to specify the location
64b87c
+of your compressed filesystem image tarball.
64b87c
+=====================
64b87c
+
64b87c
+**root=**live:__<url>__::
64b87c
+Boots a live image retrieved from __<url>__.  Valid handlers: __http, httpd, ftp, tftp__.
64b87c
++
64b87c
+[listing]
64b87c
+.Example
64b87c
+--
64b87c
+root=live:http://example.com/liveboot.img
64b87c
+root=live:ftp://ftp.example.com/liveboot.img
64b87c
+--
64b87c
+
64b87c
+**rd.live.debug=**1::
64b87c
+Enables debug output from the live boot process.
64b87c
+
64b87c
+**rd.live.dir=**__<path>__::
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.writable.fsimg=**1::
64b87c
+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
+
64b87c
+
64b87c
 Plymouth Boot Splash
64b87c
 ~~~~~~~~~~~~~~~~~~~~
64b87c
 **plymouth.enable=0**::
64b87c
-    disable the plymouth bootsplash completly.
64b87c
+    disable the plymouth bootsplash completely.
64b87c
 
64b87c
 **rd.plymouth=0**::
64b87c
     disable the plymouth bootsplash only for the initramfs.
64b87c
diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh
1755ca
index 5705e8df..c6c02c74 100755
64b87c
--- a/modules.d/90dmsquash-live/dmsquash-live-root.sh
64b87c
+++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh
64b87c
@@ -4,6 +4,8 @@
64b87c
 
64b87c
 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
64b87c
 
64b87c
+command -v unpack_archive >/dev/null || . /lib/img-lib.sh
64b87c
+
64b87c
 PATH=/usr/sbin:/usr/bin:/sbin:/bin
64b87c
 
64b87c
 if getargbool 0 rd.live.debug -n -y rdlivedebug; then
64b87c
@@ -26,6 +28,7 @@ getargbool 0 rd.live.ram -d -y live_ram && live_ram="yes"
64b87c
 getargbool 0 rd.live.overlay.reset -d -y reset_overlay && reset_overlay="yes"
64b87c
 getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay=""
64b87c
 overlay=$(getarg rd.live.overlay -d overlay)
64b87c
+getargbool 0 rd.writable.fsimg -d -y writable_fsimg && writable_fsimg="yes"
64b87c
 
64b87c
 # CD/DVD media check
64b87c
 [ -b $livedev ] && fs=$(blkid -s TYPE -o value $livedev)
64b87c
@@ -180,9 +183,18 @@ fi
64b87c
 
64b87c
 if [ -n "$FSIMG" ] ; then
64b87c
     BASE_LOOPDEV=$( losetup -f )
64b87c
-    losetup -r $BASE_LOOPDEV $FSIMG
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
+        unpack_archive $FSIMG /tmp/fsimg/
64b87c
+        losetup $BASE_LOOPDEV /tmp/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
diff --git a/modules.d/90dmsquash-live/module-setup.sh b/modules.d/90dmsquash-live/module-setup.sh
1755ca
index c6d1f9d5..f52717de 100755
64b87c
--- a/modules.d/90dmsquash-live/module-setup.sh
64b87c
+++ b/modules.d/90dmsquash-live/module-setup.sh
64b87c
@@ -11,7 +11,7 @@ check() {
64b87c
 depends() {
64b87c
     # if dmsetup is not installed, then we cannot support fedora/red hat
64b87c
     # style live images
64b87c
-    echo dm rootfs-block
64b87c
+    echo dm rootfs-block img-lib
64b87c
     return 0
64b87c
 }
64b87c