This is an old revision of the document!
Table of Contents
Create LXC Templates
Every time inspiration struck or I saw a blog post with something I wanted to try, it was frustrating and time consuming to get the base operating system set up to the way I like it before proceeding with the project.
Now I just update the template each point release or when I add something substantial to my dotfiles so it's ready to go whenever I need to spin up a fresh container.
It only takes a few minutes to set up or modify and can save lots of time in the long run.
Select an Image
We'll be doing most of this from the command line.
- SSH into Proxmox:
ssh proxmox
- List available system images:
# Check local images first (change sas-storage to wherever they are stored on your system eg. local) sudo pveam list sas-storage # If what we want isn't there, update container template database sudo pveam update # List available images sudo pveam available # or filter output like so: sudo pveam available --section system
- Download the image:
sudo pveam download sas-storage debian-10.0-standard_10.0-1_amd64.tar.gz
- See
man pveam
for more details.
Create the Container
Now we need to create the container that we will be updating and adding our programs to. Note that you will need to modify the following command to match your system.
- Create a container:
sudo pct create 250 sas-storage:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz \ --storage sas-lvm --rootfs volume=sas-lvm:16 \ --ostype debian --arch amd64 --password insecure --unprivileged 1 \ --cores 1 --memory 1024 --swap 1024 \ --hostname lxc-template --searchdomain local.lan --nameserver xxx.xxx.xxx.x \ --net0 name=eth0,bridge=vmbrxx,ip=dhcp,gw=xxx.xxx.xx.x,type=veth --start true
- See
man pct
for more information.
Modify the Container
Here's where we update/add programs/configure it to our liking.
- Enter the container:
sudo pct enter 250
- Do stuff:
# Update the apt cache apt update # Upgrade the packages apt upgrade # Install some packages apt install curl git screen stow unattended-upgrades vim # Set Vim as default editor update-alternatives --set editor /usr/bin/vim.basic # Create user adduser username # Switch to user su - username # Clone dotfiles git clone https://path.to/dotfiles ~/.dotfiles # Stow the dotfiles stow dotfiles # Create ~/.ssh directory mkdir ~/.ssh # Create ~/.ssh/authorized_keys file # And so on....
Create the template
In order to turn the container into a template, we need to delete the network interface, and create a backup.
- From proxmox (not inside the container):
- Remove the network interface:
sudo pct set 250 --delete net0
- Create a backup:
vzdump 250 --mode stop --compress gzip --dumpdir /media/sas/data/template/cache/
- The new file will be located in:
/media/sas/data/template/cache
- You can leave it as is or rename it to something:
cd /media/sas/data/template/cache sudo mv new_vz_dump.tar.gz custom_debian_10.4.tar.gz
- See
man vzdump
for info.
Cleaning up
Feel free to delete the container we used to make the template (250).
Now every time you want to create a lxc container to use, it will be ready to go with things set just the way you like!