ansible-debootstrap icon indicating copy to clipboard operation
ansible-debootstrap copied to clipboard

[Question] LVM for VMs

Open uumas opened this issue 6 years ago • 7 comments

I have a volume group (vg0) on a vm host platform, which has all vm root partitions as volumes (/dev/vg0/testvm-root). The vm sees the volume as /dev/vda. I've been trying for a while now, but can't figure out a way to handle this with this role. Is it possible without modifying this too much or do I basically need to reimplement the handling of partitions?

uumas avatar Jul 02 '19 00:07 uumas

Do you want to bootstrap the VM from the host system, without booting into a VM? I think this may be possible, you would specify the layout with the logical volume as underlying device, e.g.:

layout:
  - device: '/dev/vg0/testvm-root'
    partitions:
      - num: 1
        size: 1M
        type: ef02
      - num: 2
        size: 1022M
        type: 8300
      - num: 3
        type: 8300

What could be difficult is that the partition table may not be detected automatically (one would need to add a step to call partprobe) and perhaps the detection of device names is off - devices would probably be named /dev/maper/vg0-testvm--root--part1 etc.. I think I already wrote some code to better determine the device names when putting in nvme support.

Creating the fstab and finding the boot device should work already since it uses UUID.

Does this help at all?

nilsmeyer avatar Jul 02 '19 10:07 nilsmeyer

I should have been clearer. Yes, bootstrapping from the host would be ideal. I don't want multiple partitions, just one with no partition table so the root partition would be just /dev/vg0/testvm-root (/dev/vda, not /dev/vda1 on the vm). I use direct kernel boot, so a bootloader isn't needed at all.

uumas avatar Jul 02 '19 10:07 uumas

I see, that would require a few modification since I haven't thought about that particular use-case, so for example:

layout:
  - device: '/dev/vg0/testvm-root'
    fs: ext4
    mount: /

This doesn't work currently but shouldn't be too difficult to add.

nilsmeyer avatar Jul 02 '19 10:07 nilsmeyer

Would it be possible to implement it so that the lvm volume could be created automatically too, something like this maybe:

layout:
  - lvm:
      lv: "testvm-root"  
      vg: vg0  
      size: 5G  
      mount: /  
      fs: ext4

This isn't a great syntax, but you get the point.

uumas avatar Jul 02 '19 11:07 uumas

I think that would be somewhat out of scope for this ansible role, you can easily create the volume in your playbook beforehand. There are two additional caveats that I just now remembered:

  • You can only install one VM at a time
  • The role may not fully clean up after itself.

nilsmeyer avatar Jul 03 '19 09:07 nilsmeyer

Yeah, you're right. Installing one vm at a time is okay. What do you mean by may not fully clean up after itself

uumas avatar Jul 03 '19 09:07 uumas

I mean that it may create things on the host system that don't get removed, I've just looked at the cleanup task and it seems like at the very least I forgot to remove the bootstrap user and its SSH configuration from the host system. I haven't yet tried running this twice from the same box.

nilsmeyer avatar Jul 03 '19 09:07 nilsmeyer