Open main menu

OpenVZ Virtuozzo Containers Wiki β

Ubuntu Precise template creation

Revision as of 15:35, 22 July 2014 by Ilya Evseev (talk | contribs) ("First steps after creation" section added.)

Contents

Setup variables

Common part:

ARCH="i386" 
export COUNTRY="de" 

For 12.04 (Precise Pangolin):

export DIST="precise" 
export NAME="ubuntu1204" 
TMPL="12.04-x86"

For 14.04 (Trusty Tahr):

export DIST="trusty" 
export NAME="ubuntu1404"
TMPL="14.04-x86"

Prepare directory

apt-get -y install debootstrap
cd /usr/share/debootstrap/scripts && ln -s gutsy trusty && cd -
debootstrap --arch $ARCH $DIST /var/lib/vz/template/$NAME http://$COUNTRY.archive.ubuntu.com/ubuntu
chroot /var/lib/vz/template/$NAME

Note: Debootstrap can miss Trusty profile (as in Debian Wheezy), so you should create it manually as seen above.

Steps in chroot

Configure locales:

locale-gen ru_RU.UTF-8
locale-gen en_US.UTF-8

Configure packages:

echo " 
deb http://$COUNTRY.archive.ubuntu.com/ubuntu $DIST           main restricted universe multiverse
deb http://$COUNTRY.archive.ubuntu.com/ubuntu $DIST-updates   main restricted universe multiverse
deb http://$COUNTRY.archive.ubuntu.com/ubuntu $DIST-security  main restricted universe multiverse
#eb http://$COUNTRY.archive.ubuntu.com/ubuntu $DIST-backports main restricted universe multiverse
" > /etc/apt/sources.list
  :
dpkg --remove ubuntu-minimal isc-dhcp-client isc-dhcp-common ntpdate resolvconf
dpkg --purge  ubuntu-minimal isc-dhcp-client isc-dhcp-common ntpdate resolvconf
  :
apt-get update
apt-get -y dist-upgrade

Configure mail system (consider 192.0.2.2 is IP of venet0 on HN, or put here your own SMTP relay if needed):

mkdir /etc/dma
echo $NAME > /etc/mailname
echo '
SMARTHOST 192.0.2.2
DBOUNCEPROG dbounce-simple-safecat
MAILNAMEFILE /etc/mailname
' > /etc/dma/dma.conf
  :
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends dma bsd-mailx safecat

Disable hardware-related configs:

sed -i.orig -e 's,^#!.*,#!/bin/true,'                        /etc/init.d/ondemand
sed -i.orig -e 's,\(.* | \)\(sysctl .*\),\1 /bin/true \2,'   /etc/init/procps.conf
sed -i.orig -e 's,^console output,, ; s,^env INIT_VERBOSE,,' /etc/init/rc.conf
sed -i.orig -e 's/^\$ModLoad imklog/## \$ModLoad imklog/g'   /etc/rsyslog.conf
sed -i.orig -e 's,^\([^#].*/dev/xconsole\),## \1,'           /etc/rsyslog.d/50-default.conf
  :
mkdir /root/etc_init_console_tty
mv /etc/init/console* /etc/init/tty* /root/etc_init_console_tty

Cleanup and leave chroot:

find /var/cache/apt /var/lib/apt/lists -type f -delete
apt-get clean
exit

Create template archive

rm -f   /var/lib/vz/template/cache/ubuntu-$TMPL.tar.gz &&
tar czf /var/lib/vz/template/cache/ubuntu-$TMPL.tar.gz --numeric-owner -C /var/lib/vz/template/$NAME .

How to create CT from template

ID=123
vzctl create $ID --ostemplate ubuntu-$TMPL --hostname … --name … --layout simfs
vzctl set $ID --save --onboot yes --nameserver 192.0.2.2 --ipadd 192.0.2.$ID

First steps after creation

Start and enter:

vzctl start $ID
vzctl enter $ID

Install updates:

apt-get update
apt-get -y dist-upgrade