[lxc-devel] [PATCH] lxc-clone: support 'permanent ephemeral' containers
Stéphane Graber
stgraber at ubuntu.com
Wed Mar 27 21:16:59 UTC 2013
On 03/27/2013 10:01 AM, Serge Hallyn wrote:
> 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: Serge Hallyn <serge.hallyn at ubuntu.com>
Looks good.
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
And pushed to staging.
> ---
> src/lxc/lxc-clone.in | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/src/lxc/lxc-clone.in b/src/lxc/lxc-clone.in
> index 291db30..4c8acb4 100755
> --- a/src/lxc/lxc-clone.in
> +++ b/src/lxc/lxc-clone.in
> @@ -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 at g" $lxc_path/$lxc_new/config
> + sed -i "s@$lxc_path/$lxc_orig@$lxc_path/$lxc_new at g" $lxc_path/$lxc_new/pre-mount
> + sed -i "s at LXC_NAME=\"$lxc_orig at 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
>
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130327/f91371e3/attachment.pgp>
More information about the lxc-devel
mailing list