Ubuntu Precise template creation
- Based on Ubuntu_Trusty_template_creation.
- HN: Debian 7 (Wheezy).
- Templates: Ubuntu 12.04 (Precise Pangolin) and 14.04 (Trusty Tahr).
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"
Note: replace "i386" and "x86" to "amd64", if you want to get 64-bit environment.
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-$ARCH http://$COUNTRY.archive.ubuntu.com/ubuntu chroot /var/lib/vz/template/$NAME-$ARCH
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 echo 'LANG="en_US.UTF-8"' > /etc/default/locale
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 ' # dma-0.0.2010.xx syntax 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
14.04 note: config syntax for dma-0.9 was changed:
echo ' # dma-0.9 syntax SMARTHOST 192.0.2.2 MAILNAME /etc/mailname ' > /etc/dma/dma.conf
Disable hardware-related configs:
Disable() { local f="/etc/init/$1.conf" local o="/etc/init/$1.override" test -s "$o" && grep -qw "^manual" "$o" && return echo "manual # DISABLE UNDER OPENVZ" >> "$o" } Disable console Disable console-font Disable console-setup : Disable ondemand Disable setvtrgb : Disable hwclock Disable hwclock-save : Disable ureadahead Disable ureadahead-other : Disable plymouth Disable plymouth-log Disable plymouth-ready Disable plymouth-shutdown Disable plymouth-splash Disable plymouth-stop Disable plymouth-upstart-bridge : Disable tty2 Disable tty3 Disable tty4 Disable tty5 Disable tty6 : Disable udev Disable udev-fallback-graphics Disable udev-finish Disable udevmonitor Disable udevtrigger : sed -i.orig -e '/| sysctl / s,$, || :,' /etc/init/procps.conf sed -i.orig -e 's,^\$ModLoad imklog,## \$ModLoad imklog,g' /etc/rsyslog.conf
Cleanup and leave chroot:
apt-get clean find /var/cache/apt /var/lib/apt/lists -type f -delete 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-$ARCH .
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