How can I expand the size of VM

I created centos7 virtual machine. But when I go into the virtual machine, I see a capacity of root ( / ) about 4GB. How can I increase the capacity root ( / ) of virtual machines to 15GB?

Despite following the instructions of this article, I still cannot change as expected => LXD VM - how to set disk size?

screenshot_1

screenshot_2

Which image are you using.

I have same LXC container for Centos 7 running and I have enough disk for root

[root@mongo-cent ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 108G 29G 74G 29% /
none 492K 0 492K 0% /dev

Please paste output of below commands

lxc remote list
lxc image list

Also, how much capacity do you have on your hosts root FS?

1 Like

Thanks for your reply!

Please note that I created vm with lxd, not containers. And this is my output

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% /
3 Likes

@tomp Many thanks tomp. Very easy to follow. I was successful

[root@localhost ~]# 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  489M   2% /run
tmpfs           495M     0  495M   0% /sys/fs/cgroup
/dev/sda2       8.9G  917M  8.0G  11% /
/dev/sda1        99M   11M   88M  12% /boot/efi
1 Like