Sunday 3 September 2023

Expand a logical volume used inside a VM

This expands a LV used as a virtual disk inside a virtual machine.

First expand the LV on the hypervisor

# lvextend -L500g /dev/vg_guests/lv_myvideo

# lvs|grep myvideo

  lv_myvideo      vg_guests     -wi-ao---- 500.00g

Reboot the hypervisor so all disks are rescanned. There's probably a way of doing this without a reboot but I couldn't figure out how to get that to work;

Check the VM can see the new disk size

# fdisk -l /dev/vdc

Disk /dev/vdc: 500 GiB, 536870912000 bytes, 1048576000 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

Disklabel type: dos

Disk identifier: 0x60117149

Device     Boot Start       End   Sectors  Size Id Type

/dev/vdc1        2048 838860799 838858752  400G 83 Linux

Before continuing, stop any processes using the disk and unmount it.

The partition is still 400G so, using fdisk, delete the primary partition and recreate accepting all defaults, except...

Do not remove the existing disk signature

Do you want to remove the signature? [Y]es/[N]o: N

If you accidentally do remove it, repairing the disk should get it back.

# xfs_repair -L /dev/vdc1


Verify the new size

# fdisk -l /dev/vdc1

Disk /dev/vdc1: 500 GiB, 536869863424 bytes, 1048573952 sectors

Finally remount and grow the file system.

# xfs_growfs /dev/vdc1