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

Leave a Reply

Your email address will not be published. Required fields are marked *