[Resizing Partitions] - cloud-guest-utils
Created by: RobertCNelson
Investigate into transitioning to cloud-guest-utils for auto resizing on first bootup..
Anyway, on the off-chance you're unaware, you can simply add
cloud-guest-utils to the installed package list when building an image,
then automatically resize the partition on the first boot. A snippit
from a debootstrap second-stage script which sets this up via systemd
follows.
NOTE: The growpart utility is just a shell script, so you could also
potentially use it as a reference to do online resizing w/o requiring a
reboot in your grow_partition.sh script.
# Resize root partition on the first boot
# ==========
# Create a systetmd service file
cat > /etc/systemd/system/resize_rootfs.service << EOF_resize
[Unit]
Description=Resize root file system
After=basic.target
[Service]
Type=oneshot
ExecStartPre=-/usr/bin/growpart /dev/mmcblk0 ${ROOTPARTN}
ExecStart=-/sbin/resize2fs /dev/mmcblk0${ROOTPART}
ExecStartPost=/bin/systemctl disable resize_rootfs
[Install]
WantedBy=multi-user.target
EOF_resize
# Enable the new service
systemctl enable resize_rootfs