<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.docking.org/index.php?action=history&amp;feed=atom&amp;title=How_to_Migrate_a_Virtual_Machine</id>
	<title>How to Migrate a Virtual Machine - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.docking.org/index.php?action=history&amp;feed=atom&amp;title=How_to_Migrate_a_Virtual_Machine"/>
	<link rel="alternate" type="text/html" href="http://wiki.docking.org/index.php?title=How_to_Migrate_a_Virtual_Machine&amp;action=history"/>
	<updated>2026-05-25T06:09:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.1</generator>
	<entry>
		<id>http://wiki.docking.org/index.php?title=How_to_Migrate_a_Virtual_Machine&amp;diff=10115&amp;oldid=prev</id>
		<title>Benrwong: Page describing how to migrate VMs from one host to another</title>
		<link rel="alternate" type="text/html" href="http://wiki.docking.org/index.php?title=How_to_Migrate_a_Virtual_Machine&amp;diff=10115&amp;oldid=prev"/>
		<updated>2017-05-23T18:24:36Z</updated>

		<summary type="html">&lt;p&gt;Page describing how to migrate VMs from one host to another&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page shall describe how to transfer a virtual machine from one hypervisor to another.  The instructions below assume you have two hosts that are functioning hypervisors.  &lt;br /&gt;
&lt;br /&gt;
===VM Images and .xml files===&lt;br /&gt;
There are only two things we need to transfer from a hypervisor in order to get it functioning on the new machine:  The VM disk image and the corresponding .xml file.&lt;br /&gt;
VM disk images are typically stored in /var/lib/libvirt/images or in some subdirectory under there.  &lt;br /&gt;
.xml files are typically stored in /etc/libvirt/qemu.  &lt;br /&gt;
&lt;br /&gt;
In below example, I will transfer the VM nu from the hypervisor he to the new hypervisor vav:&lt;br /&gt;
 # Transferring the .xml file for nu&lt;br /&gt;
 [root@he bulk]# cd /etc/libvirt/qemu/&lt;br /&gt;
 [root@he qemu]# ls&lt;br /&gt;
 alpha.xml  chi.xml      gamma.xml  nu.xml       phi.xml  sigma.xml     zeta.xml&lt;br /&gt;
 autostart  epsilon.xml  kappa.xml  omega.xml    psi.xml  tau.xml&lt;br /&gt;
 beta.xml   from_aleph   networks   omicron.xml  rho.xml  testraid.xml&lt;br /&gt;
I should transfer this .xml file to /etc/libvirt/qemu but I transfer it first to scratch to avoid permission denials due to no PermitRootLogin.  &lt;br /&gt;
 [root@he qemu]# scp nu.xml s_bwong1@vav:/scratch&lt;br /&gt;
 [root@vav qemu]# cp /scratch/nu.xml /etc/libvirt/qemu/&lt;br /&gt;
Transferring the VM image for nu; Prior to VM image transfer, you must freeze or shutdown the VM because copying a live VM can cause the copy to have corruption. &amp;lt;br /&amp;gt;&lt;br /&gt;
If the VM is running, do the following command: &lt;br /&gt;
 [root@he qemu]# virsh suspend nu&lt;br /&gt;
Ensure VM is off or suspended&lt;br /&gt;
 [root@he qemu]# virsh list --all&lt;br /&gt;
 Id    Name                           State&lt;br /&gt;
 ----------------------------------------------------&lt;br /&gt;
 13    alpha                          running&lt;br /&gt;
 18    beta                           running&lt;br /&gt;
 19    gamma                          running&lt;br /&gt;
 20    epsilon                        running&lt;br /&gt;
 21    tau                            running&lt;br /&gt;
 23    zeta                           running&lt;br /&gt;
 24    phi                            running&lt;br /&gt;
 25    omega                          running&lt;br /&gt;
 26    psi                            running&lt;br /&gt;
 27    omicron                        running&lt;br /&gt;
 28    chi                            running&lt;br /&gt;
 31    rho                            running&lt;br /&gt;
 -     kappa                          shut off&lt;br /&gt;
 -     nu                             shut off&lt;br /&gt;
 -     sigma                          shut off&lt;br /&gt;
 -     testraid                       shut off&lt;br /&gt;
Find the disk image.  Sometimes there are multiple disk images in the image directories.  There are a few ways to tell which disk image is the one you need and whether you need just one or several.&lt;br /&gt;
 [root@he from_aleph]# ls -lh&lt;br /&gt;
 total 555G&lt;br /&gt;
 -rwxr-----. 1 qemu qemu 445G May 23 04:12 alpha-share&lt;br /&gt;
 -rwxr-----. 1 qemu qemu 9.0G Nov 18  2014 beta-disk1&lt;br /&gt;
 -rwxr-----. 1 qemu qemu 5.5G Nov 18  2014 delta-disk1&lt;br /&gt;
 -rwxr-----. 1 qemu qemu  12G May 23 10:08 gamma-disk1&lt;br /&gt;
 -rwxr-----. 1 qemu qemu  33G May 23 10:08 gamma-disk2&lt;br /&gt;
 -rwxr-----. 1 qemu qemu  10G Nov 18  2014 nu-disk1&lt;br /&gt;
 -rwxr-----. 1 root root  12G Feb 13 13:37 nu-disk1.qcow2&lt;br /&gt;
 -rw-r-----. 1 qemu qemu  20G May 23 10:08 psi-disk1&lt;br /&gt;
 -rwxr-----. 1 root root 9.6G Mar 31  2015 zeta-disk1&lt;br /&gt;
