{"id":2293,"date":"2016-10-09T08:52:17","date_gmt":"2016-10-09T06:52:17","guid":{"rendered":"http:\/\/possiblelossofprecision.net\/?p=2293"},"modified":"2021-05-15T11:46:37","modified_gmt":"2021-05-15T09:46:37","slug":"migrating-a-virtual-machine-from-kvm-to-esxi","status":"publish","type":"post","link":"https:\/\/possiblelossofprecision.net\/?p=2293","title":{"rendered":"Migrating a virtual machine from KVM to ESXi"},"content":{"rendered":"<p>Migrating a virtual machine from one host to another is usually no big deal if both hosts run the same <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hypervisor\">VMM<\/a>. But what if one wants to move a VM from a host running a different hypervisor than the target host? In the case of moving a VM from KVM to ESXi that&#8217;s just not (easily) possible. However, one can convert the virtual hard drive and recreate the virtual machine on the target host, which should be good enough for most use cases.<\/p>\n<p><!--more--><\/p>\n<h2>Exporting the virtual hard drive<\/h2>\n<p>To export the virtual hard drive on the KVM host, there&#8217;s a handy little command line tool called <a href=\"https:\/\/linux.die.net\/man\/1\/qemu-img\">qemu-img<\/a>, which is usually part of the distribution running KVM. On Fedora, RHEL and CentOS it can be installed with:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nyum install qemu-img\r\n<\/pre>\n<p>Let&#8217;s convert a image file from <var>raw<\/var> to <var>vmdk<\/var>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nqemu-img convert -f raw \/var\/lib\/libvirt\/images\/VM.img -O vmdk VM.tmp.vmdk -o compat6\r\n<\/pre>\n<p>For a list of supported formats have a look at the <a href=\"https:\/\/linux.die.net\/man\/1\/qemu-img\">qemu-img manpage<\/a>. We can now copy the resulting <var>vmdk<\/var> file <code>VM.tmp.vmdk<\/code> to the target ESXi host, e.g. using scp.<\/p>\n<h2>Importing the vmdk file<\/h2>\n<p>Even though we&#8217;ve just created a <var>vmdk<\/var> image file, it cannot be used as a virtual hard drive for a VM on ESXi. If you try to create a virtual machine with this particular <var>vmdk<\/var> file as hard drive, you&#8217;ll most likely get a error message in <code>\/var\/log\/hostd.log<\/code> similar to this:<\/p>\n<pre class=\"brush: plain; title: \/var\/log\/hostd.log; notranslate\" title=\"\/var\/log\/hostd.log\">\r\n&#x5B;...]\r\nPower On message: Failed to open disk scsi0:0: Unsupported or invalid disk type 7.  Ensure that the disk has been imported.\r\n&#x5B;...]\r\n<\/pre>\n<p>Fortunately, on ESXi there&#8217;s another handy command line tool for handling <var>vmdk<\/var> image files, called <a href=\"https:\/\/pubs.vmware.com\/vsphere-60\/index.jsp?topic=%2Fcom.vmware.vsphere.storage.doc%2FGUID-A5D85C33-A510-4A3E-8FC7-93E6BA0A048F.html\">vmkfstools<\/a>. However before we import the <var>vmdk<\/var> image file it is advisable to create a directory for the new virtual machine on the datastore first. This allows you to put the imported image into the correct directory (i.e. the directory where ESXi keeps all the files concerting one particular VM) straight away.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n~ # mkdir \/vmfs\/volumes\/datastore0\/New-VM\r\n~ # vmkfstools -i \/vmfs\/volumes\/datastore0\/VM.tmp.vmdk  -d thin \/vmfs\/volumes\/datastore0\/New-VM\/New-VM.vmdk\r\nDestination disk format: VMFS thin-provisioned\r\nCloning disk '\/vmfs\/volumes\/datastore0\/VM.tmp.vmdk'...\r\nClone: 100% done.\r\n<\/pre>\n<p>Of course, there are <a href=\"https:\/\/pubs.vmware.com\/vsphere-60\/index.jsp#com.vmware.vsphere.storage.doc\/GUID-9CC98802-82D9-44B0-9735-97675258FAAE.html\">other disk formats available<\/a>, too. You can throw away the original <code>VM.tmp.vmdk<\/code> image file after the import was completed successfully<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nrm \/vmfs\/volumes\/datastore0\/VM.tmp.vmdk\r\n<\/pre>\n<p>You can now go ahead an create a new virtual machine on the target host using the newly imported vmdk file <code>\/vmfs\/volumes\/datastore0\/New-VM\/New-VM.vmdk<\/code> as a virtual hard drive. But depending on your VM, you might want to change the type of the hard drive from ide to scsi first:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n~ # sed -i 's\/ddb.adapterType = &quot;ide&quot;\/ddb.adapterType = &quot;lsilogic&quot;\/' \/vmfs\/volumes\/datastore0\/New-VM\/New-VM.vmdk \r\n<\/pre>\n<h2>Making adjustments to the virtual machine<\/h2>\n<p>Booting the newly created virtual machine might not work straight away, e.g. on Fedora, RHEL and CentOS the UUID of the hard drive is included in the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Initramfs\">initial RAM file system<\/a>. The easiest way to fix this is to boot into <var>rescue mode<\/var> (there&#8217;s usually a rescue mode entry in the grub boot menu) and run<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ndracut --regenerate-all --force\r\n<\/pre>\n<p>to recreate the initramfs. You might also have to edit your network configuration since your network device usually get&#8217;s a different name.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Migrating a virtual machine from one host to another is usually no big deal if both hosts run the same VMM. But what if one wants to move a VM from a host running a different hypervisor than the target host? In the case of moving a VM from KVM to ESXi that&#8217;s just not (easily) possible. However, one can&#8230; <a href=\"https:\/\/possiblelossofprecision.net\/?p=2293\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[13,7,12],"class_list":["post-2293","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-centos","tag-fedora","tag-vmware"],"_links":{"self":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2293"}],"version-history":[{"count":12,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2293\/revisions"}],"predecessor-version":[{"id":2411,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/2293\/revisions\/2411"}],"wp:attachment":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}