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

[Xen-users] How to replicate a Xen user domain using BTRFS as the root filesystem.


  • To: xen-users <xen-users@xxxxxxxxxxxxx>
  • From: Austin S Hemmelgarn <ahferroin7@xxxxxxxxx>
  • Date: Wed, 28 Oct 2015 11:10:37 -0400
  • Delivery-date: Wed, 28 Oct 2015 15:12:48 +0000
  • List-id: Xen user discussion <xen-users.lists.xen.org>

I would generally put something like this on the wiki, but I don't have an account and don't really have interest in getting an account. I'm posting it here in the hopes that this will be useful to someone other than just me, and because it's something I've never seen suggested anywhere before (although I did post it to the BTRFS mailing list earlier today).

In essence, this makes use of BTRFS's send/receive feature to preform a safe online clone of an existing user domain with relatively minimal service degradation for that existing domain. It goes as far as replicating block layout and inode numbers without needing to do a full block level copy of the domain's storage devices (which isn't safe with BTRFS anyway).

Using this methodology, I can have a new Gentoo PV domain running in about half an hour with all of my custom local configuration, whereas it takes me at least two and a half hours (and often much longer than that) when using the regular install process for Gentoo.

These steps assume you have a decent working knowledge of BTRFS and Linux in general, as well as access to both Domain-0 and the user domain you are copying (refereed to below as the 'source domain'. I've only used this myself with Gentoo, but it should work for almost any Linux distro. I've also only done this with full PV domains, it's a lot more involved to do it with HVM domains the hotplug stuff for block devices in HVM domains can be tricky), although PVH domains should work with exactly the same steps as regular PV domains. Your source domain's root also needs to be in a subvolume on the root filesystem (and needs of course to be on a BTRFS filesystem), this won't work if it isn't.

1. Create your backend storage devices for the new domain.
2. Attach the storage device (or devices) that will hold the root filesystem for the new domain to the source domain. Using xl, this translates to something similar to: 'xl block-attach source "/dev/vg/target-disk,raw,xvdz"' 3. From the source domain, use mkfs.btrfs to create a BTRFS filesystem on the target disk. 4. On the source domain, mount both the root filesystem (don't bind mount it, and make sure that you are mounting the top-level, not a subvolume) and the target filesystem. 5. Create a read-only snapshot of the root subvolume from the source filesystem. 6. Use btrfs send piped to btrfs receive to copy the snapshot from the source filesystem to the target filesystem. This will likely take quite some time (on the low-end server equivalent hardware I have, it takes about 2o-25 minutes for a somewhat minimalistic Gentoo installation). 7. While btrfs send/receive is running, prepare the configuration file for the target domain (I usually just copy the config from the source domain, and then change only what I need to). 8. Once the send/receive operation is complete, use btrfs property set to change the snapshot on the target to be writable, then rename it to whatever you want the root subvolume to be called on the target system. 9. In the newly created root subvolume, change any system specific configuration to what is needed for the new system (at a bare minimum, you probably need to change the hostname and networking configuration, and should verify that /etc/fstab and /etc/localtime are correct for the target system).
10. Unmount the target filesystem in the source domain.
11. Use 'xl block-detach' to detach the target device from the source domain. 12. Use your regular tools to start your new domain, log in, and preform any final configuration needed.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxx
http://lists.xen.org/xen-users

 


Rackspace

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