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

33 lines
920 B
Plaintext

%post
cat << EOF > /usr/local/bin/rootfs-expand
#!/usr/bin/env bash
set -euf -o pipefail
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
fi
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}"
echo "Done."
df -kh | head -n 1 && df -kh | grep "\${DEV}" | sort
EOF
chmod +x /usr/local/bin/rootfs-expand
%end