<?xml version="1.0"?>
<rss version="2.0"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:dcterms="http://purl.org/dc/terms/" >
<channel>
<title>xen - Justin&#x27;s Ramblings</title>
<link>http://bouncybouncy.net//ramblings/tags/xen/</link>
<description>BB.Net</description>
<item>
	
	<title>xen live migration without shared storage</title>
	
	<guid>http://bouncybouncy.net//ramblings/posts/xen_live_migration_without_shared_storage/</guid>
	<link>http://bouncybouncy.net//ramblings/posts/xen_live_migration_without_shared_storage/</link>
	
	
	<category>tags/tech</category>
	
	<category>tags/xen</category>
	
	
	<pubDate>Sat, 16 Feb 2008 17:02:25 -0500</pubDate>
	<dcterms:modified>2008-02-19T03:51:14Z</dcterms:modified>
	
	<description><![CDATA[<h2>The problem</h2>
<p>The <a href=
"http://www.cl.cam.ac.uk/research/srg/netos/xen/readmes/user/user.html#SECTION03520000000000000000">
Xen documentation on live migration states</a>:</p>
<blockquote>
<p>Currently, there is no support for providing automatic remote
access to filesystems stored on local disk when a domain is
migrated. Administrators should choose an appropriate storage
solution (i.e. SAN, NAS, etc.) to ensure that domain filesystems
are also available on their destination node. GNBD is a good method
for exporting a volume from one machine to another. iSCSI can do a
similar job, but is more complex to set up.</p>
</blockquote>
<p>This does not mean that it is impossible though. Live migration
is a more efficient migration, and migration can be seen as a save
on one node, and a restore on another. Normally, if you save a VM
on one machine, and try to restore it on another machine, it will
fail when it is unable to read its filesystems. But what would
happen if you coppied the filesystem to the other node between the
save and restore? If done right, it works pretty well.</p>
<h2>The solution?</h2>
<p>The solution is simple:</p>
<ul>
<li>Save running image</li>
<li>Sync disks</li>
<li>copy image to other node, restore</li>
</ul>
<p>This can be somewhat sped up by syncing the disks twice:</p>
<ul>
<li>Sync disks</li>
<li>Save running image</li>
<li>Sync disks - only having to save any changes in the last few
seconds</li>
<li>copy image to other node, restore</li>
</ul>
<h3>Syncronizing block devices</h3>
<h4>File backed</h4>
<p>If you are using plain files as vbds, you can sync the disks
using rsync.</p>
<h4>Raw devices</h4>
<p>If you are using raw devices, rsync can not be used. I wrote a
small utility called <a href="http://bouncybouncy.net//ramblings/tags/xen/../../../programs/blocksync.py">blocksync</a> which can syncronize
2 block devices over the network. In my testing it was easily able
to max out the network on an initial sync, and max out the disk
read speed on a resync.</p>
<p>$ blocksync.py /dev/xen/vm-root 1.2.3.4</p>
<p>Will sync /dev/xen/vm-root onto 1.2.3.4. The device should
already exist on the destination and be the same size.</p>
<h4>Solaris ZFS</h4>
<p>If you are using ZFS, it should be possible to use <code>zfs
send</code> to sync the block devices before migration. This would
give an almost instantaneous sync time.</p>
<h2>Automation</h2>
<p>A simple script <a href="http://bouncybouncy.net//ramblings/tags/xen/../../../programs/xen_migrate.sh">xen
migrate.sh</a> and its helper <a href="http://bouncybouncy.net//ramblings/tags/xen/../../../programs/xen_vbds.py">xen vbds.py</a> will migrate a
domain to another host. File and raw vbds are supported. <code>ZFS
send</code> support is not yet implemented.</p>
<h3>Example migration</h3>
<div class="syntax">
<pre>
<span class=
"synComment">#migrating a 1G / + 128M swap over the network</span>
<span class=
"synComment">#physical machines are 350mhz with 64M of ram,</span>
<span class="synComment">#total downtime is about 3 minutes</span>

xen1:~# time ./migrate.sh test 192.168.1.2
+ <span class="synConstant">'['</span> 2 -ne 2 <span class=
"synConstant">']'</span>
+ DOMID=test
+ DSTHOST=192.168.1.2
++ xen_vbds.py test
+ FILES=/dev/xen/test-root
/dev/xen/test-swap
+ main
+ check_running
+ xm list test
Name              Id  Mem(MB)  CPU  State  Time(s)  Console
test              87       15    0  -b---      0.0    9687
+ sync_disk
+ blocksync.py /dev/xen/test-root 192.168.1.2
ssh -c blowfish 192.168.1.2 blocksync.py server /dev/xen/test-root -b 1048576
same: 942, diff: 82, 1024/1024
+ blocksync.py /dev/xen/test-swap 192.168.1.2
ssh -c blowfish 192.168.1.2 blocksync.py server /dev/xen/test-swap -b 1048576
same: 128, diff: 0, 128/128
+ save_image
+ xm save test test.dump
+ sync_disk
+ blocksync.py /dev/xen/test-root 192.168.1.2
ssh -c blowfish 192.168.1.2 blocksync.py server /dev/xen/test-root -b 1048576
same: 1019, diff: 5, 1024/1024
+ blocksync.py /dev/xen/test-swap 192.168.1.2
ssh -c blowfish 192.168.1.2 blocksync.py server /dev/xen/test-swap -b 1048576
same: 128, diff: 0, 128/128
+ copy_image
+ scp test.dump 192.168.1.2:
test.dump                                       100%   16MB   3.2MB/s   00:05
+ restore_image
+ ssh 192.168.1.2 <span class=
"synConstant">'xm restore test.dump &amp;&amp; rm test.dump'</span>
(domain
    (id 89)
    [domain info stuff cut out]
)
+ rm test.dump

real    6m6.272s
user    1m29.610s
sys     0m30.930s


</pre>
<span class="synTitle"><a href=
"http://www.bouncybouncy.net//ramblings/files/example_migration.txt">download
file "/ramblings/files/example_migration.txt"</a></span></div>

]]></description>
	
</item>

</channel>
</rss>
