clone volume group on bare-metal, import onto kvm virtual machine

Posted on

I have a bare-metal host, app03, with the following LVM setup:

$ sudo vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  vgdata   7   1   0 wz--n- 419.78g    0
  vgroot   3   1   0 wz--n- <39.44g    0
$ sudo lvs
  LV     VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lvdata vgdata -wi-ao---- 419.78g
  lvroot vgroot -wi-ao---- <39.44g

$ mount | grep -E 'boot|lvroot'
/dev/mapper/vgroot-lvroot on / type xfs (rw,relatime,attr2,inode64,noquota)
/dev/sda1 on /boot type ext4 (rw,relatime,data=ordered)
$

I would like to create a KVM VM that looks just like the app03 bare metal host; specifically it should use the copy of app03s root filesystem from app03 in vg=vgroot,lv=lvroot. I dont want the VM to have vg=vgdata,lv=lvdata.

I created an img file, with dd, of /dev/sda from block 0 up to and including the sda1 partition (which contains /boot).

I also created an img file, also with dd, with a command like this:

sudo dd if=/dev/vgroot/lvroot of=/export/data/app03-vgroot-lvroot.img bs=4096

I start the VM as follows:

$ sudo virt-install --name test --memory 8192 --disk path=/export/data/app03-sda1.img --disk path=/export/data/app03-vgroot-lvroot.img --boot hd --vcpus 4 --network network=default --os-type linux --os-variant rhel7 --graphics vnc --console pty,target_type=serial 

This boots up, but complains that it cant find the volume group and drops me to the dracut emergency shell. Specifically:

Warning: Could not boot.
Warning: /dev/mapper/vgroot-lvroot does not exist
Warning: /dev/vgroot/lvroot does not exist

So I need to tell the system somehow that the second disk I'm giving the VM should be vg=vgroot and lv=lvroot.

So, I have booted the VM with the ISO and went to a shell.

I can see the app03-vgroot-lvroot.img as /dev/vdb with lsblk. However, I see nothing when I run pvs and "vgimportclone /dev/vdb" returns: "Failed to find physical volume "/dev/vdb".

How can I get that block device set up as vg=vgroot, lv=lvroot? I need it to have this setup because I dont want to change the grub config from the original bare metal host, which is configured with: "rd.lvm.lv=vgroot/lvroot"

Responses