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
|
|
|
|
|
2024-01-03 06:58:41 +00:00
|
|
|
growpart "${PARENT_ROOT_DEVICE}" "${ROOT_PARTITION}" && GP_OK='true'
|
|
|
|
resize2fs "${ROOT_DEVICE}" && RESIZE_OK='true'
|
|
|
|
|
|
|
|
if [[ "${GP_OK}" == 'true' && "${RESIZE_OK}" == 'true' ]]; then
|
|
|
|
systemctl disable expand-rootfs.service
|
|
|
|
rm /etc/systemd/system/expand-rootfs.service
|
|
|
|
systemctl daemon-reload
|
|
|
|
rm /usr/local/bin/expand-rootfs.sh
|
|
|
|
fi
|