summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorSimon Rettberg2024-01-29 15:09:23 +0100
committerSimon Rettberg2024-01-29 15:09:23 +0100
commit75568a191bed499d12818cd474cf4474b406b6ab (patch)
treed1bae52c1b040d500962f879be9de8065a55b891 /core
parent[run-virt] Split mounting of /tmp/virt into own service (diff)
downloadmltk-75568a191bed499d12818cd474cf4474b406b6ab.tar.gz
mltk-75568a191bed499d12818cd474cf4474b406b6ab.tar.xz
mltk-75568a191bed499d12818cd474cf4474b406b6ab.zip
[bwlp-stage4-tweaks] Add service to grow rootfs to blockdev size
This was previously done in initrd, but it turns out this was happening rather late and blocked the switchroot for a couple seconds. Let's do it in stage 4 instead as early as possible, and order it before gather-hw-info.service, as that service will determine the rootfs free space and needs to see the properly resized rootfs.
Diffstat (limited to 'core')
-rw-r--r--core/modules/bwlp-stage4-tweaks/data/etc/systemd/system/grow-rootfs.service9
l---------core/modules/bwlp-stage4-tweaks/data/etc/systemd/system/sysinit.target.wants/grow-rootfs.service1
-rw-r--r--core/modules/bwlp-stage4-tweaks/data/opt/openslx/scripts/systemd-grow_rootfs53
3 files changed, 63 insertions, 0 deletions
diff --git a/core/modules/bwlp-stage4-tweaks/data/etc/systemd/system/grow-rootfs.service b/core/modules/bwlp-stage4-tweaks/data/etc/systemd/system/grow-rootfs.service
new file mode 100644
index 00000000..60985596
--- /dev/null
+++ b/core/modules/bwlp-stage4-tweaks/data/etc/systemd/system/grow-rootfs.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Grow size of rootfs to underlying block device
+DefaultDependencies=no
+Before=gather-hw-info.service
+
+[Service]
+Type=oneshot
+RemainAfterExit=true
+ExecStart=/opt/openslx/scripts/systemd-grow_rootfs
diff --git a/core/modules/bwlp-stage4-tweaks/data/etc/systemd/system/sysinit.target.wants/grow-rootfs.service b/core/modules/bwlp-stage4-tweaks/data/etc/systemd/system/sysinit.target.wants/grow-rootfs.service
new file mode 120000
index 00000000..57dd5ae4
--- /dev/null
+++ b/core/modules/bwlp-stage4-tweaks/data/etc/systemd/system/sysinit.target.wants/grow-rootfs.service
@@ -0,0 +1 @@
+../grow-rootfs.service \ No newline at end of file
diff --git a/core/modules/bwlp-stage4-tweaks/data/opt/openslx/scripts/systemd-grow_rootfs b/core/modules/bwlp-stage4-tweaks/data/opt/openslx/scripts/systemd-grow_rootfs
new file mode 100644
index 00000000..a1b9d22a
--- /dev/null
+++ b/core/modules/bwlp-stage4-tweaks/data/opt/openslx/scripts/systemd-grow_rootfs
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+# This tries to call growfs helpers (xfs_growfs, resize2fs, ...) to resize
+# the root filesystem mounted on $NEWROOT to the maximum size of the backing
+# disk partition (done by dmsetup-slx-device).
+
+. /opt/openslx/config
+
+if [ -z "$SLX_DNBD3_DEVICE_COW" ]; then
+ SLX_DNBD3_DEVICE_COW="$( awk '$2 == "/" {print $1; exit}' /proc/mounts )"
+fi
+if ! [ -b "$SLX_DNBD3_DEVICE_COW" ]; then
+ echo "Cannot grow rootfs on '$SLX_DNBD3_DEVICE_COW' - not a block device"
+ exit 0
+fi
+
+resize_rootfs() {
+ # First let's check what filesystem it is
+ local fstype helper
+ declare -a options
+ fstype="$(blkid "$SLX_DNBD3_DEVICE_COW" | grep -oE 'TYPE=\S+')"
+ if [ -z "$fstype" ]; then
+ echo "Failed to detect filesystem on '$SLX_DNBD3_DEVICE_COW' - ignoring."
+ return 1
+ fi
+ fstype="${fstype#TYPE=}"
+ fstype="${fstype//\"/}"
+ case "$fstype" in
+ ext?)
+ helper="resize2fs"
+ options=()
+ ;;
+ xfs)
+ helper="xfs_growfs"
+ options=( "-d" )
+ ;;
+ *)
+ echo "'$fstype' not supported - ignoring."
+ return 1
+ ;;
+ esac
+ if ! hash "${helper}" &> /dev/null; then
+ echo "'$fstype' is supported, but cannot find helper binary - ignoring."
+ return 1
+ fi
+ if ! "${helper}" "${options[@]}" "$SLX_DNBD3_DEVICE_COW"; then
+ echo "Failed to run '${helper}' on '${SLX_DNBD3_DEVICE_COW}'."
+ return 1
+ fi
+ return 0
+}
+
+resize_rootfs