generic-arm64-kickstart/includes/rootfs-expand.ksi

33 lines
920 B
Plaintext
Raw Permalink Normal View History

2022-12-17 23:23:41 +00:00
%post
2023-11-08 03:54:35 +00:00
cat << EOF > /usr/local/bin/rootfs-expand
#!/usr/bin/env bash
set -euf -o pipefail
2022-12-17 23:23:41 +00:00
2023-11-08 03:54:35 +00:00
ROOT_PART=\$(mount | grep ' on / ' | awk '{print \$1}')
if [[ \${ROOT_PART} =~ "mmcblk" || \${ROOT_PART} =~ "nvme" ]]; then
DEV=\$(echo "\${ROOT_PART}" | rev | sed -r 's/^.{2}//' | rev)
INTERMEDIATE_DEV="\${DEV}p"
elif [[ \${ROOT_PART} =~ "vd" || \${ROOT_PART} =~ "sd" ]]; then
DEV=\$(echo "\${ROOT_PART}" | rev | sed -r 's/^.{1}//' | rev)
INTERMEDIATE_DEV="\${DEV}"
else
>&2 echo "\$0: device type unsupported"
exit 1
2022-12-17 23:23:41 +00:00
fi
2023-11-08 03:54:35 +00:00
PART_NUM="\${ROOT_PART#"\$INTERMEDIATE_DEV"}"
echo "\${DEV} \${PART_NUM} \${ROOT_PART}"
echo "Extending partition \${PART_NUM} of \${DEV} to max size..."
growpart "\${DEV}" "\${PART_NUM}"
echo "Resising ext4 filesystem on \${ROOT_PART}..."
resize2fs "\${ROOT_PART}"
2022-12-17 23:23:41 +00:00
echo "Done."
2023-11-08 03:54:35 +00:00
df -kh | head -n 1 && df -kh | grep "\${DEV}" | sort
2022-12-17 23:23:41 +00:00
EOF
chmod +x /usr/local/bin/rootfs-expand
%end