Updating CentOS 5 Template

From Proxmox VE
Jump to: navigation, search

This article shows how to update a Standard CentOS 5 Template. CentOS v5.9 (Final) was released on 2013-01-29 whilst the first release of CentOS 5.0 was on 2007-04-12.

Get the Source Template

On the Proxmox VE host download the source template (or take it from OpenVZ.org) and name it according to Proxmox VE convention:

cd /var/lib/vz/template/cache
wget http://download.proxmox.com/appliances/system/centos-5-standard_5.8-1_i386.tar.gz

Create Container

Create an OpenVZ container (assumed VEID 107 here) using the source template and study the existing version info:

# cat /etc/redhat-release
CentOS release 5.8

# uname -a
Linux test 2.6.32-7-pve #1 SMP Mon Feb 13 07:33:21 CET 2012 i686 GNU/Linux

# uname -r

# cat /proc/version
Linux version 2.6.32-7-pve (root@oahu) (gcc version 4.3.2 (Debian 4.3.2-1.1) ) #1 SMP Mon Feb 13 07:33:21 CET 2012

We will see that only the first command above will show a change in the version when using the updated template.

Update CentOS

vzctl enter 107
yum update
yum clean all

# Change Time Zone from MSK to GMT
mv /etc/localtime /etc/localtime.bak
ln -s /usr/share/zoneinfo/Etc/GMT /etc/localtime
rm -f /etc/localtime.bak

#	Mon Jan 21 09:38:54 GMT 2013

history -c

# Stop the container
vzctl stop 107
1:2345:respawn:/sbin/agetty tty1 38400 linux

Clean Up Container and Build Template

# On the host remove IP of container
vzctl set 107 --ipdel all --save

# Go to VM File System
cd /var/lib/vz/private/107

# Remove SSH keys and PIDs
rm -f etc/ssh/ssh_host_*
rm -f var/run/*.pid
# New SSH keys are generated on first boot by /etc/rc.d/init.d/sshd.

# Remove session files
touch fastboot

rm -f .autofsck
rm -f .autorelabel
rm -f aquota.group
rm -f aquota.user
rm -f etc/hosts
rm -f etc/resolv.conf
rm -f etc/hostname
rm -f var/log/fsck/*
rm -rf var/log/news
rm -f var/run/*.reboot
rm -f var/lib/random-seed
rm -rf var/cache/yum/*

cd var/log
rm -f `ls -l | grep -v boot | grep -v wtmp | grep -v faillog | grep -v lastlog | awk '{print $9}'`
# Harmless warnings:
# rm: cannot remove `httpd': Is a directory
# rm: cannot remove `mail': Is a directory
# rm: cannot remove `samba': Is a directory
cd ../..

cat /dev/null > var/log/httpd/error_log
cat /dev/null > var/log/httpd/access_log

# Make the template
tar --numeric-owner -czf /var/lib/vz/template/cache/centos-5-standard_5.9-1_i386.tar.gz .
# Harmless Warning:
# tar: ./var/run/saslauthd/mux: socket ignored
# Takes 1 minute on atom board

# Delete the VM
cd ../../
vzctl destroy 107

Listing the source and updated templates would show a marginal increase in file size which is to be expected:

cd /var/lib/vz/template/cache/
ls -al centos-5-standard*_i386.tar.gz
-rw-r--r-- 1 root root 182051277 Oct 17 22:37 centos-5-standard_5.8-1_i386.tar.gz
-rw-r--r-- 1 root root 184095665 Jan 21 19:39 centos-5-standard_5.9-1_i386.tar.gz

Test Updated Template

Create a container using the updated template and start it. The first boot log would be like:

starting init logger
INIT: version 2.86 booting
Welcome to CentOS release 5.9 (Final)
hwclock is unable to get I/O port access: the iopl(3) call failed.
Setting clock : Mon Jan 21 11:42:44 GMT 2013 [ OK ]
Starting udev: cp: cannot create special file `/dev/console': File exists
cp: cannot create special file `/dev/core': File exists
cp: cannot create special file `/dev/null': File exists
cp: cannot create special file `/dev/tty': File exists
cp: cannot create special file `/dev/zero': File exists
Wait timeout. Will continue in the background.[FAILED]
Setting hostname centos59.example.com: [ OK ]
raidautorun: failed to open /dev/md0: Operation not permitted
awk: cmd. line:1: fatal: cannot open file `/proc/misc' for reading (No such file or directory)
Mounting local filesystems: [ OK ]
Enabling local filesystem quotas: [ OK ]
Enabling /etc/fstab swaps: [ OK ]
INIT: Entering runlevel: 3
Entering non-interactive startup
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: mangle filter [ OK ]
Unloading iptables modules: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface venet0: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [PASSED]
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
Starting xinetd: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
Starting httpd: [ OK ]
Starting crond: [ OK ]
Starting saslauthd: [ OK ]
INIT: no more processes left in this runlevel

Stop and Destroy the container from the GUI.

Update the apl-available file

To make the template available with a proper name in the PVE 1.9 GUI, append the following to /var/lib/pve-manager/apl-available (it will get overwritten on next startup of PVE Host or next day when HQ updates the file):

Package: centos-5-standard
Version: 5.9-1
Type: openvz
OS: centos-5
Section: system
Maintainer: Ap.Muthu <apmuthu@usa.net>
Location: http://www.sacollege.net/files/appliances/centos-5-standard_5.9-1_i386.tar.gz
Infopage: http://pve.proxmox.com/wiki/CentOS_5_Standard
md5sum: c0219eb76d9c69b4d7a81bf22decc578
Description: CentOS 5.9 Standard
 A regular CentOS 5.9 system having only the basic packages.
 The original template is at 

Note that each stanza must have a blank line separating them. Adjust the md5sum to suit your updated template file and if you are placing yours in some other Location.