base-image/files/grow-root

17 lines
389 B
Plaintext
Raw Normal View History

#!/bin/bash
dev="$(findmnt -nfvo SOURCE -- "/")"
# If it's a partition, expand that first using growpart.
if [ "$(lsblk -ndo TYPE -- "$dev")" = part ]; then
disk="$(lsblk -ndpo PKNAME -- "$dev")"
partnum="${dev##*[!0-9]}"
growpart "$disk" "$partnum" || { [ $? -ne 1 ] && exit 1; }
fi
# Inform kernel of new partition
partprobe
# Expand the filesystem.
resize2fs -- "$dev" || exit 1