sbc-images/scripts/expand-rootfs.sh
2023-09-13 06:59:56 +05:30

23 lines
677 B
Bash
Executable File

#!/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}"
xfs_growfs -d /