Expanding VM Disk Size on LXD

Mon, Aug 7, 2023 2-minute read

In this blog post, we’ll be discussing a simple and straightforward way to expand the disk size of a Virtual Machine (VM) on LXD using a cloud-init image. The image will auto-expand once we pass the appropriate configuration.

Initial VM Disk Status

Initially, the VM disk size looks like this:


ubuntu@umbrel:~$ df -h
Filesystem        Size  Used Avail Use% Mounted on
/dev/sda2         9.3G  9.3G    0G 100% /

As you can see, the /dev/sda2 filesystem is fully utilized.

Expanding VM Disk Size from the Host

To expand the disk size, we first shut down the VM then override the root device size from the host:


> $ lxc config device override myvm root size=20GiB                                                                                                                                                                                                                           

Device root overridden for myvm

Then, we start the VM:


> $ lxc start umbrel

Verifying the New VM Disk Size

Once the VM has started, we can verify the new size of the VM disk:


ubuntu@umbrel:~$ df -h
Filesystem        Size  Used Avail Use% Mounted on
/dev/sda2          20G  9.3G   10G  49% /

As you can see, the /dev/sda2 filesystem has now expanded to 20GB, with 10GB available.

In conclusion, expanding the disk size of a VM on LXD is a straightforward process when using a cloud-init image. By passing the appropriate configuration, the image will auto-expand, allowing you to easily manage your VM’s disk space.

Remember to always keep an eye on your disk usage to ensure optimal performance of your VMs.

Happy coding!