Editing Archlinux Template creation

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
Script & archived instructions for creating an Arch container.
+
Instructions manually create a minimal Archlinux (0.8) "Voodoo" OS Template.
  
== Script ==
+
== Prerequisites ==
  
Script for creating a minimal Arch Linux template adapted from the script in [[Talk:Archlinux_Template_creation|Disussion]].
+
I used a modified archbootstrap script which can be found at http://forzza.systs.org/openvz-misc/
<pre>#!/bin/bash -x
 
  
DISTRO=arch
+
Edit settings of script "archbootstrap" :
VERSION=2013
 
  
# set up base system plus:
+
<pre>
#    syslinux (necessary? i don't think it is...)
+
ARCH="i686"
#    vim (because nano is lame)
+
IGNORE="rp-pppoe ppp wireless_tools xfsdump xfsprogs reiserfsprogs lshwd usbutils pciutils pcmciautils module-init-tools mdadm mkinitcpio libusb jfsutils lvm2 lilo cryptsetup device-mapper dhcpcd hwdetect dmapi gen-init-cpio grub"
#    openssh
 
# ...any other package from standard Arch repos...
 
PACKS="base base-devel syslinux openssh vim"
 
  
MIRROR1=http://mirror.umoss.org/archlinux
+
umark PACMAN_OPTS (remove '#')
MIRROR2=http://mirror.rit.edu/archlinux
+
</pre>
  
if [[ ${1} == 64 ]]; then
+
{{Note|I suggest to place the build for OpenVZ templates to /vz/template/, schema: /vz/template/$DIST/$VERSION/$ARCH/}}
  ARCH=x86_64
 
else
 
  if [[ ${1} == 32 ]]; then
 
    ARCH=i686
 
  else
 
    echo "Usage: ${0} 32|64"
 
    exit 1
 
  fi
 
fi
 
  
ROOT=${DISTRO}-${VERSION}-${ARCH}
+
<pre>
 +
Built this OS-Template with:
  
TEMPLATE=$(pwd)/${ROOT}.tar.gz
+
VE0_dist        Debian
 +
VE0_ARCH i386
  
if [[ "$(whoami)" == "root" ]]; then
+
DIST arch
    echo "Building template: ${ROOT}"
+
VERSION 0.8
else
+
ARCH depends on VE0 settings above
    echo "This script must be run as root (or with sudo)"
+
</pre>
    exit 1
 
fi
 
  
cat <<EOF > pacman.conf
 
[options]
 
HoldPkg    = pacman glibc
 
SyncFirst  = pacman
 
Architecture = ${ARCH}
 
  
[core]
+
== bootstrapping Archlinux ==
Server = ${MIRROR1}/\$repo/os/${ARCH}
 
Server = ${MIRROR2}/\$repo/os/${ARCH}
 
Include = /etc/pacman.d/mirrorlist
 
[extra]
 
Server = ${MIRROR1}/\$repo/os/${ARCH}
 
Server = ${MIRROR2}/\$repo/os/${ARCH}
 
Include = /etc/pacman.d/mirrorlist
 
[community]
 
Server = ${MIRROR1}/\$repo/os/${ARCH}
 
Server = ${MIRROR2}/\$repo/os/${ARCH}
 
Include = /etc/pacman.d/mirrorlist
 
EOF
 
  
mkarchroot -C pacman.conf ${ROOT} ${PACKS}
+
Syntax:
  
if [[ $? -ne 0 ]]; then
+
VE0_# /usr/bin/archbootstrap /vz/template/$DIST/$VERSION/$ARCH/ [MIRROR]
    echo "Build failed".
 
    exit 1
 
