Incus VM and disk size limit

Hi,

I launched a new virtual machine:

$ incus launch local:debian-with-ssh-keys  test-mongo --vm -d root,size=25GiB -c 'security.secureboot=false' -c 'limits.memory=4096MiB'

But the resulting machine appears to have only a 5GB disk, of which 4GB are available on the root partition.

root@test-mongo:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           390M  664K  389M   1% /run
/dev/sda2       4.0G  1.4G  2.2G  39% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            50M   22M   29M  43% /run/incus_agent
/dev/sda1        99M   12M   87M  12% /boot/efi
tmpfs           390M     0  390M   0% /run/user/0

After taking a second look, it appears that with btrfs, if I run

root@test-mongo:~# btrfs filesystem resize max /
Resize device id 1 (/dev/sda2) from 3.90GiB to max

the rest of the 25GiB appear. Is there a way to bake this right into the image without just piling on the first-start systemd unit or using something like cloud-init?

Also, how do I select to create a slim “cloud-only” image, instead of a fat image with everything?

I am currently running incus 1:6.11-debian12-202504032034.

If you include cloud-init in your custom VM image, then it should handle the resize for you, at least it does for ext4.

Otherwise, you may need to ship a systemd unit similar to our incus-growpart.service which will handle the growpart+btrfs resize on boot.

The fact that your partition was the correct size here suggests that incus-growpart is in your image, it just failed to do the resize2fs as it’s not on ext4.

If you used distrobuilder directly to produce that image, you could contribute to distrobuilder to template the incus-growpart.service unit so it runs the correct command based on the filesystem selected.

As for what makes it into the image, it really depends on how you build it. If that was done using distrobuilder, then you can tweak the YAML with whatever you want in there, though our images are pretty minimal to begin with.

Thank you! I’ll see what I can do there. I dimly remember that there was a growfs or so error message on boot. As for cloud images vs. “normal” images, I think I once had a cloud image at around 130MB, whereas the normal image is somewhere between 300 and 400MB. Especially if you have a slow network, this makes a difference.

I’ve come up with a small patch to the debian-upstream.yaml file that should do the trick.

--- debian-upstream.yaml.orig	2025-03-18 16:26:39.612199195 +0000
+++ debian-upstream.yaml	2025-04-13 21:55:26.448000000 +0000
@@ -1121,6 +1121,26 @@
   types:
   - vm
 
+- path: /usr/bin/resize-filesystem.sh
+  generator: dump
+  mode: 0755
+  uid: 0
+  gid: 0
+  content: |-
+    #!/bin/sh
+
+    set -e
+    partition="$1"
+    mountpoint="`mount | grep -F ${partition} | awk '{ print $3; }' `"
+    fstype="`mount | grep -F ${partition} | awk '{ print $5 }' `"
+    if [ ${fstype} = 'btrfs' ]; then
+            /usr/bin/btrfs filesystem resize max ${mountpoint}
+    else
+            /sbin/resize2fs ${partition}
+    fi
+    exit $?
+
+
 - name: meta-data
   generator: cloud-init
   variants:

This script needs to be called from the systemd unit instead of just executing the resize2fs command.

I didn’t like my previous patch too much, so here’s another one that works without an external script, but one needs to tolerate that one of the units will fail:

--- debian-upstream.yaml.orig	2025-03-18 16:26:39.612199195 +0000
+++ debian-upstream.yaml.small	2025-04-14 14:48:51.972000000 +0000
@@ -1428,9 +1428,9 @@
     set -eux
 
     # Automatic disk resize
-    cat << EOF > /etc/systemd/system/incus-growpart.service
+    cat << EOF > /etc/systemd/system/incus-growpart-ext4.service
     [Unit]
-    Description=Incus - grow root partition
+    Description=Incus - grow root partition (ext4)
 
     [Service]
     Type=oneshot
@@ -1441,7 +1441,21 @@
     WantedBy=default.target
     EOF
 
-    systemctl enable incus-growpart
+    cat << EOF > /etc/systemd/system/incus-growpart-btrfs.service
+    [Unit]
+    Description=Incus - grow root partition (btrfs)
+
+    [Service]
+    Type=oneshot
+    ExecStartPre=-/usr/bin/growpart /dev/sda 2
+    ExecStart=/usr/bin/btrfs filesystem resize max /
+
+    [Install]
+    WantedBy=default.target
+    EOF
+
+    systemctl enable incus-growpart-ext4
+    systemctl enable incus-growpart-btrfs
   types:
   - vm