The lxc-clone script was so useful to me that I decided I simply must have it with LVM. So that’s now committed at lp:~serge-hallyn/ubuntu/natty/lxc/lxc-clone and pushed to ppa:serge-hallyn/lxc-natty.

To get started I create a pristine LVM-based container. This only needs to be done once, as I’ll update the pristine images periodically rather than build new ones. So I didn’t automate that step, rather I created a normal container and converted it. I created the container using:

lxc-create -f /etc/lxc-basic.conf -n maverick -t maverick

I didn’t yet have an LVM partition set up, so I merged /dev/sda7 and /dev/sda8 into one 20G partition of type 8e (linux LVM) and did

pvcreate /dev/sda7
vgcreate lxc /dev/sda7

Then I created an lvm partition and copied the rootfs to it:

lvcreate -L 2G -n maverick lxc
mkfs.xfs /dev/lxc/maverick
mkdir /mnt/1
mount /dev/lxc/maverick /mnt/1
rsync -va /var/lib/lxc/maverick/rootfs/ /mnt/1/
umount /mnt/1

Next I removed the original container rootfs and tweaked the config file to use the LVM partition:

rm -rf /var/lib/lxc/maverick/rootfs
mkdir !!:2
sed -i ‘/lxc.rootfs/d’ /var/lib/lxc/maverick/config
echo “lxc.rootfs = /dev/lxc/maverick” >> /var/lib/lxc/maverick/config

Now the pristine container is ready. I can start it as usual using

lxc-start -n maverick

and keep it uptodate with the usual tools. When I want to create a container to, say, reproduce a bug,

lxc-lvm-clone -o maverick -n mtmp1

When I’m done,

lxc-destroy -l -n mtmp1

where -l tells lxc-destroy to call lvremove on the lvm snapshot. The only downside to using these for bug reproduction is that syslog is not being properly handled. Hopefully we can do something about that soon.

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

One Response to lxc-lvm-clone

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s