Resize VM root disk inside Alpine image

It likely did, its just the filesystem inside the VM didn’t detect and resize on first boot.

LXD does not have control of the filesystems inside a VM so cannot resize them itself (unlike containers).

This is how to resize the root disk inside an Alpine VM:

lxc init images:alpine/3.16 v1 --vm -c security.secureboot=false
lxc config device override v1 root size=50GiB
lxc start v1
lxc shell v1
v1:~# df -h # root partition /dev/sda2 is too small.
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     490.3M         0    490.3M   0% /dev/shm
/dev/sda2                 3.7G    177.2M      3.5G   5% /
tmpfs                   196.1M    260.0K    195.9M   0% /run
/dev/sda1                98.4M    266.0K     98.2M   0% /boot/efi
config                  231.5G     38.8G    180.9G  18% /run/lxd_config/drive

Lets resize it:

v1:~# growpart /dev/sda 2
CHANGED: partition=2 start=206848 old: size=8181727 end=8388574 new: size=104650719 end=104857566
v1:~# resize2fs /dev/sda2
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 7
The filesystem on /dev/sda2 is now 13081339 (4k) blocks long.

v1:~# df -h # Now root /dev/sda2 is correct size.
Filesystem                Size      Used Available Use% Mounted on
devtmpfs                 10.0M         0     10.0M   0% /dev
shm                     490.3M         0    490.3M   0% /dev/shm
/dev/sda2                48.3G    182.7M     48.1G   0% /
tmpfs                   196.1M    260.0K    195.9M   0% /run
/dev/sda1                98.4M    266.0K     98.2M   0% /boot/efi
config                  231.5G     38.8G    180.9G  18% /run/lxd_config/drive

This is similar to How can I expand the size of VM - #4 by tomp

1 Like