Creating debian template for lxc virtualization

To create debian template for lxc you need fresh copy of debian system.

Well, we do have one installed recently on guruplug.
All debian install on guruplug steps are here.

So, lets archive all system to tar.gz.

Firstly it’s a good practice to exclude unneeded files.
Create /tmp/exclude file with this content:

Edit templates /etc/fstab file and comment everything out.
Create new file /etc/fstab.lxc
Contents of that file:

Well, this file doesn’t have to be in virtual machine, but I think that’s more convenient, when lxc fstab configuration is kept inside virtual host. And you have more than one of them.

It’s a good idea to delete udev startup file from /etc/rcS.d/
as it makes unnecessary longer boot.

And create archive:

Lets make one virtual host (commands are made on host machine).

You can use this bridge configuration for lxc containers.

I assume lxc is already installed on your host system. If not, You can do that with command.

and add line to /etc/fstab

You can mount everything what’s on fstab by command “mount -a”.

Assume lxc containers are in /lxc on host machine.
So extract template to that directory:

Make configuration file in /etc/lxc/

Yes, machine IP is static, if You want to get it by DHCP, You need to write:

Make script in /bin/ directory (for fixing dev directory in container):

Make it executable:

Go to virtual machine root directory and start the script:

Create virtual machine:

Edit /etc/default/lxc to make container boot automatically.

That’s it.
You can start container with command:

Now connect to it using ssh.

Leave a Reply