fi
 
  
chmod 666 ${ROOT}/dev/null
+
{{Note|Please use mirrors ! A full list of Archlinux mirrors : http://wiki.archlinux.org/index.php/Mirror}}
chmod 666 ${ROOT}/dev/zero
 
mknod -m 666 ${ROOT}/dev/random c 1 8
 
mknod -m 666 ${ROOT}/dev/urandom c 1 9
 
mkdir -m 755 ${ROOT}/dev/pts
 
mkdir -m 1777 ${ROOT}/dev/shm
 
mknod -m 666 ${ROOT}/dev/tty c 5 0
 
mknod -m 666 ${ROOT}/dev/full c 1 7
 
mknod -m 600 ${ROOT}/dev/initctl p
 
mknod -m 666 ${ROOT}/dev/ptmx c 5 2
 
  
  
# we don't need any getty entries in a container
+
== enter the Build with chroot ==
sed 's/^.*getty.*$//' -i ${ROOT}/etc/inittab
 
  
cd ${ROOT}
+
All the commands below are executed from the root shell. I this howto "chroot" is used to enter as NEWROOT, a BUILD-VE must not be created!
tar czvf ${TEMPLATE} .
 
  
echo "Created template: ${ROOT}"</pre>
+
VE0_# chroot /vz/template/$DIST/$VERSION/$ARCH/
  
== Manual Instructions ==
 
  
The instructions below are informative but out of date and likely '''will not''' work with an Arch system built after 2011.
+
=== setting DNS server ===
  
=== Prerequisites ===
+
For the chroot BUILD we also need to specify a DNS for it:
  
I used a modified archbootstrap script which can be found at http://forzza.systs.org/openvz-misc/
+
BUILD_# mv /etc/resolv.conf.pacorig /etc/resolv.conf
{{Note | This link is currently broken}}
+
{{Note | One can use mkarchroot (provided by devtools) in place of archbootstrap if building the template on Archlinux. See [[Talk:Archlinux_Template_creation|Disussion]] for a bash script to do this. The script makes it easy to build an image on an arch machine, then copy the zipped template over to your VZ host.}}
 
  
Edit settings of script "archbootstrap" :
+
=== update and install packages ===
  
ARCH="i686"
+
Update (sync) pacman cache and update installed packages
IGNORE="rp-pppoe ppp wireless_tools xfsdump xfsprogs reiserfsprogs lshwd usbutils pciutils pcmciautils module-init-tools mdadm mkinitcpio libusb jfsutils lvm2 lilo cryptsetup device-mapper dhcpcd hwdetect dmapi gen-init-cpio grub"
 
umark PACMAN_OPTS (remove '#')
 
  
 +
BUILD_# pacman -Syu
  
{{Note|I suggest to place the build for OpenVZ templates to /vz/template/, schema: /vz/template/$DIST/$VERSION/$ARCH/}}
 
  
Built this OS-Template with:
+
Install openssh (client and server) , quota-tools and iproute
  
{| class="wikitable"
+
BUILD_# pacman -S openssh quota-tools iproute
|| [[CT0]]_dist || Debian
 
|-
 
|| [[CT0]]_ARCH || i386
 
|-
 
|| DIST || arch
 
|-
 
|| VERSION || 0.8
 
|-
 
|| ARCH || depends on CT0 settings above
 
|}
 
  
=== bootstrapping Archlinux ===
 
  
Syntax:
+
=== fix /etc/mtab ===
  
CT0_# /usr/bin/archbootstrap /vz/template/$DIST/$VERSION/$ARCH/ [MIRROR]
+
Add symlink /proc/mount /etc/mtab
  
{{Note|Please use mirrors! A full list of Archlinux mirrors: http://wiki.archlinux.org/index.php/Mirror}}
+
BUILD_# ln -s /proc/mounts /etc/mtab
  
=== enter the Build with chroot ===
 
  
All the commands below are executed from the root shell. I this howto "chroot" is used to enter as NEWROOT, a BUILD-VE must not be created!
+
=== fix /etc/inittab ===
  
CT0_# chroot /vz/template/$DIST/$VERSION/$ARCH/
+
Remove getties from inittab
  
==== setting DNS server ====
+
BUILD_# sed -i -e '/getty/d' /etc/inittab
  
For the chroot BUILD we also need to specify a DNS for it:
 
  
BUILD_# mv /etc/resolv.conf.pacorig /etc/resolv.conf
+
=== create device nodes ===
  
==== update and install packages ====
+
Create device nodes at /dev, like console, full, null, zero, urandom, ptmx and fifo of initctl
  
Update (sync) pacman cache and update installed packages
+
BUILD_# mknod -m 600 /dev/console c 5 1
  
BUILD_# pacman -Syu
+
BUILD_# mknod -m 666 /dev/tty c 5 0
  
Install openssh (client and server) , quota-tools and iproute
+
BUILD_# mknod -m 666 /dev/full c 1 7
  
BUILD_# pacman -S openssh quota-tools iproute
+
BUILD_# mknod -m 600 /dev/initctl p
  
==== fix /etc/mtab ====
+
BUILD_# mknod -m 666 /dev/null c 1 3
  
Add symlink /proc/mount /etc/mtab
+
BUILD_# mknod -m 666 /dev/ptmx c 5 2
  
BUILD_# ln -s /proc/mounts /etc/mtab
+
BUILD_# mkdir pts
  
==== fix /etc/inittab ====
+
BUILD_# mknod -m 666 /dev/random c 1 8
  
Remove getty lines from inittab:
+
BUILD_# mknod -m 444 /dev/urandom c 1 9
  
BUILD_# sed -i -e '/getty/d' /etc/inittab
+
BUILD_# mknod -m 666 /dev/zero c 1 5
  
==== create device nodes ====
 
  
Create device nodes at /dev, like console, full, null, zero, urandom, ptmx and fifo of initctl
+
=== sysinit script modification ===
 
 
BUILD_# mknod -m 600 /dev/console c 5 1
 
BUILD_# mknod -m 666 /dev/tty c 5 0
 
BUILD_# mknod -m 666 /dev/full c 1 7
 
BUILD_# mknod -m 600 /dev/initctl p
 
BUILD_# mknod -m 666 /dev/null c 1 3
 
BUILD_# mknod -m 666 /dev/ptmx c 5 2
 
BUILD_# mkdir pts
 
BUILD_# mknod -m 666 /dev/random c 1 8
 
BUILD_# mknod -m 444 /dev/urandom c 1 9
 
BUILD_# mknod -m 666 /dev/zero c 1 5
 
 
 
==== sysinit script modification ====
 
  
 
Remove deleting of /etc/mtab in /etc/rc.sysinit and add mounting of /dev/pts
 
Remove deleting of /etc/mtab in /etc/rc.sysinit and add mounting of /dev/pts
  
BUILD_# nano /etc/rc.sysinit
+
BUILD_# nano /etc/rc.sysinit
  
[...]
+
<pre>
/bin/rm -f /etc/mtab
+
[...]
[...]
+
/bin/rm -f /etc/mtab
 +
[...]
 +
</pre>
  
 
to  
 
to  
  
[...]
+
<pre>
#/bin/rm -f /etc/mtab
+
[...]
/bin/mount -t devpts none /dev/pts
+
#/bin/rm -f /etc/mtab
[...]
+
/bin/mount -t devpts none /dev/pts
 +
[...]
 +
</pre>
  
==== modify the main configuration file ====
 
  
BUILD_# nano /etc/rc.conf
+
=== modify the main configuration file ===
  
 +
BUILD_# nano /etc/rc.conf
  
 +
<pre>
 
  # Localization
 
  # Localization
 
  LOCALE="en_US.utf8"
 
  LOCALE="en_US.utf8"
Line 218: Line 147:
 
  # Add openssh to DAEMONS, start at bootup ; ssh-keys are build on first VE start !!!
 
  # Add openssh to DAEMONS, start at bootup ; ssh-keys are build on first VE start !!!
 
  DAEMONS=(syslog-ng network netfs crond ssh)
 
  DAEMONS=(syslog-ng network netfs crond ssh)
 +
</pre>
 +
  
==== enable ssh connections ====
+
=== enable ssh connections ===
  
 
{{Note|All connection are disabled to VE, see /etc/hosts.deny, only affected server built-in with libwrap}}
 
{{Note|All connection are disabled to VE, see /etc/hosts.deny, only affected server built-in with libwrap}}
  
Allow ssh:
+
Allow ssh :
 +
 
 +
<pre>
 +
BUILD_# echo "ssh: ALL : ALLOW" >> /etc/hosts.allow}
 +
</pre>
  
BUILD_# echo "ssh: ALL : ALLOW" >> /etc/hosts.allow
 
  
==== lock (disable) the root account ====
+
=== lock (disable) the root account ===
  
BUILD_# passwd -l root
+
BUILD_# passwd -l root
  
==== exit the chroot to CT0 ====
 
  
BUILD_# exit
+
=== exit the chroot to VE0 ===
  
=== build a exclude list ===
+
BUILD_# exit
 +
 
 +
 
 +
== build a exclude list ==
  
 
Shrink the OS-Template, so not all files needed in a VE - OS - TEMPLATE
 
Shrink the OS-Template, so not all files needed in a VE - OS - TEMPLATE
  
Remove unused pacman backup files:
 
  
CT0_# find ./ -name '*.pacorig' > ../exclude.list-$ARCH
+
Remove unused pacman backup files
  
<code>/etc/resolv.conf</code> is added by vzctl:
+
VE0_# find ./ -name '*.pacorig' > ../exclude.list-$ARCH
  
CT0_# echo "etc/resolv.conf" >> ../exclude.list-$ARCH
 
  
Don't add downloaded pkg to ostemplate:
+
/etc/resolv.conf is added by vzctl:
  
CT0_# find ./var/cache/ -name '*.tar.gz' >> ../exclude.list-$ARCH
+
VE0_# echo "etc/resolv.conf" >> ../exclude.list-$ARCH
  
We dont need no logs and history:
 
  
CT0_# find ./var/cache/ -name '*.tar.gz' >> ../exclude.list-$ARCH
+
dont add downloaded pkg to ostemplate:
CT0_# find ./root/.bash_history >> ../exclude.list-$ARCH
 
  
=== create OS template ===
+
VE0_# find ./var/cache/ -name '*.tar.gz' >> ../exclude.list-$ARCH
  
CT0_# tar --numeric-owner -X ../exclude.list-$ARCH -czf /vz/template/cache/arch-0.8-$ARCH-minimal.tar.gz ./
 
  
=== use the OS template ===
+
we dont need no logs and historys
  
CT0_# vzctl create <VEID> --ostemplate arch-0.8-$ARCH-minimal ...
+
VE0_# find ./var/cache/ -name '*.tar.gz' >> ../exlcude.list-$ARCH
  
=== update the OS template ===
 
  
To update a template is really easy, enter the build with chroot, performing upgrade task
+
VE0_# find ./root/.bash_history >> ../exclude.list-$ARCH
  
CT0_# chroot /vz/template/$DIST/$VERSION/$ARCH/ 'pacman -Syu'
+
 
 +
== create OS-Template ==
 +
 
 +
VE0_# tar -X ../exclude.list-$ARCH -czf /vz/template/cache/arch-0.8-$ARCH-minimal.tar.gz ./
 +
 
 +
 
 +
== use the OS-Template ==
 +
 
 +
VE0_# vzctl create <VEID> --ostemplate arch-0.8-$ARCH-minimal ...
 +
 
 +
 
 +
== update the OS-Template ==
 +
 
 +
to update a template is really easy, enter the build with chroot, performing upgrade task
 +
 
 +
VE0_# chroot /vz/template/$DIST/$VERSION/$ARCH/ 'pacman -Syu'
  
 
Update the exclude list, and pack upgraded OS - Template
 
Update the exclude list, and pack upgraded OS - Template
  
=== Links ===
 
  
* [http://wiki.archlinux.org/index.php/Main_Page Arch Linux Wiki]
+
== Links ==
 +
 
 +
Archlinux wiki http://wiki.archlinux.org/index.php/Main_Page
 +
 
  
 
[[Category: HOWTO]]
 
[[Category: HOWTO]]
 
[[Category: Templates]]
 
[[Category: Templates]]

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Template used on this page: