There are many articles available which discuss customizing a pre-existing Proxmox Container Template. Few, if any, discuss constructing an LXC container from scratch. Maybe because, fundamentally, a container template is just the rootfs as tarball, so building it is quite easy:
- Build a linux based virtual machine, I use Debian's recent release
- Install LXC and its template package
- Construct and initialize an LXC container
- Shut it down and and zip it up
- Copy it over to the ProxMox template directory
The details:
# build the linux vm - details not relevant here # ssh into the vm, or start a command line # install basic packages sudo apt install --no-install-recommends lxc lxc-templates xz-utils bridge-utils wget debootstrap rsync # basic container templates are in: # /usr/share/lxc/templates/ # for debian as well as other distributions # create an lxc container, provide a list any additional packages lxc-create --template debian --name trixie-template -- --release trixie --packages iputils-ping,vim-tiny # start and attach to the container lxc-start trixie-template lxc-attach trixie-template # prepare for generating template apt clean apt purge # Remove SSH host keys to ensure unique keys for each clone: rm /etc/ssh/ssh_host_* # Empty the machine ID file: truncate -s 0 /etc/machine-id # clear history unset HISTFILE # truncate history history -c > ~/.bash_history # the following has a space in front to prevent inclusion in the history shutdown -h now # the shutdown returns to the virtual machine's prompt # compress the directory structure cd /var/lib/lxc/trixie-template/ # remove /dev files as they can't be created in an unprivileged container # an example error message if not removed: # tar: ./rootfs/dev/urandom: Cannot mknod: Operation not permitted # construction of a new container will re-create the directory and files rm ./rootfs/dev/ptmx rm ./rootfs/dev/zero rm ./rootfs/dev/tty3 rm ./rootfs/dev/urandom rm ./rootfs/dev/null rm ./rootfs/dev/tty rm ./rootfs/dev/console rm ./rootfs/dev/tty4 rm ./rootfs/dev/tty2 rm ./rootfs/dev/random rm ./rootfs/dev/tty1 rm ./rootfs/dev/full # cd into rootfs and zip the container cd rootfs tar --xz --acls --numeric-owner -cf /var/local/trixie-13-3-template.tar.xz ./ # the xz file can be copied over to proxmox and placed into # /var/lib/pve/local-btrfs/template/cache/ # for use as a template for container creation
During the first use of lxc-create to create the original container, packages are downloaded and installed to build the container. The packages and installation is cached for faster subsequent builds of the same container type.
If the cache becomes stale, it can be rebuilt by using --flush-cache in a manner similar to:
lxc-create --template debian --name trixie-template -- --release trixie --flush-cache --packages iputils-ping,vim-tiny,less
An existing cache can be updated with something like:
sudo chroot /var/cache/lxc/debian/rootfs-trixie-amd64 apt-get update apt-get dist-upgrade apt-get clean exit
courtesy of Updating lxc image/container caches
One other note, there are two package candidates for installing the ping utility:
- iputils-ping - native Linux ping, preferred for Debian/Linux
- inetutils-ping - general gnu version, used on a variety of posix sytstems, less preferred
Some fix-ups in the process:
- apt-get install less
- dpkg-reconfigure locales
- useradd user

