Enlarge LXD VM Disk

I covered how to create an Ubuntu LXD Virtual Machine in June 2022. Unfortunately, the default disk on a LXD VM image is only about 10GB. This tutorial leverages skills in the last video “Linux Disk Drives” to enlarge a LXD VM disk drive.

We created a Debian Bullseye LXD Virtual Machine with the following command on your configured LXD host:

lxc init images:debian/11 --vm Test-VM --profile default --profile bridgeprofile -c boot.autostart=true -c limits.cpu=4 -c limits.memory=4GiB

“bridgeprofile” is a profile to bridge the container to the main LAN. You should watch my tutorial on LXD 101 where I cover configuring the bridge if this is unfamiliar to you.

To enlarge the size of the disk for the VM, perform the following command on the LXD host setting your desired size.

lxc config device override Test-VM root size=100GiB

Start the LXD VM:

lxc start Test-VM

Connect to the exec console of the VM after about 2 minutes.

lxc exec Test-VM bash

Be sure to update the VM. Note that sudo is not needed since “exec” runs as root.

apt update && apt upgrade -y

The “df” command lists your disk size which is not changed at this point.

df

Install the following two utilities:

apt install cloud-guest-utils
apt install fdisk

Now grow your partition. the root disk partition should be “sda2” from the “df” command.

growpart /dev/sda   2

At this point you have grown the partition size to use the new space, but the file system is still the original size inside of the partition.

Resize the file system:

resize2fs /dev/sda2

Now a “df” command will show that the root partition has grown larger.