Online resizing block devices and file systems

Here is a short reference sheet for resizing block devices and file systems.

Resizing block devices

Logical volumes

Add 100 GiB to the logical volume with name logicalvolume in volume group volumegroup.

# lvextend -L +100G volumegroup/logicalvolume 

QEMU block device

If you resized a block device which is used to store a virtual disk for a QEMU VM, you will need to expand the virtual disk itself. First we need to know the name of the virtual disk. If you are managing your QEMU VMs via libvirt, you can use this command to see all virtual disks:

# virsh qemu-monitor-command VMname – hmp "info block"
drive-virtio-disk0 (#block108): /dev/vm/web-www (raw)
    Attached to:      /machine/peripheral/virtio-disk0/virtio-backend
    Cache mode:       writeback, direct

drive-virtio-disk1 (#block302): /dev/vm/web-logs (raw)
    Attached to:      /machine/peripheral/virtio-disk1/virtio-backend
    Cache mode:       writeback, direct

Then if you resized the logical volume /dev/vm/web-www from 100 to 200 GiB using the command mentioned before, you can resize the corresponding QEMU virtual disk drive-virtio-disk0 using this command:

# virsh qemu-monitor-command VMname – hmp "block_resize drive-virtio-disk0 200G"

Resizing file systems

When you have resized a block device, you will need to resize the file system on the block device too in order to use the disk space.

EXT4

# resize2fs /dev/vda

XFS

# xfs_growfs /var/www/

BTRFS

# btrfs filesystem resize max /var/www

Importing a VMWare virtual machine in qemu/kvm/libvirtd

So you have a VMWare virtual machine and you want to migrate it to Qemu/KVM setup managed by libvirt? This is very easy, using libguestfs.

You will need libguestfs 1.37.10 or higher, which unfortunately is not available for Debian Stretch. The libguestfs-tools package in Debian Buster is fine though.

The command you need is this:

$ virt-v2v -i vmx /mnt/storage/vmware/vm/vm.vmx -o libvirt -of qcow2 -os storage-pool -n network

Replace storage-pool with the name of the libvirt storage pool where you want to store the new VM it, and network by the network name. In this example the disk images will be converted to qemu’s qcow2 format.

To get a list of all available storage pools, use this:

$ virsh pool-list

This command will show all available networks:

$ virsh net-list