summaryrefslogtreecommitdiffstats
path: root/modules.d/slx-dmsetup/scripts/grow-rootfs.sh
diff options
context:
space:
mode:
authorJonathan Bauer2020-05-13 11:04:02 +0200
committerJonathan Bauer2020-05-13 11:04:02 +0200
commit1130873aa55c9b0a7e5af48edc44bd6c6fd1f888 (patch)
tree0fcfa186cd631d8d36611b3d4bc509fd38841d51 /modules.d/slx-dmsetup/scripts/grow-rootfs.sh
parentMerge branch 'centos8' into downloader (diff)
downloadsystemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.gz
systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.xz
systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.zip
restructure repo
* remove packager * move everything from builder/* back to root
Diffstat (limited to 'modules.d/slx-dmsetup/scripts/grow-rootfs.sh')
-rw-r--r--modules.d/slx-dmsetup/scripts/grow-rootfs.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/modules.d/slx-dmsetup/scripts/grow-rootfs.sh b/modules.d/slx-dmsetup/scripts/grow-rootfs.sh
new file mode 100644
index 00000000..e2603835
--- /dev/null
+++ b/modules.d/slx-dmsetup/scripts/grow-rootfs.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# This tried 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).
+
+. /etc/openslx
+
+declare -Ag growfs_helpers growfs_targets growfs_opts
+# xfs
+growfs_helpers[xfs]="xfs_growfs"
+growfs_targets[xfs]="$NEWROOT"
+growfs_opts[xfs]="-d"
+# ext4
+growfs_helpers[ext4]="resize2fs"
+growfs_targets[ext4]="$SLX_DNBD3_DEVICE_COW"
+growfs_opts[ext4]=""
+
+resize_rootfs() {
+ # First let's check what filesystem it is
+ local 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//\"/}"
+ if [ ! "${growfs_helpers[${fstype}]+set}" ]; then
+ echo "'$fstype' not supported - ignoring."
+ return 1
+ fi
+ if ! hash "${growfs_helpers[${fstype}]}" &> /dev/null; then
+ echo "'$fstype' is supported, but cannot find helper binary - ignoring."
+ return 1
+ fi
+ if ! "${growfs_helpers[${fstype}]}" ${growfs_opts[$fstype]} "${growfs_targets[$fstype]}"; then
+ echo "Failed to run '${growfs_helpers[${fstype}]}' on '${growfs_targets[$fstype]}'."
+ return 1
+ fi
+ return 0
+} &> /run/openslx/rootfs-grow.log
+
+[ -b "$SLX_DNBD3_DEVICE_COW" ] && resize_rootfs
+# non-critical, so always fake success
+true