<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lennart&#039;s weblog &#187; kvm</title>
	<atom:link href="http://blog.karssen.org/tag/kvm/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.karssen.org</link>
	<description>Open source, computers, Africa and other more (or less) interesting stuff.</description>
	<lastBuildDate>Thu, 02 Feb 2012 19:15:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Cloning Ubuntu virtual machines: some problems (and solutions)</title>
		<link>http://blog.karssen.org/2009/12/13/cloning-ubuntu-virtual-machines-some-problems-and-solutions/</link>
		<comments>http://blog.karssen.org/2009/12/13/cloning-ubuntu-virtual-machines-some-problems-and-solutions/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 13:33:09 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[nfs]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[virtual machine]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=55</guid>
		<description><![CDATA[Yesterday I set up a KVM virtual machine on my new Ubuntu 9.10 server. The VM also ran Ubuntu 9.10 server. In order to do some performance tests (what would be the speed up of having the VM&#8217;s disks on an LVM LV on the host, compared to having them in a file on the [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I set up a KVM virtual machine on my new Ubuntu 9.10 server. The VM also ran Ubuntu 9.10 server. In order to do some performance tests (what would be the speed up of having the VM&#8217;s disks on an LVM LV on the host, compared to having them in a file on the host) I used virt-clone to clone the machine:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">virt-clone <span style="color: #660033;">--connect</span>=qemu:<span style="color: #000000; font-weight: bold;">///</span>system <span style="color: #660033;">-o</span> testldap <span style="color: #660033;">-n</span> testldap-lvm <span style="color: #660033;">-f</span> testldap-lvm<span style="color: #000000; font-weight: bold;">/</span>ubuntu-kvm<span style="color: #000000; font-weight: bold;">/</span>disk0.qcow2</pre></div></div>

<p>This clones the VM named <em>testldap</em> to <em>testldap-lvm</em> and put its disk file in the subdirectory <em>testldap-lvm/ubuntu-kvm/</em>. After that I still had to convert this qcow2 image to it&#8217;s location in an LV, but that&#8217;s not what this post is about. </p>
<p>As the machine is cloned, the MAC address of its virtual NIC is also changed. The &#8216;source&#8217; VM had 52:54:00:f2:cc:40, the new VM was given 00:16:36:46:34:42. As I booted the new VM I noticed it wouldn&#8217;t come up as expected. I couldn&#8217;t reach it via the fixed IP that I had given the source VM (even though the source VM was shut down, of course). Closer inspection revealed that the interface name for the NIC in the new VM had changed. I vaguely remembered that Debian-derived distro&#8217;s do that: because they don&#8217;t want NIC name assignments (eth0, eth1, etc.) to change if a new network adapter is added, they tie a name to a MAC address. And, as noted, the MAC address had indeed changed in the cloning process. </p>
<p>The assignments between MAC and <em>eth?</em> name are recorded in the file <em>/etc/udev/rules.d/70-persistent-net.rules</em>. They are set by the script <em>/lib/udev/write_net_rules</em>, so I removed the execute permissions on that file. However, this was not a clean solution, since it resulted in an error on start up. I found that editing <em>/lib/udev/rules.d/75-persistent-net-generator.rules</em> is a far better solution. Adding the lines</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ignore KVM virtual interfaces</span>
ENV<span style="color: #7a0874; font-weight: bold;">&#123;</span>MATCHADDR<span style="color: #7a0874; font-weight: bold;">&#125;</span>==<span style="color: #ff0000;">&quot;52:54:00:*&quot;</span>, <span style="color: #007800;">GOTO</span>=<span style="color: #ff0000;">&quot;persistent_net_generator_end&quot;</span>
<span style="color: #666666; font-style: italic;"># This seems to be the range used by Xen, but also by virt-clone</span>
ENV<span style="color: #7a0874; font-weight: bold;">&#123;</span>MATCHADDR<span style="color: #7a0874; font-weight: bold;">&#125;</span>==<span style="color: #ff0000;">&quot;00:16:36:*&quot;</span>, <span style="color: #007800;">GOTO</span>=<span style="color: #ff0000;">&quot;persistent_net_generator_end&quot;</span></pre></div></div>

<p>seems to do the trick (don&#8217;t forget to remove the rules already added in <em>/etc/udev/rules.d/70-persistent-net.rules</em>). Make sure to add them after the lines</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># read MAC address</span>
ENV<span style="color: #7a0874; font-weight: bold;">&#123;</span>MATCHADDR<span style="color: #7a0874; font-weight: bold;">&#125;</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$attr</span>{address}&quot;</span></pre></div></div>

<p>so that the variable <em>MATCHADDR</em> has a value. I documented this solution in <a href="https://bugs.launchpad.net/ubuntu/+source/udev/+bug/345234">the Ubuntu bug report</a> that seemed the most appropriate as well. </p>
<p>This solved one problem. Then the next problem reared its ugly head: Both the source VM and the clone refused to finish their boot process, they kept hanging on the NFS mounts defined in <em>/etc/fstab</em>. The only option <em>mountall</em> gave was to enter the root password (after pressing ESC) or type Crtl-D to continue. Doing the latter resulted in nothing but an infinite wait. In <a href="https://bugs.launchpad.net/ubuntu/+source/mountall/+bug/461133">an Ubuntu bug report</a> I found that using DHCP for the network interface would solve the problem. And, indeed it did. However, since I want static IP addresses for my servers this was not a solution that I liked. Much to my surprise the NFS mounts worked perfectly after changing the interface (in <em> /etc/network/interfaces</em>) back to static. I don&#8217;t know why, but on both VMs I set the configuration for <em>eth0</em> from static to dhcp, rebooted, changed it back to static and rebooted again to find the problem solved&#8230; Strange!</p>
<p>Update 2009-12-18:<br />
As it turns out, the solution to the mount problem doesn&#8217;t always work. I tried it again, but now it failed to work after switchting back from DHCP to a static IP. I guess it has something to do with the lease time of the IP, because in the case I described above there was a night between using the DHCP IP and turning static back on. So somewhere, something needs to time out before switching back from DHCP to static IPs works again. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2009/12/13/cloning-ubuntu-virtual-machines-some-problems-and-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

