How can I expand the size of VM

The disk image created by LXD is 10GB by default, but the image unpacked into it is smaller.

When using distro images with cloud-init, it auto resizes the partition and filesystem inside the VM on first boot.

However when using non-cloud-init based images it is necessary to do it yourself.

These commands work for me on our centos 7 image:

Before:

df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        489M     0  489M   0% /dev
tmpfs           495M     0  495M   0% /dev/shm
tmpfs           495M  6.5M  488M   2% /run
tmpfs           495M     0  495M   0% /sys/fs/cgroup
/dev/sda2       3.8G  913M  2.9G  25% /

Resize:

yum install e2fsprogs cloud-utils-growpart gdisk
growpart /dev/sda 2
resize2fs /dev/sda2

After:

df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        489M     0  489M   0% /dev
tmpfs           495M     0  495M   0% /dev/shm
tmpfs           495M  6.5M  488M   2% /run
tmpfs           495M     0  495M   0% /sys/fs/cgroup
/dev/sda2       8.9G  914M  8.0G  11% /
9 Likes