Difference between revisions of "Ubuntu Precise template creation"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
m (64-bit mode added.)
(Disabled services added/fixed.)
 
(4 intermediate revisions by the same user not shown)
Line 25: Line 25:
 
  apt-get -y install debootstrap
 
  apt-get -y install debootstrap
 
  cd /usr/share/debootstrap/scripts && ln -s gutsy trusty && cd -
 
  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
+
  debootstrap --arch $ARCH $DIST /var/lib/vz/template/$NAME-$ARCH http://$COUNTRY.archive.ubuntu.com/ubuntu
  chroot /var/lib/vz/template/$NAME
+
  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.
 
Note: Debootstrap can miss Trusty profile (as in Debian Wheezy), so you should create it manually as seen above.
Line 35: 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 54: 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 60: 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:
  sed -i.orig -e 's,^#!.*,#!/bin/true,'                        /etc/init.d/ondemand
+
  Disable() {
sed -i.orig -e 's,\(.* | \)\(sysctl .*\),\1 /bin/true \2,'  /etc/init/procps.conf
+
    local f="/etc/init/$1.conf"
sed -i.orig -e 's,^console output,, ; s,^env INIT_VERBOSE,,' /etc/init/rc.conf
+
    local o="/etc/init/$1.override"
sed -i.orig -e 's/^\$ModLoad imklog/## \$ModLoad imklog/g'  /etc/rsyslog.conf
+
    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
 
   :
 
   :
  mkdir /root/etc_init_console_tty
+
  sed -i.orig -e '/| sysctl / s,$, || :,'                    /etc/init/procps.conf
mv /etc/init/console* /etc/init/tty* /root/etc_init_console_tty
+
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
apt-get clean
 
 
  exit
 
  exit
  
Line 78: 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 ==

Latest revision as of 14:40, 16 February 2016

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