[arch-releng] [PATCH 1/1] allow to grow devices

Christian Hesse list at eworm.de
Thu Aug 29 09:55:45 EDT 2013


From: Christian Hesse <mail at eworm.de>

actually cowfile_size is limited to values smaller or equal to 100. That
way you have to decide at iso build time what size your filesystems should
have.

I have added a feature to allow values bigger than 100: In this case the
read only device is linearly assembled with a sparse file (we do not have
to care about size on disk as no write go to this file), this device is
used for read only device then. After chroot (or when the system has
bootet up) you can grow your filesystem to the new size.

Growing the filesystem in initramfs would be possible, but we would have
to add userspace utilities (resize2fs, xfs_growfs, ...) there...
---
 archiso/initcpio/hooks/archiso | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/archiso/initcpio/hooks/archiso b/archiso/initcpio/hooks/archiso
index 66a6273..94d5a99 100644
--- a/archiso/initcpio/hooks/archiso
+++ b/archiso/initcpio/hooks/archiso
@@ -6,13 +6,28 @@ _mnt_fs() {
     local img_fullname="${img##*/}";
     local img_name="${img_fullname%%.*}"
     local dm_snap_name="${dm_snap_prefix}_${img_name}"
-    local ro_dev ro_dev_size rw_dev
+    local ro_dev ro_dev_size rw_dev rw_dev_size pad_dev pad_dev_size
 
     ro_dev=$(losetup --find --show --read-only "${img}")
     echo ${ro_dev} >> /run/archiso/used_block_devices
     ro_dev_size=$(blockdev --getsz ${ro_dev})
+
     if [[ "${cowfile_size}" == "100" ]]; then
         rw_dev_size=${ro_dev_size}
+    elif [[ "${cowfile_size}" -gt 100 ]]; then
+        pad_dev_size=$((ro_dev_size/100*cowfile_size - ro_dev_size))
+        dd of="/run/archiso/cowspace/${cow_directory}/${img_name}.pad" count=0 seek=${pad_dev_size} &> /dev/null
+        pad_dev=$(losetup --find --show --read-only "/run/archiso/cowspace/${cow_directory}/${img_name}.pad")
+        echo ${pad_dev} >> /run/archiso/used_block_devices
+        # this is just a sparse file that never gets written to, so just delete it
+        rm "/run/archiso/cowspace/${cow_directory}/${img_name}.pad"
+        echo -e "0 ${ro_dev_size} linear ${ro_dev} 0\n${ro_dev_size} ${pad_dev_size} linear ${pad_dev} 0" | dmsetup create "ro_${dm_snap_name}"
+
+        ro_dev="/dev/mapper/ro_${dm_snap_name}"
+        ro_dev_size="$((ro_dev_size + pad_dev_size))"
+        rw_dev_size="${ro_dev_size}"
+
+        msg ":: Device ${dm_snap_name} has been grown, remember to grow your filesystem!"
     else
         # size calculation done in this way to avoid integer overflow when ro_dev_size is > 10.2G
         rw_dev_size=$((ro_dev_size/100*cowfile_size))
-- 
1.8.4



More information about the arch-releng mailing list