From: Austin S Hemmelgarn <ahferroin7@gmail.com>
To: linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: How to replicate a Xen VM using BTRFS as the root filesystem.
Date: Wed, 28 Oct 2015 08:07:20 -0400 [thread overview]
Message-ID: <5630BA78.1090804@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 3423 bytes --]
I would put this on the wiki in the stuff about use cases, but I don't
have a wiki account and don't really have the time or interest right now
in getting one, so I'm posting it here instead.
This is a rather interesting use case for send/receive that I've never
seen discussed anywhere else. In essence, it lets you take a working
Xen user domain which uses BTRFS as the root filesystem, and use that as
a template for new VM's without having to deal with seed devices (which
means you can do it with the source domain online with only minimal
service degradation).
These steps assume you have a minimal working knowledge of Xen and
BTRFS, 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 fully paravirtualized domains, it's a lot
more involved to do it with hardware virtualized domains, 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, 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 (be careful, if you specify the wrong disk you may
cause serious issues).
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.
Using this methodology, I can have a new Gentoo PV domain running in
about half an hour, 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.
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 3019 bytes --]
next reply other threads:[~2015-10-28 12:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-28 12:07 Austin S Hemmelgarn [this message]
2015-10-29 2:39 ` How to replicate a Xen VM using BTRFS as the root filesystem Russell Coker
2015-10-29 11:16 ` Austin S Hemmelgarn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5630BA78.1090804@gmail.com \
--to=ahferroin7@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.