Skip to main content

KVM host, add LV to guest [Resolved]

I have a KVM host with a software RAID 10 array. The software RAID 10 array is a PV on the host and there's a single VG.

I have a couple of LVs used at the host level (a datastore for KVM guest .img files).

Normally when adding a new disk to a guest I create the LV on the host then add that to the guest's config. Then pvcreate directly on the block device (no partition), vgcreate, lvcreate and mkfs on the new block device within the guest.

I don't bother partitioning the block device before pvcreate because it's one less step to do when resizing the LV on the host. I realise the downside is in theory some systems might decide to automatically partition the unpartitioned block device because they don't recognise the LVM metadata, though I have never ever seen this happen in practice.

When resizing the LV on the host the free space in the PV is picked up and I have to vgextend, lvextend and resize2fs in the guest.
I don't suppose there's a way I can skip having LVM running in the guest and just lvextend on the host then resize2fs in the guest?


Question Credit: batfastad
Question Reference
Asked June 24, 2019
Tags:
Posted Under: Unix Linux
144 views
1 Answers

I don't suppose there's a way I can skip having LVM running in the guest and just lvextend on the host then resize2fs in the guest?

There's absolutely no requirement to use LVM inside a guest. You can just use the block device directly. Using LVM inside the guest gets you almost nothing (since you're already using LVM on the host to manage your space).

If by "KVM" you mean "libvirt", you can do use the virsh blockresize command to get your guest to recognize the additional space once you've resized a block device. That is, if I have a guest with an attached LV:

</disk><disk type="block" device="disk">
  <driver name="qemu" type="raw"/>
  <source dev="/dev/tank/foobar"/>
  <backingStore/>
  <target dev="vdb" bus="virtio"/>
  <alias name="virtio-disk1"/></disk>

Where:

# lvs
  foobar                                      tank           -wi-ao----   4.00g                                                              

I can add space to the LV on the host:

# lvresize -L +2G /dev/tank/foobar

Tell libvirt to update the size:

# virsh blockresize myguest /dev/tank/foobar --size 0

And then inside the guest, resize the filestem:

guest# resize2fs 1.42.12 (29-Aug-2014)
Resizing the filesystem on /dev/vdb to 1572864 (4k) blocks.
The filesystem on /dev/vdb is now 1572864 (4k) blocks long.

credit: larsks
Answered June 24, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA