Linux – Converting a live server to XEN domU

linuxvirtualizationxen

What are the steps of converting a live server as a XEN guest?

Here's my understanding of the process, please comment if you see any flaws with such thinking.

  • Install a xen guest kernel that would run on my target dom0.

Question: does XEN differentiate kernels by dom0/domU?

  • Backup partitions using dd tool to a safe place.

Here's my current server layout:

/dev/sda1              64G   49G   12G  81% /
tmpfs                 3,9G     0  3,9G   0% /lib/init/rw
udev                   10M   64K   10M   1% /dev
tmpfs                 3,9G     0  3,9G   0% /dev/shm

Question: I only need to dd /dev/sda1 out, right? How can I copy it in a consistent state without turning the machine off, without mounting it as readonly (I assume I'd lose network connectivity by doing so?), without physically being in the data centre to do so.

  • Prepare dom0 with LVM.
  • Create 2 LVs, one for /dev/sda1, one for swap.
  • dd the data in from earlier backups.
  • Boot?

I'm sure I've missed alot.

Best Answer

There's a couple of potential pitfalls here. First of all, you mention dd for backups. While dd can be a wonderful tool, it's not an ideal backup tool, and if you're referring to using it to backup a live machine, it's a very poor choice. You're going to have some really badly inconsistent data and may not end up with a working image file.

Also, one note for the future. . . always setup your disk layout with LVM (and leave a few GB unallocated in the Volume Group), as it makes these kinds of situations about a hundred times easier to deal with. If the partitions were logical volumes under LVM, you could snapshot them, and then make use of the snapshot to give you a fairly consistent image.

Now, how critical is it that this box stay up? If you can take it down for a few minutes, there are P2V (Physical to Virtual) converters that you can use to make this transition a lot easier.

What kind of hardware configuration are you dealing with? If you have mirrored disks (RAID1) you might be able to break the mirror, pull a disk, and bring up the yanked disk in a second box. You could then clone that non-production copy.

Another important thing to consider, is what are you using for Xen? Is it RHEL and the Xen that's included? Or is it Citrix XenServer (now free)? This makes a difference as they both expect (by default) a slightly different disk format. Manually building an image for XenServer is a bit more complicated than building one for stock Xen.

It may sound a little unorthodox, but I've actually had better success in this type of situation by doing a simple base Linux install on a separate box, then running rsync from the production box to the new box, and then converting the non-production rsync'ed clone into the Xen domU (I've even had some luck just rsynch'ing from the production box to a Xen domU). Just run rsync (I recommend the options -HavSux) the old box to the new one while it's running, and once the rsync has completed, run rsync again. The first one will take a while to run, and will leave you with a lot of inconsistencies. The second one will run faster and because it only has to pull the changed stuff this time, put things in a more consistent state.

Whether that will be "good enough" for you, with regards to consistency, will depend on your requirements and what applications you're running. For example, if you've got an active database server on the production box, you'd definitely not want to leave rsync'ed file backups as "good enough". Instead, after the second rsync you'd take a database backup using the database tools, and import that on the clone. Or you'd wait to do that final synchronization until you have your xen domU up and running.

Good luck, and plan on a couple of dry runs and a couple more practice runs to get things working smoothly before you go for real.