Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

The situation is the following: we have an lxc (linux-container), which contains a Debian Squeeze distribution, built up with a preseed file. We wanted to add some extra packages (packages for the OMF testbed) which are not part of the main, contrib or non-free debian packages list. The goal is (/was) to distribute the preseed file so other users can easily use the debian distribution (with the new packages) in their linux container. But LXC does not seem to provide a possibility to add extra repositories (or we missed something) in the installation from where additional packages can be downloaded and installed.

The solution we looked into is using Vagrant in combination with Chef, where we first create the linux container, then convert that linux container to a vagrant box, let vagrant in combination with chef add our own packages (from the omf repositories) and then convert it back to a linux container. This way we distribute the linux container preseed file, the VagrantFile and maybe some shell script to do conversions.

But how is this done? Is it possible to convert a linux container (/var/lib/lxc/nameContainer/rootfs) to a .box? Or is it possible to convert a .ext2/.ext4/.img (we could convert the linux container first to that) to a .box? And can we convert back (from the generated Vagrant VM to a linux container)? We could not find any information on this topic (which isn't a good sign, obviously...)

Thanks in advance,


share|improve this question
Can't you chroot /var/lib/lxc/nameContainer/rootfs to make changes to the container? – ewwhite Jul 5 '12 at 13:27
Maybe, I'm actually not familiar with using chroot, but we want to prevent that other users have to go "in" the container (so starting it up) and download/add packages. Everything should be preconfigured by the configuration files (the preseed file or the Vagrantfile) – atobi Jul 5 '12 at 13:39
Why would you switch between vagrant and lxc? Why not just use one or the other all the time? – womble Jul 5 '12 at 13:50
We HAVE to use lxc, but because in lxc it does not seem possible to add external repositories/packages in the creating (lxc-create) phase (so that those packages are automatically installed while creating the lxc). At least, that is what we found out. Do you maybe know a way how this is done in the creating (lxc-create) phase? – atobi Jul 5 '12 at 14:31
Is the militant faction of the lxc-supporters mailing list holding your family hostage? I hate it when they do that. – womble Jul 5 '12 at 15:18

1 Answer 1

There is no automated way, no. Or at least none I could find.

However storage-wise LXC is essentially a chroot.

You could:

  • take the "chroot" (rootfs)
  • add a kernel and grub if needed
  • turn it into a filesystem on a virtual disk
  • add a bootloader
  • add the classical boot-time configuration (/etc/fstab and co)
  • create a VirtualBox VM around this virtual disk
  • convert it into a Vagrant box
  • create a VM from the Vagrant box, transform it as you want
  • extract the system again from the VM disk
  • put it back into your chroot, after a clean up if you want to remove the kernel and grub stuff

I wrote a script automating the creation of a Vagrant image for Squeeze, where most of the operations are done in a chroot (and virtualization isn't involved). A lot of the steps involved in your project could be largely "stolen" from there.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.