LXD VM - how to set disk size?

Is it possible to set VM disk size?

Something akin to --disk from multipass:

multipass launch 20.04 -v --disk 10G --name testvm

I know I can resize the disk using qemu-img, but a handy shortcut like --disk in multipass would be great.

Alternatively, how to add a disk of a given size to an existing LXD VM?

You can set that with:
lxc config device override [vm name] root size=15GB

Right, but that only resized the disk, but not the filesystem. So one needs to boot up the VM, remove the partition, readd it, reboot, resize the fs etc.

“multipass launch 20.04 -v --disk 10G --name testvm” launches a VM with a filesystem which is already 10 GB in size and ready to use.

lxc init lets you create without starting.

You need an image which supports resizing on boot, not all do.

Is there still no way to define root disk size at launch ?

Yes there is since LXD 5.8:

But there was a problem with it when combined with using -s flag for specifying the storage pool which was fixed in LXD 5.9. These changes should be in the forthcoming LXD 5.0.2 LTS release too.


lxc launch images:ubuntu/jammy v1 -d root,size=15GiB

Is equivalent to:

lxc init images:ubuntu/jammy v1
lxc config device override v1 root size=15GiB
lxc start v1

It can be used to override any device setting, not just disk size.

If you use an image with cloud-init in it the guest will notice the larger disk size on boot and grow the guest filesystem too. Otherwise that needs to be done manually inside the VM, as LXD does not know/dictate what partition layout or filesystem a VM uses.