Feature request: Support for the 'toram' boot parameter in dmsquash-live

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

This feature request is regarding the dracut module dmsquash-live.

I've attached a patch [1] to change the behavior of the module if the boot parameter 'toram' is set. With the patch and if the 'toram' parameter is set, the root file system will be copied to tmpfs during the boot process, and the system boots from there. The usual overlay partition will not be created, and the root file system is being run directly from tmpfs with rw permissions.

Background:
Bootable livecd images are usually iso9660 file systems which include vmlinuz, initrd and a compressed squashfs. The compressed squashfs includes an ext file system image containing the real file system. What seems happen during boot is that the (read-only) squashfs is mounted and an (rw) overlay partition is being mounted on top to allow the user to write data during the live session. This overlay partition holds the diff from the original file system. 

Now, what's interesting is that production servers running for several months eventually will end up with a diff larger than the overlay can handle. Therefore, in some scenarios, it makes sense to skip the overlay, copy the entire file system to tmpfs, and then mount the writable rootfs from there - and that's where the optional 'toram' parameter comes in.

Thanks,

[1] The patch is for /usr/share/dracut/modules.d/90dmsquash-live/dmsquash-live-root

-- 
Kind regards
Espen Braastad
Redpill Linpro AS
+47 21 54 41 37
--- /usr/share/dracut/modules.d/90dmsquash-live/dmsquash-live-root	2012-02-20 13:10:35.000000000 +0100
+++ dmsquash-live-root	2012-04-16 16:20:24.085280515 +0200
@@ -19,6 +19,7 @@
 live_dir=$(getarg live_dir)
 [ -z "$live_dir" ] && live_dir="LiveOS"
 getarg live_ram && live_ram="yes"
+getarg toram && toram="yes"
 getarg reset_overlay && reset_overlay="yes"
 getarg readonly_overlay && readonly_overlay="--readonly" || readonly_overlay=""
 overlay=$(getarg overlay)
@@ -131,7 +132,10 @@
     BASE_LOOPDEV=$( losetup -f )
     losetup -r $BASE_LOOPDEV $EXT3FS
 
-    do_live_from_base_loop
+    # Create overlay only if toram is not set
+    if [ -z "$toram" ] ; then
+        do_live_from_base_loop
+    fi
 fi
 
 # we might have an embedded ext3 on squashfs to use as rootfs (compressed live)
@@ -160,13 +164,61 @@
 
     umount -l /squashfs
 
-    do_live_from_base_loop
+    # Create overlay only if toram is not set
+    if [ -z "$toram" ] ; then
+        do_live_from_base_loop
+    fi
+fi
+
+# I the kernel parameter toram is set, create a tmpfs device and copy the 
+# filesystem to it. Continue the boot process with this tmpfs device as
+# a writable root device.
+if [ -n "$toram" ] ; then
+    blocks=$( blockdev --getsz $BASE_LOOPDEV )
+
+    echo "Create tmpfs ($blocks blocks) for the root filesystem..."
+    mkdir -p /image
+    mount -n -t tmpfs -o nr_blocks=$blocks tmpfs /image
+
+    echo "Copy filesystem image to tmpfs... (this may take a few minutes)"
+    dd if=$BASE_LOOPDEV of=/image/rootfs.img
+
+    ROOTFS_LOOPDEV=$( losetup -f )
+    echo "Create loop device for the root filesystem: $ROOTFS_LOOPDEV"
+    losetup $ROOTFS_LOOPDEV /image/rootfs.img
+
+    echo "It's time to clean up.. "
+
+    echo " > Umounting images"
+    umount -l /image
+    umount -l /dev/.initramfs/live
+
+    echo " > Detach $OSMIN_LOOPDEV"
+    losetup -d $OSMIN_LOOPDEV
+
+    echo " > Detach $OSMIN_SQUASHED_LOOPDEV"
+    losetup -d $OSMIN_SQUASHED_LOOPDEV
+    
+    echo " > Detach $BASE_LOOPDEV"
+    losetup -d $BASE_LOOPDEV
+    
+    echo " > Detach $SQUASHED_LOOPDEV"
+    losetup -d $SQUASHED_LOOPDEV
+
+    echo "Root filesystem is now on $ROOTFS_LOOPDEV."
+    echo
+
+    ln -s $ROOTFS_LOOPDEV /dev/root
+    printf '/bin/mount -o rw %s %s\n' "$ROOTFS_LOOPDEV" "$NEWROOT" > /mount/01-$$-live.sh
+    exit 0
 fi
 
 if [ -b "$OSMIN_LOOPDEV" ]; then
     # set up the devicemapper snapshot device, which will merge
     # the normal live fs image, and the delta, into a minimzied fs image
-    echo "0 $( blockdev --getsz $BASE_LOOPDEV ) snapshot $BASE_LOOPDEV $OSMIN_LOOPDEV p 8" | dmsetup create --readonly live-osimg-min
+    if [ -z "$toram" ] ; then
+        echo "0 $( blockdev --getsz $BASE_LOOPDEV ) snapshot $BASE_LOOPDEV $OSMIN_LOOPDEV p 8" | dmsetup create --readonly live-osimg-min
+    fi
 fi
 
 ROOTFLAGS="$(getarg rootflags)"

[Index of Archives]     [Linux Kernel]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux