Custom LXC Templates

tsumaru720

Well-Known Member
May 1, 2016
66
2
48
44
Hi Guys

I used to have some documentation for Proxmox 3 that detailed how to convert an existing OpenVZ container into a template I could use for new containers. Since the move to LXC I feel I need to refresh things a bit.

I dont really want to use the containers available via `pveam` because they ship with packages I dont nessecrily care about (Although there are follow up questions on this point).

This got me looking into the underlying LXC template stuff.

I first started by downloading a template:

Code:
lxc-create -t download -n ubuntu-test -- --dist ubuntu --release xenial --arch amd64

Upon success this seems to create a "STOPPED" LXC container (that proxmox has no knowledge of via pct) with its rootfs in /var/lib/vz/private/ubuntu-test. I've then proceeded to tar up that folder and use the resulting tarball as a template for new containers.

Is there anything I need to consider with this? I do notice when I create a new container via gui using this new "template", it does seem to create new SSH host keys for me and I presume proxmox deals with the rest such as hostname, dns, networking and root password etc.

A tangential question here - If I were to use one of the templates available via `pveam`, created a container and booted it up, removed all the packages I dont need and then vzdumped that container - I could theoretically use the tarball for new containers in a similar method as above? So I guess the same question applies - Do I need to consider anything (such as UUIDs) when doing this? I recall reading somewhere that container settings (RAM/CPU allocation etc) are included in the tarbal, do i need to remove these? (If so, where are they)

(Or is there a better way I can get "minimal" images for use with Proxmox - just the bare essentials to have a running container which I can then grab what I need via apt)
 
Last edited:
To create a template you want, just use dab for that. It debootstraps the system and you can then automatically run post-scripts.

One example that illustrates how it works is this:
https://github.com/chriswayg/proxmox-templates/tree/master/debian-8.2-minimal-64

But to your other questions:

Yes, a container template is simply a compressed tar from you container, so you can create it from a running lxc container. You should then cleanup the machine before creating the template:
  • cleanup log files
  • clear all hostname-specific configuration (e.g. for running an oracle database)
  • cleanup shell history
  • cleanup temporary files
I've done it several times and I never encountered a problem. I also migrated other LXC templates to Proxmox VE, which sometimes need some postprocessing.

There are post-processing steps to prepare the template for proxmox
  • setting up networking with distribution specific settings including DNS
  • clear and recreate SSH keys
So, it should be very easy for you. Just play around. If you do not want to do this on your real host, just run Proxmox VE inside Proxmox VE. It works fine for LXC containers.
 
Answered my own question - yes it can

Problem I'm having now is that dab seems unable to create an lxc container to use ...

Code:
initialize VE b38ffb91-defa-4d61-8dae-e9c9f07ae23d

create basic environment
initialize ld cache
command 'lxc-attach -n b38ffb91-defa-4d61-8dae-e9c9f07ae23d --clear-env -- defenv /sbin/ldconfig' failed with exit code 1
command 'lxc-attach -n b38ffb91-defa-4d61-8dae-e9c9f07ae23d --clear-env -- defenv /sbin/ldconfig' failed with exit code 1

any ideas?

Code:
pve-manager/4.2-17/e1400248 (running kernel: 4.4.15-1-pve)
 
Yes, that is a known bug. I run into it yesterday too.

Ubuntu is Debian-based and you can create any Debian based linux distribution.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!