About

Using libvirt we can grow the size of partitions of a virtual drive without having to resize the partitions manually. This spares a lot of time and annoyances with having to boot a Live CD and then expand the partition by hand.

Requirements

The two tools necessary for this are: virt-filesystems and virt-resize, both of which can be found on Debian by installing the package libguestfs-tools:

aptitude install libguestfs-tools

Listing the Partitions Inside Images

Using virt-filesystems we can list he filesystems inside an image. Suppose that we have an image file called first.img stored in /var/lib/libvirt/images/ that is 8GB large and we would like to expand the storage and the filesystem to 50GB. We would first issue:

virt-filesystems --long -h --all -a /var/lib/libvirt/images/first.img

which would something like:

Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  ext4  -      -    8.0G  -
/dev/sda1  partition   -     -      83   8.0G  /dev/sda
/dev/sda   device      -     -      -    8.0G  -

This means that we have a filesystem inside the image as a partition named /dev/sda1 that has 8GB as expected.

Now we create a new image second.img based on the fist image using truncate:

truncate -r /var/lib/libvirt/images/first.img /var/lib/libvirt/images/second.img

Next, we expand the new image (second.img) to 50GB using truncate':

truncate -s +42GB /var/lib/libvirt/images/second.img

Finally, the filesystem inside the image that we found out lies at /dev/sda1 has to be expanded to fill the remaining space:

virt-resize --expand /dev/sda1 /var/lib/libvirt/images/first.img /var/lib/libvirt/images/second.img

and we are done.


unix/virtual_machines/resize_partitions_with_virsh.txt ยท Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.