nu has two disk images but only one of these is vital for the VM transfer.  Looking at the date, It seems the one with 12GB that was last used on Feb 13 of the current year is the correct one. &amp;lt;br /&amp;gt;&lt;br /&gt;
VMs are constantly updating when they are on, so the most recent date should correspond to the correct VM. &amp;lt;br /&amp;gt;&lt;br /&gt;
But if you need a surefire way of checking which VM image corresponds to the VM, then check the xml file for the vm with this command: &amp;lt;br /&amp;gt;&lt;br /&gt;
 [root@he from_aleph]# virsh dumpxml nu | grep &amp;#039;source\ file&amp;#039;&lt;br /&gt;
      &amp;lt;source file=&amp;#039;/var/lib/libvirt/images/bulk/nu-disk1.qcow2&amp;#039;/&amp;gt;&lt;br /&gt;
After we found the correct disk image, we&amp;#039;ll copy this over to our new hypervisor.  We want to copy this over to /var/lib/libvirt/images on the new host but we&amp;#039;ll put it on an all-accessible directory first so we can avoid &amp;lt;br /&amp;gt;&lt;br /&gt;
permission denials due to no PermitRootLogin.&lt;br /&gt;
 [root@he from_aleph]# scp /var/lib/libvirt/images/bulk/nu-disk1.qcow2 s_bwong1@vav:/scratch&lt;br /&gt;
 [root@vav scratch]# cp /scratch/nu-disk1.qcow2 /var/lib/libvirt/images&lt;br /&gt;
&lt;br /&gt;
===Defining then Running VM on New Hypervisor===&lt;br /&gt;
With both our VM images and our .xml files in the places they should be, we can get started on reconfigurations for the new host.  &lt;br /&gt;
 [root@vav ~]# ls -lh /var/lib/libvirt/images/&lt;br /&gt;
 total 165G&lt;br /&gt;
 -rwxr--r--. 1 qemu qemu 6.9G May 23 10:26 chronos-disk1&lt;br /&gt;
 -rw-r--r--. 1 root root  14G May  9 10:50 kappa-disk1.qcow2&lt;br /&gt;
 drwx------. 2 root root  16K Apr 24 15:52 lost+found&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;-rwxr-----. 1 root root  12G May 22 14:10 nu-disk1.qcow2&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
 -rw-r-----. 1 root root  16G May 22 14:32 omega-disk1.qcow2&lt;br /&gt;
 -rw-r-----. 1 root root  15G May 22 14:47 omicron-disk1.qcow2&lt;br /&gt;
 -rw-r-----. 1 root root  69G May 22 15:39 phi-disk1.qcow2&lt;br /&gt;
 -rw-r-----. 1 root root  20G May 22 15:55 psi-disk1&lt;br /&gt;
 -rwxr-----. 1 root root  15G May 22 16:06 zeta-disk1&lt;br /&gt;
 [root@vav ~]# ls -lh /etc/libvirt/qemu&lt;br /&gt;
 total 36K&lt;br /&gt;
 -rw-------. 1 root root 2.4K May  9 14:19 chronos.xml&lt;br /&gt;
 -rw-------. 1 root root 2.4K May  8 14:39 kappa.xml&lt;br /&gt;
 drwx------. 3 root root 4.0K May  9 14:14 networks&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;-rw-------. 1 root root 2.2K May 22 16:13 nu.xml&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
 -rw-------. 1 root root 2.4K May 22 16:13 omega.xml&lt;br /&gt;
 -rw-------. 1 root root 2.4K May 22 16:13 omicron.xml&lt;br /&gt;
 -rw-------. 1 root root 2.3K May 22 16:13 phi.xml&lt;br /&gt;
 -rw-------. 1 root root 2.2K May 22 16:13 psi.xml&lt;br /&gt;
 -rw-------. 1 root root 2.6K May 22 16:13 zeta.xml&lt;br /&gt;
Next step, we have to reconfigure the .xml file for our VM because it reflects configurations that were known on the old host but are foreign to our new host.  First, define the host by providing the .xml file as an argument.&lt;br /&gt;
 [root@vav ~]# virsh define /etc/libvirt/qemu/nu.xml&lt;br /&gt;
 Domain nu defined from /etc/libvirt/qemu/nu.xml&lt;br /&gt;
The VM nu previously belonged in the directory /var/lib/libvirt/images/bulk/ in the old host.  But in the new host, it is in /var/lib/libvirt/images.  The .xml file will have to be adjusted to reflect this change.  &lt;br /&gt;
 [root@vav ~]# virsh dumpxml nu | grep &amp;#039;source\ file&amp;#039;&lt;br /&gt;
 &amp;lt;source file=&amp;#039;/var/lib/libvirt/images/bulk/nu-disk1.qcow2&amp;#039;/&amp;gt;&lt;br /&gt;
Edit the xml file with the following command:&lt;br /&gt;
 [root@vav ~]# virsh edit nu&lt;br /&gt;
Change the line that contains the &amp;#039;source file&amp;#039; to the directory where your disk image actually resides now and then save your changes:&lt;br /&gt;
 &amp;lt;source file=&amp;#039;/var/lib/libvirt/images/nu-disk1.qcow2&amp;#039;/&amp;gt;&lt;br /&gt;
 Domain nu XML configuration edited.&lt;/div&gt;</summary>
		<author><name>Benrwong</name></author>
	</entry>
</feed>