{"id":181,"date":"2020-01-29T18:02:47","date_gmt":"2020-01-30T02:02:47","guid":{"rendered":"https:\/\/www.lucaswilliams.net\/?p=181"},"modified":"2020-01-29T18:02:50","modified_gmt":"2020-01-30T02:02:50","slug":"manually-migrating-vms-from-one-kvm-host-to-another","status":"publish","type":"post","link":"https:\/\/www.lucaswilliams.net\/index.php\/2020\/01\/29\/manually-migrating-vms-from-one-kvm-host-to-another\/","title":{"rendered":"Manually Migrating VM&#8217;s from one KVM host to another"},"content":{"rendered":"\n<p>Hello everyone! Been a while since I posted a blog. This one was a doozy. I tried to find this information online and there was a ton to peruse through. Luckily, I was able to peice a few of them together to finally get it working the way I needed for my environment.<\/p>\n\n\n\n<p>So, this is what I was doing. I needed to retire a KVM host, but it was running a couple of VM&#8217;s that I couldn&#8217;t migrate using virt-manger or with <code>virsh migrate<\/code> so I decided I would try to just move the qcow2 files and build them from new. <\/p>\n\n\n\n<p>That did not work at all. <\/p>\n\n\n\n<p>So, after researching some solutions, I finally have one that works, and I&#8217;m going to share it with you now.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p><strong>NOTE:<\/strong> I shared my public ssh keys between the hosts so I don&#8217;t need to type passwords in when ssh&#8217;ing and scp&#8217;ing between the hosts.<\/p>\n\n\n\n<p>First, power off the VM on the original host if it is running:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>virsh stop &lt;vm name><\/code><\/pre>\n\n\n\n<p>Now, I had to <code>chown<\/code> the storage file since I don&#8217;t enable root on any of my systems and I needed to scp the file from one host to the new host:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo chown wililupy:wililupy server.qcow2<\/code><\/pre>\n\n\n\n<p>I could then scp it to the server where I keep my vm storage. <\/p>\n\n\n\n<p><strong>NOTE:<\/strong> The path for the storage of my VM&#8217;s is the same on both hosts, if it is different for you, you are going to have to make some modifications to the xml file that is part of the next step.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>scp server.qcow2 host2:\/data\/vms<\/code><\/pre>\n\n\n\n<p>I then ssh into the new host and <code>chown<\/code> the file back to <code>root:root<\/code>.<\/p>\n\n\n\n<p>Back on the first host machine, I execute:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>virsh dumpxml server > ~\/server.xml<\/code><\/pre>\n\n\n\n<p>I then change to root using sudo and copy the NVRAM file for my host since I use UEFI for my VM&#8217;s:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo -s\ncd \/var\/lib\/libvirt\/qemu\/nvram\ncp server_VARS.fd ~wililupy\nexit\ncd ~\nsudo chown wililupy:wililupy server_VARS.fd<\/pre>\n<\/div><\/div>\n\n\n\n<p>I then scp&#8217;d the <code>server_VARS.fd<\/code> and the <code>server.xml<\/code> files to the new host:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">scp server_VARS.fd server.xml host2:~<\/pre>\n\n\n\n<p>I then ssh&#8217;d to the new host and perform the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">virsh define server.xml\nsudo chown root:root server_VARS.fd\nsudo mv server_VARS.fd \/var\/lib\/libvirt\/qemu\/nvram<\/pre>\n\n\n\n<p>I was then able to start my VM&#8217;s on my new host and everything worked perfectly.<\/p>\n\n\n\n<p><code>virsh start server<\/code><\/p>\n\n\n\n<p>NOTE: My new host and old host had the same network and storage for the VM paths the same, which made this integration much easier. If yours are different, you will have to modify the xml file to match your new hosts information otherwise network will not work or the VM won&#8217;t find the storage correctly.<\/p>\n\n\n\n<p>Leave me a comment if this helps or you need some pointers! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello everyone! Been a while since I posted a blog. This one was a doozy. I tried to find this information online and there was a ton to peruse through. Luckily, I was able to peice a few of them together to finally get it working the way I needed for my environment. So, this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,49,6],"tags":[55,50,85,86,5,84],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-howto","category-kvm","category-ubuntu","tag-howto","tag-kvm","tag-migrate","tag-offline","tag-ubuntu","tag-vm"],"_links":{"self":[{"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":1,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":182,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/posts\/181\/revisions\/182"}],"wp:attachment":[{"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lucaswilliams.net\/index.php\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}