Skip to main content

Raymii.org Raymii.org Logo

Quis custodiet ipsos custodes?
Home | About | All pages | Cluster Status | RSS Feed

OpenVZ/Proxmox - Container to Template

Published: 11-07-2014 | Author: Remy van Elst | Text only version of this article


❗ This post is over nine years old. It may no longer be up to date. Opinions may have changed.

This guide will show you how to convert an OpenVZ (Proxmox) container to a template. You can then use this template on any other OpenVZ (or proxmox) host. This can be used either to migrate containers or to create a kind of master image to deploy new hosts from.

This guide is tested on a proxmox machine running proxmox version 3.2.

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:

I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!

Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.

You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $200 credit for 60 days. Spend $25 after your credit expires and I'll get $25!

Login as root to the proxmox machine via ssh.

Get a list of containers using vzlist:

 CTID      NPROC STATUS    IP_ADDR         HOSTNAME
 100         85 running   10.21.21.5      master.raymii.nl
 101         34 running   10.21.21.6      test-master.raymii.nl

I want to create a template of master.raymii.nl which has ID 100.

You must stop the container before creating the image:

vzctl stop 101
Stopping container ...
Container was stopped
Container is unmounted

Go to the container folder:

cd /var/lib/vz/private/100

Then start the image creation:

tar -cvzpf /var/lib/vz/template/cache/master.raymii.nl.tar.gz .

This will place the image in /var/lib/vz/template/cache/master.raymii.nl.tar.gz. This file can be copied and deployed on another host, or used on the same host as a template.

Tags: bash , kvm , openvz , proxmox , proxmox-ve , ssh , tutorials , virtualization