sbc-images/scripts/expand-rootfs.sh

23 lines
688 B
Bash
Raw Normal View History

2023-09-13 01:29:56 +00:00
#!/usr/bin/env bash
set -xeu
if [[ ${EUID} -ne 0 || ${UID} -ne 0 ]]; then
>&2 echo "$0: error: please run this script as root"
exit 1
fi
ROOT_DEVICE=$(mount | grep 'on / ' | awk '{print $1}')
ROOT_PARTITION="${ROOT_DEVICE: -1}"
if [[ "${ROOT_DEVICE}" =~ "mmcblk" || "${ROOT_DEVICE}" =~ "nvme" ]]; then
PARENT_ROOT_DEVICE=$(echo "${ROOT_DEVICE}" | rev | sed -r 's/^.{2}//' | rev)
elif [[ "${ROOT_DEVICE}" =~ "vd" || "${ROOT_DEVICE}" =~ "sd" ]]; then
PARENT_ROOT_DEVICE=$(echo "${ROOT_DEVICE}" | rev | sed -r 's/^.{1}//' | rev)
else
>&2 echo "$0: device type unsupported"
exit 1
fi
growpart "${PARENT_ROOT_DEVICE}" "${ROOT_PARTITION}"
resize2fs "${ROOT_DEVICE}"