[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-users] How can I duplicate a running guest OS in Xen ?

  • To: tim.post@xxxxxxxxxxx
  • From: Nico Kadel-Garcia <nkadel@xxxxxxxxx>
  • Date: Sat, 28 Apr 2007 07:13:11 +0100
  • Cc: xen-users@xxxxxxxxxxxxxxxxxxx, openbsd shen <openbsd.shen@xxxxxxxxx>
  • Delivery-date: Fri, 27 Apr 2007 23:09:56 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=ZzNZRpFHnkDUfnCwPCDWjiMXA5n/Jb6l3+1HLY606abh4jYjhtVrjPjg1EgsQWtSjSJssMaujIubhYLHv1ZPCDANzBxJRTPF/3BUaAZrFf/7dQEVaaf4PZzQi0BwXV9siC8iYnmbY9PZ/Tydd9J3372Boo1T7bgHUYRQVOKdCWc=
  • List-id: Xen user discussion <xen-users.lists.xensource.com>

Tim Post wrote:
On Sat, 2007-04-28 at 09:58 +0800, openbsd shen wrote:
When a guest OS is running in Xen, how can I duplicate it?


There is no "elegant" way to do this if the guest is running. The best
way I've found is to follow these steps :

1.) On dom-0 create a vbd of equal size (or the size you want for your
clone). This can be a loop, lv , whatever.

2.) xm block-attach it to the running dom-U

Use rsync on the live OS to push to a mounted partition of another OS. Be sure to exclude /proc, /sys, and similar mount run-time created directories, and manally push things like /dev/null and /sev/serial that reside under the udev created countents of /dev/ For databases which cannot safely be duplicated while live, exclude them from the push and use tools like mysqldump to dump them to pushable text files.

I use this technique to create nightly backup snapshots with "rsnapshot" for recovery purposes. Works pretty well!

3.) Enter the dom-u, most likely you will have to use mknod to create
the device for the new drive in /dev (probably going to be sdc1 if its a
pv guest) in which case you'd type 'mknod /dev/sdc1 b 8 33'
4.) Format it (this can also be done on dom-0) and mount it.

5.) Use rsync or a similar utility to make a copy of the root file
system. Get only the stuff you need.

6.) Once copy is done, unmount the second fs, 'sync' and exit the dom-u

7.) Go to dom-0 xm block-detach the cloned drive. create your config for
the new VM, make a swap vbd for it, get it all set up. Mount the file
system in dom-0 and make your edits in etc/ to change networking (ip and
That's where I do the rsync stuff one final time, with the shutdown and manually mounted filesystem. This also avoids the target having to be the same size or even set up with the same filesystems. Or if the target need not be absolutely identical, such as slave copies of master servers, it allows in-vivo operations to preserve configurations of the slave.

8.) Unmount and boot the new clone :)

Like another poster has said, if your current dom-u is under heavy
stress (lots of SQL activity or so) this isn't the best idea even using
the above method which doesn't need to worry about locking. You still
should watch inodes like you would in any other regular GNU/Linux

If you are running database servers, you should dump -> import them from
old to new after booting the clone so that they're identical. Lots of
stuff could have changed after rsync left /var/lib.

Hope this helps, --Tim
And you should be dumping them regularly as part of backup and recovery techniques.

Xen-users mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.