Create OpenVZ Template

Based on http://www.neonhost.com/openvz/. This shows how to create a CentOS 5 OpenVZ template based on CentOS-4 OpenVZ template metadata.

  1. install yum packages for building rpm:
    yum install createrepo
    yum install rpm-build
    yum install gcc
  2. mkdir /usr/src/redhat
  3. wget http://download.openvz.org/template/metadata/centos-4/src/vztmpl-centos-4.src.tar.bz2
  4. wget http://www.neonhost.com/openvz/centos-5-metadata-v2.diff
  5. tar xvjf vztmpl-centos-4.src.tar.bz2
  6. mv centos-4 centos-5
  7. cd centos-5
  8. patch -p1 < ../centos-5-metadata-v2.diff
  9. make clean
  10. make rpms

If your arch is i386, the metadata rpm should now be located in:
/usr/src/redhat/RPMS/i386/vztmpl-centos-5-2.0-2.i386.rpm

# rpm -ihv /usr/src/redhat/RPMS/i386/vztmpl-centos-5-2.0-2.i386.rpm

Now install the CentOS-5 template cache:

# wget http://download.openvz.org/template/precreated/centos-5-x86.tar.gz

# cd /vz/template/cache

# mv centos-5-x86.tar.gz centos-5-i386-default.tar.gz

Now you should be able to create container based on the new centos-5 template.

 


 

Another reference: http://vpshostingstuff.com/category/openvz

Before you create your own, check out this page http://wiki.openvz.org/Download/template/precreated and see whether there is one for your desired OS already exists. If there is, just download the existing one into your host system's /vz/template/cache directory.

After you've downloaded the precreated template cache, run "vzpkgls" and see whether it is included. If not, then you most likely don't have the OS template metadata yet. You can create the metadata following http://wiki.openvz.org/OS_template_metadata. At the moment, there isn't official CentOS5 openvz template. If you want one, you can download the metadata from http://www.neonhost.com/openvz/.

After you have the metadata rpm, say "vztmpl-centos-5-2.0-2.i386.rpm", run "rpm -ihv vztmpl-centos-5-2.0-2.i386.rpm".

Now your "vzpkgls" should show you the installed template cache.

Comments

Well, it worked... partially.

Eeek! I tried to follow your tutorial on CentOS 5.3, but vzpkgcache fails with following error:

sed: can’t read /etc/init.d/syslog: No such file or directory
ERROR: Script install-post failed
Updating cache for centos-5-i386-default OS template
rpmdb: unable to initialize mutex: Invalid argument
rpmdb: PANIC: Invalid argument
rpmdb: PANIC: DB_RUNRECOVERY: Fatal error, run database recovery
error: db4 error(-30977) from dbenv->open: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 – (-30977)
error: cannot open Packages database in /vz/root/100001/var/lib/rpm
Traceback (most recent call last):
File “/usr/share/vzyum/bin/yum”, line 28, in ?
yummain.main(sys.argv[1:])
File “/usr/share/vzyum/yum-cli/yummain.py”, line 75, in main
base.getOptionsConfig(args)
File “/usr/share/vzyum/yum-cli/cli.py”, line 172, in getOptionsConfig
self.doConfigSetup(fn=opts.conffile, root=root, vps=opts.vps)
File “/usr/share/vzyum/lib/yum/__init__.py”, line 82, in doConfigSetup
self.conf = config.yumconf(configfile=fn, root=root, vps=vps)
File “/usr/share/vzyum/lib/yum/config.py”, line 271, in __init__
self.yumvar['releasever'] = self._getsysver()
File “/usr/share/vzyum/lib/yum/config.py”, line 384, in _getsysver
idx = ts.dbMatch(’provides’, self.getConfigOption(’distroverpkg’))
TypeError: rpmdb open failed
ERROR: Command yum check-update failed with 1 exit code

Did I miss something?..

Delete the rpm DB

Every time I encountered this problem, I just vzctl enter the container, and the delete the rpm database like this:

CT100# rm -f /var/lib/rpm/__db*
CT100# rpm -rebuilddb