~drscream

Migrate from libvirt to SmartOS

We currently migrate our infrastructure from Linux libvirt based KVM to SmartOS. Most of the services could be moved to zones but some should also run on Linux. So we like to migrate the existing qcow2- or raw-image to SmartOS.

This could be done really simple.

  1. Convert the existing linux image to raw if it is a qcow image.
  2. Sync the raw image to an temporary folder, for example /opt/tmp.
  3. Create a KVM virtual machine via vmadm create on your SmartOS host system. JSON example
  4. Get the disk0 from the KVM image on the SmartOS host.
  5. dd the raw image to the disk0.
  6. Start the new linux image on SmartOS.

Now from the theory to the required commands :-)

[linux-kvm]# qemu-img convert -O raw linux-vm.qcow2 linux-vm.raw
[linux-kvm]# scp linux-vm.raw smartos-host:/opt/tmp

[smartos-host]# vmadm create -f linux-vm.json
Successfully created VM fee9be01-6d2e-4e43-a958-57ad4668d5b7

[smartos-host]# vmadm info fee9be01-6d2e-4e43-a958-57ad4668d5b7 block
{
  "block": [
    {
        [...]
        "file": "/dev/zvol/rdsk/zones/fee9be01-6d2e-4e43-a958-57ad4668d5b7-disk0"
      },
      "type": "hd"
    },
    [...]

[smartos-host]# vmadm stop fee9be01-6d2e-4e43-a958-57ad4668d5b7
[smartos-host]# dd if=linux-vm.raw of=/dev/zvol/rdsk/zones/fee9be01-6d2e-4e43-a958-57ad4668d5b7-disk0 bs=1M

Hints:

  • Be sure to turn off the linux-vm before convert to raw
  • Stop the virtual machine before dd the data to disk0
  • Create the new disk0 with the exact size of the raw image

  1. Jonas says:

    Thu 23/03/17, 4:20 pm

    Hi, great little howto. Just want to mention, that getting info of a vm with vmadm does not work for a stopped vm - at least on my machine. Best, Jonas

    /

  2. drscream says:

    Mon 27/03/17, 3:57 pm

    Thanks you for the info, I will update the blog post I maybe missed that point!

    /

Send your comment by mail.