2021-02-04 09:45:00 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2022-01-19 15:50:19 +01:00
|
|
|
# Credits to hassos-expand original script
|
|
|
|
# https://github.com/home-assistant/operating-system/
|
|
|
|
|
2022-09-29 14:02:47 +02:00
|
|
|
DEVICE_OVERLAYFS="$(findfs PARTUUID=f1326040-5236-40eb-b683-aaa100a9afcf)"
|
|
|
|
DEVICE_OVERLAYFS_NAME="$(basename "${DEVICE_OVERLAYFS}")"
|
|
|
|
DEVICE="/dev/$(lsblk -no pkname "${DEVICE_OVERLAYFS}")"
|
|
|
|
PART_NUM="$(cat "/sys/class/block/${DEVICE_OVERLAYFS_NAME}/partition")"
|
2022-01-19 15:50:19 +01:00
|
|
|
PART_TABLE="$(sfdisk -lqJ "${DEVICE}")"
|
|
|
|
|
|
|
|
if sfdisk --verify "${DEVICE}" 2>&1 | grep "The backup GPT table is not on the end of the device."; then
|
|
|
|
echo "[INFO] Moving GPT backup header to the end"
|
|
|
|
sfdisk --relocate gpt-bak-std "${DEVICE}"
|
|
|
|
|
|
|
|
# Reload partition label to get correct .partitiontable.lastlba
|
|
|
|
PART_TABLE="$(sfdisk -lqJ "${DEVICE}")"
|
|
|
|
fi
|
|
|
|
LAST_USABLE_LBA="$(echo "${PART_TABLE}" | jq -r '.partitiontable.lastlba')"
|
|
|
|
|
|
|
|
echo "[INFO] Last usable logical block ${LAST_USABLE_LBA}"
|
2021-02-04 09:45:00 +01:00
|
|
|
|
2022-09-29 14:02:47 +02:00
|
|
|
JQ_FILTER=".partitiontable.partitions[] | select ( .node == \"${DEVICE_OVERLAYFS}\" ) | .start + .size"
|
|
|
|
OVERLAYFS_PARTITION_END="$(echo "${PART_TABLE}" | jq "${JQ_FILTER}")"
|
|
|
|
echo "[INFO] Overlayfs partition end block ${OVERLAYFS_PARTITION_END}"
|
2021-02-04 09:45:00 +01:00
|
|
|
|
2022-01-19 15:50:19 +01:00
|
|
|
UNUSED_BLOCKS=$(( LAST_USABLE_LBA - DATA_PARTITION_END ))
|
|
|
|
if [ "${UNUSED_BLOCKS}" -le "16384" ]; then
|
2022-09-29 14:02:47 +02:00
|
|
|
echo "[INFO] No resize of overlayfs partition needed"
|
2021-02-04 09:45:00 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2022-09-29 14:02:47 +02:00
|
|
|
echo "[INFO] Update Overlayfs partition ${PART_NUM}"
|
2022-01-19 15:50:19 +01:00
|
|
|
echo ", +" | sfdisk --no-reread --no-tell-kernel -N "${PART_NUM}" "${DEVICE}"
|
|
|
|
sfdisk -V "${DEVICE}"
|
|
|
|
partx -u "${DEVICE}"
|
|
|
|
udevadm settle
|
|
|
|
partprobe "${DEVICE}"
|
|
|
|
|
2022-09-29 14:02:47 +02:00
|
|
|
echo "[INFO] Resizing the overlayfs partition"
|
|
|
|
resize2fs "${DEVICE_OVERLAYFS}"
|
2022-01-19 15:50:19 +01:00
|
|
|
echo "[OK]"
|