Is it possible to do online resizing of guest block devices ( Or without shutdown ?)

Today I got this question,

Is it possible to resize the guest block device without shutting down the guest? Or in another way, Is it possible to do online resizing of guest block devices ?

The answer was ‘YES‘, it is possible with a switch called ‘blockresize’ of ‘virsh’ command :

Below example would illustrate this method in a simple way:

Inside guest, the second ‘disk’ has ‘512M’ Space.

[terminal]
[root@guest ~]# fdisk -l /dev/vdb

Disk /dev/vdb: 524 MB, 524288000 bytes, 1024000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[/terminal]

Now on host we resize the LVM ( which is the backend or the underlying space for second disk of VM)  to 1 GB

[terminal]
# lvresize -L 1024M /dev/mapper/VMDISK-lvm1
Extending logical volume lvm1 to 1.00 GiB
Logical volume lvm1 successfully resized
[/terminal]

Once above is done, then from the host OS I do the following:

[terminal]
[root@host ~]# virsh blockresize –path /dev/VMDISK/lvm1 –size 1024M
Block device ‘/dev/VMDISK/lvm1’ is resized
[/terminal]

After which from the guest we recheck again and see the following.

[terminal]
[root@guest ~]# fdisk -l /dev/vdb

Disk /dev/vdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[/terminal]

So, we were able to do ‘online’ resizing of guest block device using ‘blockresize’ of ‘virsh’ command’.

You should have quite a recent libvirt version for this support.

Additional Ref# http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=ab95da40587665063b0c8eaeae22c91003f0da1c

If your libvirt doesnot have support for online resize of guest block device, you may give a try with libguestfs, but its offline.

for complete guide on guest LVM and filesystem extension please refer https://humblec.com/complete-guide-to-extend-guest-disk-from-backend-lvm-and-filesystem-inside-kvm-guest/

Digiprove sealCopyright secured by Digiprove © 2020 Humble Chirammal

7 thoughts on “Is it possible to do online resizing of guest block devices ( Or without shutdown ?)”

  1. Thanks for help. It worked except the last step. So, I informed VM with the new size:

    # virsh blockresize –path

    it showed me that it is succedeed:
    Block device ‘/dev/alma-srv-1/alma-backup-1’ is resized

    VM noticed the new size:

    #dmesg
    virtio_blk virtio1: new size: 3145728000 512-byte logical blocks (1.61 TB/1.46 TiB)

    And kernel knows about new size:
    # lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    vda 254:0 0 1.5T 0 disk

    Also:
    # cat /sys/block/vda/size
    3145728000

    But fdisk, cfdisk, sfdisk, parted do not notice the new size:

    # fdisk -l /dev/vda
    Disk /dev/vda: 1073.7 GB, 1073741824000 bytes

    #cfdisk /dev/vda
    Disk Drive: /dev/vda
    Size: 1073741824000 bytes, 1073.7 GB

    What can it be? How can I update the size all partition utulities use?

    • Hi, Can you try below commands ..

      #parted -l, fdisk -l /dev/vda ( before and after #partprobe ).

      ‘partprobe’ may not be really needed.. still a try..

  2. I wasn’t aware about virsh blockresize option. Thanks a lot for sharing the details. It seems a syntax problem in 3rd output snippet –

    # virsh blockresize –path /dev/VMDISK/lvm1 –size 1024M

    I got following when tried

    # virsh blockresize –path /dev/vg1/lv1 –size 10240M
    error: command ‘blockresize’ requires option

    Thanks a lot for such a good article !.

    Cheers ….

Comments are closed.