#!/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