[Lxc-users] Create container as clone of host

Fajar A. Nugraha list at fajar.net
Tue Apr 2 06:04:05 UTC 2013


On Tue, Apr 2, 2013 at 10:48 AM, Cody Doucette <doucette at bu.edu> wrote:

> Hi all,
>
> I'm a student and pretty new to LXC. I'm having a little bit of difficulty
> and
> hoping someone could point me in the right direction.
>
> A project that I'm working on has made some changes to the network stack
> in the
> Linux kernel, and we're looking to test those changes utilizing containers.


What changes are they? You DO know that lxc uses the same kernel as the
host, right?

If you wanted to modify the kernel and test the changes, then
KVM/virtualbox/whatever would be a better choice.



> Each
> of these containers should be a clone of the host system which is running
> our
> own custom version of the kernel under Ubuntu 12.10.
>
> So far I have a pretty simple LXC configuration file:
>
> lxc.utsname = my_container
> lxc.tty = 4
> lxc.network.type = veth
> lxc.network.flags = up
> lxc.network.link = br0
> lxc.network.name = eth0
> lxc.network.mtu = 1500
> lxc.network.ipv4 = 0.0.0.0/24
> lxc.rootfs = /var/lib/lxc/my_container
> lxc.mount = /var/lib/lxc/fstab.lxc
>
> And a similarly simple fstab file:
>
> / /var/lib/lxc/my_container none bind 0 0
>
> And am (perhaps naively) trying to create a container with the above using:
>
> # lxc-create -f /var/lib/lxc/config.lxc -n my_container
>
> So naturally I was hoping after executing the above that
> /var/lib/lxc/my_container would be a bind mount of / (root), but that was
> not
> the case. Eventually, each container of course does not need to be a
> complete
> copy of the host, but I figured I would start with trying to do a basic
> clone of
> everything and then pare it down to what is really needed.
>
> Could anyone nudge me in the right direction? Any tips would be
> appreciated.
>
>
Even if it worked, you'd have major problems as programs (e.g. syslog) will
try to write the same file that was already open in the host system.

If your changes are kernel-related, just clone the storage (e.g. using dd),
then use KVM.

If your changes are NOT kernel-related, then the easy way is if the root
filesystem is on a snapshot/clone-capable fs (e.g. btrfs,zfs). Otherwise
just use plain tar/rsync/whatever to copy the filesystem. I do NOT
recommend using LVM snapshot as (from experience) it's more hassle than
what it's worthed.

Regards,

Fajar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20130402/407ee565/attachment.html>


More information about the lxc-users mailing list