Commit 48853811 by Serge Hallyn Committed by Stéphane Graber

lxc-clone: support 'permanent ephemeral' containers

All of this needs a rewrite/redesign, and that will be coming (details below), but for now You can start 'non-ephemeral ephemeral' containers using lxc-start-ephemeral -o oldname -n newname --keep-data When you shut that down, the container stick around and can be restarted. Now lxc-clone will recognize such a container by the presence of the delta0/ which contains the read-write overlayfs layer. This means you can do incremental development of containers, i.e. lxc-create -t ubuntu -n r1 lxc-start-ephemeral --keep-data -o r1 -n r1-2 # make some changes, poweroff lxc-clone -o r1-2 -n r1-3 # make some changes... lxc-clone -o r1-3 -n r1-4 # etc... Now, as for design changes... from a higher level 1. lxc-clone should be re-written in c and exported through the api. 2. lxc-clone should support overlayfs and aufs 3. lxc-start-ephemeral should become a thin layer which clones a container, starts and stops and destroys it. at a lower level, 1. the api should support container->setup_mounts 2. lxc-clone should be written as a set of backend classes which can copy mounts to each other. So when you load a container which is lvm-backed, it creates a lvm backend class. That class instance can be converted into a loopback or qemu-nbd or directory backed class. A directory-backed class can be converted into a overlayfs or aufs backed class, which (a) uses the dirctory-backed class as the read-only base, and (b) pins the base container (so it can't be deleted until all snapshots are deleted). Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent f63b1efd
......@@ -251,6 +251,23 @@ elif which btrfs >/dev/null 2>&1 && btrfs subvolume list $oldroot >/dev/null 2>&
# if oldroot is a btrfs subvolume, assume they want a snapshot
btrfs subvolume snapshot "$oldroot" "$rootfs" 2>&1 || { echo "$(basename $0): btrfs snapshot failed" >&2; false; }
echo "lxc.rootfs = $rootfs" >> "$lxc_path/$lxc_new/config"
elif [ -d $lxc_path/$lxc_orig/delta0 ]; then # this is a quasi-ephemeral container
if [ $container_running = "True" ]; then
echo "$(basename $0): container $lxc_orig is running." >&2
cleanup
fi
rsync -Hax $lxc_path/$lxc_orig/delta0 $lxc_path/$lxc_new/
touch $lxc_path/$lxc_new/configured
cp -f $lxc_path/$lxc_orig/pre-mount $lxc_path/$lxc_new/
sed -i "s@$lxc_path/$lxc_orig@$lxc_path/$lxc_new@g" $lxc_path/$lxc_new/config
sed -i "s@$lxc_path/$lxc_orig@$lxc_path/$lxc_new@g" $lxc_path/$lxc_new/pre-mount
sed -i "s@LXC_NAME=\"$lxc_orig@LXC_NAME=\"$lxc_new@" $lxc_path/$lxc_new/pre-mount
# lxc-start-ephemeral will have updated /etc/hostname and such under the
# delta0, so just mounting the delta should suffice.
mkdir -p $rootfs
mount --bind $lxc_path/$lxc_new/delta0 $rootfs
mounted=1
echo "lxc.rootfs = $rootfs" >> "$lxc_path/$lxc_new/config"
else
if [ $snapshot = "yes" ]; then
echo "$(basename $0): cannot snapshot a directory" >&2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment