User Tools

Site Tools


openvz:updating-debian-template

Updating a Debian (or Ubuntu) template

http://wiki.openvz.org/Updating_Ubuntu_template

Create a container based on the template you want to update

vzctl create 1097 --ostemplate debian-5.0-i386-minimal --config vps.16

Specify an IP address and a nameserver, you can get the value of nameserver from your /etc/resolv.conf

vzctl set 1097 --hostname debian.dw.lan --save
vzctl set 1097 --ipadd 192.168.0.97 --save
vzctl set 1097 --nameserver 192.168.0.22 --save
vzctl set 1097 --userpasswd root:<your-root-password>

Start the VE and check that Internet is working from inside your container

vzctl start 1097
vzctl exec 1097 ping -n -c 1 google.com

Enter the container

vzctl enter 1097

Set the correct timezone, choosing the right value (mine is Europe/Rome):

dpkg-reconfigure tzdata

Updating the Linux distribution

Make sure that your /etc/apt/sources.list contains the right links to the repositories. Mine is Debian, so i've done this:

nano /etc/apt/sources.list
sources.list
## Debian Stable (Lenny)
deb http://ftp.it.debian.org/debian/ lenny main contrib non-free
deb-src http://ftp.it.debian.org/debian/ lenny main contrib non-free
 
## security updates
deb http://security.debian.org/ lenny/updates main contrib non-free
deb-src http://security.debian.org/ lenny/updates main contrib non-free
 

Update the apt package database and and install updates

apt-get update

One time i have got an error, related to gpg keys, after adjusting the /etc/apt/sources.list, so before proceed, i've done this

apt-get install debian-archive-keyring

Then again, and the problem vanished

apt-get update

Finally, install updates

apt-get -y upgrade

Cleanup the template

Cleanup unused log files, .bash_history etc, then exit from a container:

apt-get clean
rm -rf /var/lib/apt/lists/* # delete the entire cache
> /etc/resolv.conf
exit

Stop the container, remove its IP

vzctl stop 1097
vzctl set 1097 --ipdel all --save

Rename the existing template cache

mv /vz/template/cache/debian-5.0-i386-minimal.tar.gz{,-old}

Create a new tarball

vzctl mount 1097
cd /vz/root/1097
tar --numeric-owner -czf /vz/template/cache/debian-5.0-i386-minimal.tar.gz .
cd

Clean up

vzctl umount 1097
vzctl destroy 1097
rm -f /etc/vz/conf/1097.conf.destroyed

Compare the sizes of the old and the new template caches, the sizes should not differ much

ls -lh /vz/template/cache/debian-5.0-i386-minimal*

Test the just created template

Try to create and start container made from your new template

vzctl create 1097 --ostemplate debian-5.0-i386-minimal --config vps.16
vzctl set 1097 --ipadd 192.168.0.97 --save
vzctl start 1097
vzctl enter 1097

Execute a few basic commands to check container is fine, examples are:

ps axf
dpkg -l
...

Finally, clean up the testing container:

vzctl stop 1097
vzctl destroy 1097
rm -f /etc/vz/conf/1097.conf.destroyed
openvz/updating-debian-template.txt · Last modified: 2019-06-15 09:47 by kokkez