Difference between revisions of "Ubuntu Precise template creation"
Ilya Evseev (talk | contribs) (Created page with "* Based on Ubuntu_Trusty_template_creation. * HN: Debian 7 (Wheezy). * Templates: Ubuntu 12.04 (Precise Pangolin) and 14.04 (Trusty Tahr). == Setup variables == ARCH="i...") |
Ilya Evseev (talk | contribs) (Disabled services added/fixed.) |
||
(9 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
== Setup variables == | == Setup variables == | ||
+ | Common part: | ||
ARCH="i386" | ARCH="i386" | ||
+ | export COUNTRY="de" | ||
+ | |||
+ | For 12.04 (Precise Pangolin): | ||
export DIST="precise" | export DIST="precise" | ||
export NAME="ubuntu1204" | export NAME="ubuntu1204" | ||
− | |||
TMPL="12.04-x86" | 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 == | == Prepare directory == | ||
apt-get -y install debootstrap | apt-get -y install debootstrap | ||
− | debootstrap --arch $ARCH $DIST /var/lib/vz/template/$NAME http://$COUNTRY.archive.ubuntu.com/ubuntu | + | cd /usr/share/debootstrap/scripts && ln -s gutsy trusty && cd - |
− | chroot /var/lib/vz/template/$NAME | + | 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 == | == Steps in chroot == | ||
Line 22: | Line 35: | ||
locale-gen ru_RU.UTF-8 | locale-gen ru_RU.UTF-8 | ||
locale-gen en_US.UTF-8 | locale-gen en_US.UTF-8 | ||
+ | echo 'LANG="en_US.UTF-8"' > /etc/default/locale | ||
Configure packages: | Configure packages: | ||
Line 41: | Line 55: | ||
echo $NAME > /etc/mailname | echo $NAME > /etc/mailname | ||
echo ' | echo ' | ||
+ | # dma-0.0.2010.xx syntax | ||
SMARTHOST 192.0.2.2 | SMARTHOST 192.0.2.2 | ||
DBOUNCEPROG dbounce-simple-safecat | DBOUNCEPROG dbounce-simple-safecat | ||
Line 47: | Line 62: | ||
: | : | ||
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends dma bsd-mailx safecat | 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 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: | Cleanup and leave chroot: | ||
+ | apt-get clean | ||
find /var/cache/apt /var/lib/apt/lists -type f -delete | find /var/cache/apt /var/lib/apt/lists -type f -delete | ||
− | |||
exit | exit | ||
Line 66: | Line 121: | ||
rm -f /var/lib/vz/template/cache/ubuntu-$TMPL.tar.gz && | 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 . | + | 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 == | == How to create CT from template == | ||
ID=123 | ID=123 | ||
− | vzctl create $ID --ostemplate ubuntu- | + | 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 | 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 | + | apt-get -y dist-upgrade |
− | |||
− |
Latest revision as of 14:40, 16 February 2016
- Based on Ubuntu_Trusty_template_creation.
- HN: Debian 7 (Wheezy).
- Templates: Ubuntu 12.04 (Precise Pangolin) and 14.04 (Trusty Tahr).
Contents
Setup variables[edit]
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[edit]
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[edit]
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[edit]
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[edit]
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[edit]
Start and enter:
vzctl start $ID vzctl enter $ID
Install updates:
apt-get update apt-get -y dist-upgrade