Publish/Export lxd virtual machines for use with other systems (virt-manager/vmware)

We have been testing lxd at work and between lxd and ansible we have been able to create workflows that are the same for both containers and virtual machines. The company is investing in vmware for its integration with other products we require and we maintain a significant number of qemu based systems that are not going away any time soon.

Q: How can we use the same workflows and vm images to create QEMU and vmware native systems? I realize I could just stick an iso in and rebuild the whole thing but we like the way LXD lets us work and are a lean team with less resources than this would require.

Please, please, please, tell me that migration is not a one way street #eagle-vs-kicad-vs-fusion
:slight_smile:
Thanks.

When you export a VM to a non-optimised tarball file, inside there is the VM’s root disk file.
It is in raw format, so if you can find a tool to convert that to the required format of your target system then that should be possible.

Ok so based on what I read and what you just suggested I am trying the following.

# lxc export isg-mon-02 -v --compression gzip --instance-only isg-lxd-vm.tgz
# tar -tzvf isg-lxd-vm.tgz
# tar -xzvf isg-lxd-vm.tgz backup/virtual-machine.img
# losetup -f backup/virtual-machine.img
# fdisk -lu  /dev/loop6
Disk /dev/loop6: 10 GiB, 10737418240 bytes, 20971520 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: gpt
Disk identifier: 39F8B3E1-F4C8-40B0-9148-CF49523F0BAA

Device        Start      End  Sectors  Size Type
/dev/loop6p1   2048   206847   204800  100M EFI System
/dev/loop6p2 206848 20971486 20764639  9.9G Linux filesystem

Which looks right and which I can convert to qcow2.

qemu-img convert -f raw -O qcow2 backup/virtual-machine.img vm_hdd.qcow2

But which doesn’t boot out of the box.

Is it worth looking at the other data to configure qemu appropriately (cpu type, devices where the os expects them etc)? Or should I just futz with it until I get a configuration that works?

Also is this something we can expect to not change without notice?

Exporting an lxd vm to virt-manager

Thank goodness I work with @Teaton . The missing piece is in the firmware which is also in the exported tar.

# lxc export isg-mon-02 -v --compression gzip --instance-only isg-lxd-vm.tgz
# tar -xzvf isg-lxd-vm.tgz backup/virtual-machine.img
# qemu-img convert -f raw -O qcow2 backup/virtual-machine.img /var/lib/libvirt/images/isg-mon-02.qcow2
# tar -xzvf isg-lxd-vm.tgz backup/virtual-machine/qemu.nvram
# cp backup/virtual-machine/qemu.nvram /var/lib/libvirt/qemu/nvram/isg-mon-02.nvram

Then use virt-manager to create a new kvm and adjust the new disk and qemu/nvram settings

# virsh edit isg-mon-02
..... blah blahh .....
  <os>
    <type arch='x86_64' machine='pc-i440fx-2.9'>hvm</type>
    <loader readonly='yes' type='pflash'>/usr/share/OVMF/OVMF_CODE.fd</loader>
    <nvram>/var/lib/libvirt/qemu/nvram/isg-mon-02.nvram</nvram>
    <boot dev='hd'/>
  </os>
..... more stuff .....
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/isg-mon-02.qcow2' index='1'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
    </disk>
....
virsh start isg-mon-02 --console

And that’s it. (aside from a bunch of other minor os adjustments).

1 Like