User Tools

Site Tools


proxmox:lxc:lxc-template

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

  • SSH into Proxmox:
    [[email protected]]$ ssh proxmox
  • List available system images:
    # Check local images first (change sas-storage to wherever they are stored on your system eg. local)
    [[email protected]]$ sudo pveam list sas-storage
    
    # If what we want isn't there, update container template database
    [[email protected]]$ sudo pveam update
    
    # List available images
    [[email protected]]$ sudo pveam available
    
    # or filter output like so:
    [[email protected]]$ sudo pveam available --section system
  • Download the image:
    [[email protected]]$ 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:
    [[email protected]]$ 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.


Create the template

In order to turn the container into a template, we need to delete the network interface then create a backup.

  • From proxmox (not inside the container):
  • Remove the network interface:
    [[email protected]]$ sudo pct set 250 --delete net0
  • Create a backup:
    [[email protected]]$ 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:
    [[email protected]]$ cd /media/sas/data/template/cache
    
    [[email protected]]$ 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).


Modifying or Updating

It's really easy to modify the container when a new version of the OS is released or you want to add something to your templates.

  • Create a container with your custom file:
    [[email protected]]$ sudo pct create 250 sas-storage:vztmpl/custom_debian_10.4.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.xxx.x,type=veth \
    --start true
  • Enter the container:
    [[email protected]]$ sudo pct enter 250
  • Do stuff:
    # Update/Upgrade
    # Install new stuff
    # Add new dotfiles
  • Exit back to Proxmox:
    exit
  • Remove the network device:
    [[email protected]]$ sudo pct set 250 --delete net0
  • Create the backup:
    [[email protected]]$ vzdump 250 --mode stop --compress gzip --dumpdir /media/sas/data/template/cache/
  • Rename the backup if you like:
    [[email protected]]$ cd /media/sas/data/template/cache
    
    [[email protected]]$ sudo mv new_vz_dump.tar.gz custom_debian_10.5.tar.gz

Conclusion

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!


proxmox/lxc/lxc-template.txt · Last modified: 2020/05/25 10:21 by chuck