diff options
Diffstat (limited to 'modules.d/slx-dmsetup/hooks/s3-grow-rootfs.sh')
-rwxr-xr-x | modules.d/slx-dmsetup/hooks/s3-grow-rootfs.sh | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/modules.d/slx-dmsetup/hooks/s3-grow-rootfs.sh b/modules.d/slx-dmsetup/hooks/s3-grow-rootfs.sh new file mode 100755 index 00000000..b93c5658 --- /dev/null +++ b/modules.d/slx-dmsetup/hooks/s3-grow-rootfs.sh @@ -0,0 +1,45 @@ +#!/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). + +. /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 +} + +[ -b "$SLX_DNBD3_DEVICE_COW" ] && resize_rootfs +# non-critical, so always fake success +true |