|
Harald Hoyer |
43a122 |
From d6e34d362a05cda61baaf8e231ad3f0e8665a9cc Mon Sep 17 00:00:00 2001
|
|
Harald Hoyer |
43a122 |
From: Fabian Deutsch <fabiand@fedoraproject.org>
|
|
Harald Hoyer |
43a122 |
Date: Wed, 18 Feb 2015 14:31:40 +0100
|
|
Harald Hoyer |
43a122 |
Subject: [PATCH] dmsquash: Add rd.live.overlay.thin
|
|
Harald Hoyer |
43a122 |
|
|
Harald Hoyer |
43a122 |
This option changes the underlying mechanism for the overlay in the
|
|
Harald Hoyer |
43a122 |
dmsquash module.
|
|
Harald Hoyer |
43a122 |
Instead of a plain dm snapshot a dm thin snapshot is used. The advantage
|
|
Harald Hoyer |
43a122 |
of the thin snapshot is, that the TRIM command is recognized, which
|
|
Harald Hoyer |
43a122 |
means that at runtime, only the occupied blocks will be claimed from
|
|
Harald Hoyer |
43a122 |
memory, and freed blocks will really be freed in ram.
|
|
Harald Hoyer |
43a122 |
|
|
Harald Hoyer |
43a122 |
Signed-off-by: Fabian Deutsch <fabiand@fedoraproject.org>
|
|
Harald Hoyer |
43a122 |
---
|
|
Harald Hoyer |
43a122 |
dracut.cmdline.7.asc | 7 +++++++
|
|
Harald Hoyer |
43a122 |
modules.d/90dmsquash-live/dmsquash-live-root.sh | 27 ++++++++++++++++++++++++-
|
|
Harald Hoyer |
43a122 |
2 files changed, 33 insertions(+), 1 deletion(-)
|
|
Harald Hoyer |
43a122 |
|
|
Harald Hoyer |
43a122 |
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
|
|
Harald Hoyer |
43a122 |
index 60826a1..9ddad0f 100644
|
|
Harald Hoyer |
43a122 |
--- a/dracut.cmdline.7.asc
|
|
Harald Hoyer |
43a122 |
+++ b/dracut.cmdline.7.asc
|
|
Harald Hoyer |
43a122 |
@@ -834,6 +834,13 @@ 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.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 |
+blocks which are not claimed by the filesystem. In this use case this means,
|
|
Harald Hoyer |
43a122 |
+that memory is given back to the kernel, when the filesystem does not claim it
|
|
Harald Hoyer |
43a122 |
+anymore.
|
|
Harald Hoyer |
43a122 |
+
|
|
Harald Hoyer |
43a122 |
**rd.writable.fsimg=**1::
|
|
Harald Hoyer |
43a122 |
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 |
diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh
|
|
Harald Hoyer |
43a122 |
index 9c08e94..45f724c 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 |
@@ -30,6 +30,8 @@ getargbool 0 rd.writable.fsimg -d -y writable_fsimg && writable_fsimg="yes"
|
|
Harald Hoyer |
43a122 |
overlay_size=$(getarg rd.live.overlay.size=)
|
|
Harald Hoyer |
43a122 |
[ -z "$overlay_size" ] && overlay_size=512
|
|
Harald Hoyer |
43a122 |
|
|
Harald Hoyer |
43a122 |
+getargbool 0 rd.live.overlay.thin && thin_snapshot="yes"
|
|
Harald Hoyer |
43a122 |
+
|
|
Harald Hoyer |
43a122 |
# CD/DVD media check
|
|
Harald Hoyer |
43a122 |
[ -b $livedev ] && fs=$(blkid -s TYPE -o value $livedev)
|
|
Harald Hoyer |
43a122 |
if [ "$fs" = "iso9660" -o "$fs" = "udf" ]; then
|
|
Harald Hoyer |
43a122 |
@@ -146,7 +148,30 @@ do_live_overlay() {
|
|
Harald Hoyer |
43a122 |
base=$BASE_LOOPDEV
|
|
Harald Hoyer |
43a122 |
over=$OVERLAY_LOOPDEV
|
|
Harald Hoyer |
43a122 |
fi
|
|
Harald Hoyer |
43a122 |
- echo 0 $sz snapshot $base $over p 8 | dmsetup create live-rw
|
|
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 |
+
|
|
Harald Hoyer |
43a122 |
+ # In block units (512b)
|
|
Harald Hoyer |
43a122 |
+ thin_data_sz=$(( $overlay_size * 1024 * 1024 / 512 ))
|
|
Harald Hoyer |
43a122 |
+ thin_meta_sz=$(( $thin_data_sz / 10 ))
|
|
Harald Hoyer |
43a122 |
+
|
|
Harald Hoyer |
43a122 |
+ # It is important to have the backing file on a tmpfs
|
|
Harald Hoyer |
43a122 |
+ # this is needed to let the loopdevice support TRIM
|
|
Harald Hoyer |
43a122 |
+ dd if=/dev/null of=/run/initramfs/thin-overlay/meta bs=1b count=1 seek=$((thin_meta_sz)) 2> /dev/null
|
|
Harald Hoyer |
43a122 |
+ dd if=/dev/null of=/run/initramfs/thin-overlay/data bs=1b count=1 seek=$((thin_data_sz)) 2> /dev/null
|
|
Harald Hoyer |
43a122 |
+
|
|
Harald Hoyer |
43a122 |
+ THIN_META_LOOPDEV=$( losetup --show -f /run/initramfs/thin-overlay/meta )
|
|
Harald Hoyer |
43a122 |
+ THIN_DATA_LOOPDEV=$( losetup --show -f /run/initramfs/thin-overlay/data )
|
|
Harald Hoyer |
43a122 |
+
|
|
Harald Hoyer |
43a122 |
+ echo 0 $thin_data_sz thin-pool $THIN_META_LOOPDEV $THIN_DATA_LOOPDEV 1024 1024 | dmsetup create live-overlay-pool
|
|
Harald Hoyer |
43a122 |
+ dmsetup message /dev/mapper/live-overlay-pool 0 "create_thin 0"
|
|
Harald Hoyer |
43a122 |
+
|
|
Harald Hoyer |
43a122 |
+ # Create a snapshot of the base image
|
|
Harald Hoyer |
43a122 |
+ echo 0 $sz thin /dev/mapper/live-overlay-pool 0 $base | dmsetup create live-rw
|
|
Harald Hoyer |
43a122 |
+ else
|
|
Harald Hoyer |
43a122 |
+ echo 0 $sz snapshot $base $over p 8 | dmsetup create live-rw
|
|
Harald Hoyer |
43a122 |
+ fi
|
|
Harald Hoyer |
43a122 |
|
|
Harald Hoyer |
43a122 |
# Create a device that always points to a ro base image
|
|
Harald Hoyer |
43a122 |
echo 0 $sz linear $base 0 | dmsetup create --readonly live-base
|