Launch Incus VM with Custom root Partition Size
By chimo on (updated on )This is "part 3" of the Virtual Machines with Incus on an Alpine Linux Host blog post saga. In this post we'll have a look at what I needed to do to resize the root partition of the VM that was created in part 1.
After (re)setting to
root password and gaining access to the VM, I set out to do some of the
actual work I needed this VM for. After installing tools and dependencies, I
ran into some disk space issues. A df -h
showed the /dev/sda2 partition being
99% full at 3.9G.
Which I found odd since I had specified a root disk of 10GiB while launching the VM:
incus launch images:alpine/3.21/amd64 alpine-vm --vm \
-c security.secureboot=false --device root,size=10GiB
Astute readers might have noticed something odd with the fdisk
output from
the previous post:
fdisk -l /var/lib/incus/virtual-machines/alpine-vm/root.img
Disk ./root.img: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 438F2735-BBFD-42BF-AB24-E40D80434790
Device Start End Sectors Size Type
./root.img1 2048 206847 204800 100M EFI System
./root.img2 206848 8388574 8181727 3.9G Linux filesystem
The disk (root.img) is 10GiB, but the partitions only amount to 4GiB. I knew
that after resizing a disk, the filesystem needs to be resized as well, but
since that step wasn’t mentioned anywhere (or anywhere obvious to me) I had
assumed that this was done automatically. Furthermore, I would’ve expected to
see some free space in the fdisk
output to grow the partition with, but this
didn’t seem to be the case.
As it turns out, all this resizing might be automatic, but only when using the “cloud” version of a VM. Otherwise, the following needs to be done on the VM:
# Install tools
apk add cloud-utils-growpart e2fsprogs-extra
# Grow the root partition
growpart /dev/sda 2
# Resize the filesystem
resize2fs /dev/sda2