Changes

Jump to: navigation, search

Creating a CentOS 5.0 Template

669 bytes added, 04:54, 7 August 2011
no edit summary
<div style="font-size[[Category: 14pt"><strong>Creating a CentOS 5.0 Template for OpenVZ</strong></div>HOWTO]]<ol> <li>Install a system with the default CentOS installation that you wish to package. This could be a minimal distro or the default distro or even something custom.</li> <li>Once the OS has been installed, you need to tar the contents of the OS. <ol style="list-style-type: lower-alpha"> <li>First, create a file called /tmp/exclude and add the following lines to it[[Category:<br /> <code>.bash_history<br />lost+found<br />/dev/*<br />/mnt/*<br />/tmp/*<br /> /proc/*<br />/sys/*<br />/usr/src/*<br /></code></li> <li>Now, tar the OS file up by typing <code>tar –czvf /tmp/centos-5.0-&lt;ARCH&gt;-&lt;DISTRO&gt;-image.tar.gz / –X /tmp/exclude</code> where <strong>&lt;ARCH&gt;</strong> represents the system architecture (such as <strong>i386</strong> or <strong>x86_64</strong>) and <strong>&lt;DISTRO&gt;</strong> represents the distribution (<strong>default</strong>, <strong>minimal</strong>, etc.).</li> <li>Now transfer the file over to the OpenVZ server into the <strong>/vz/template/cache</strong> folder.</li> </ol></li> <li>On the OpenVZ server create a “dummy” VPS by creating a folder called <strong>/vz/private/50</strong> and copying the <strong>/etc/vz/conf/ve-vps.basic.conf-sample</strong> to <strong>/etc/vz/conf/50.conf</strong>.Templates]]</ol>{{wikify}}
# Install a system (virtual or physical) with the default CentOS installation that you wish to package. This could be a minimal distro or the default distro or even something custom.## It's generally quicker to bootstrap a CentOS system on another yum/rpm-based, or Debian based system by following the instructions in [http://faiwiki.informatik.uni-koeln.de/index.php/FAI_multi-distribution#bootstrapping_the_base_images__for_other_distributions]# Once the OS has been installed, you need to '''tar''' the contents of the OS.## First, create a file called '''/tmp/exclude''' and add the following lines to it:#: .bash_history#: lost+found#: /dev/*#: /mnt/*#: /tmp/*#: /proc/*#: /sys/*#: /usr/src/*## Now, tar the OS file up by typing: '''tar --numeric-owner -czvf /tmp/centos-5.0-<ARCH>-<DISTRO>-image.tar.gz -X /tmp/exclude /''' where <'''ARCH'''> represents the system architecture ('''i386''' or #: '''x86_64''') and <'''DISTRO'''> represents the distribution (default, minimal, etc.).## Now transfer the file over to the OpenVZ server into '''/vz/template/cache''' folder.# On the OpenVZ server create a “dummy” container by creating a folder called '''/vz/private/50''' #: and copying the '''/etc/vz/conf/ve-vps.basic.conf-sample''' to '''/etc/vz/conf/50.conf'''.#: '''NOTE''':50 is the VEID CTID for the VPScontainer. You can choose any unused VEID CTID on the OpenVZ server.# Now create a new folder called '''/vz/template/centos/5/<ARCH>/config''' again where #: <'''ARCH'''> represents the system architecture.# Create a file in the folder called rpm and add the following line:#: 43# Create a file called '''yum.conf''' in the folder and add the following lines:#: [main]#: #: cachedir=/vz/template/centos/5/<ARCH>/yum-cache/#: #: reposdir=/dev/null#: #: installonlypkgs=#: #: [centos5-base]#: name=CentOS 5 - <ARCH> - Base#: #: baseurl=http://mirror.centos.org/centos/5/os/<ARCH>/#: #: enabled=1#: #: gpgcheck=1#: #: [centos5-updates-released]#: #: name=CentOS 5 - <ARCH> - Released Updates#: #: baseurl=http://mirror.centos.org/centos/5/updates/<ARCH>/#: #: enabled=1#: #: gpgcheck=1# Copy '''/etc/vz/dists/centos-4.conf''' to '''/etc/vz/dists/centos-5.conf'''.# Copy '''/vz/template/centos/4/i386/config/minimal.list''' to ''' /vz/template/centos/5/i386/config/minimal.list'''. # Change to the '''/vz/private/50''' folder and then run the command '''gunzip –dc /vz/template/cache/centos-5-<ARCH>-<DISTRO>-image.tar.gz | tar –xvf –''' to unpack the base image to the folder.# Make sure you are in the '''/vz/private/50''' folder.# Edit '''etc/shadow''' and remove the replace the '''root''' password with !! instead of the hashed value.# Edit the '''etc/inittab''' file and comment out the lines that respawn '''/sbin/mingetty''' on '''tty1''' through '''tty6'''. Just put a # at the beginning of the line.# Remove the '''etc/mtab''' file and then create a symbolic link by typing '''ln -s /proc/mounts etc/mtab'''.# Remove all of the lines from '''etc/fstab''' except for the line that mounts '''/dev/pts'''.# Edit '''etc/rc.d/rc.sysinit''' and comment out the line that starts '''/sbin/start_udev''' by placing a # at the beginning of the line.# Now create device nodes by typing:#: mknod dev/ptmx c 5 2#: mkdir dev/pts#: /sbin/MAKEDEV –d/vz/private/50/dev ttyp ptyp#: mknod dev/null c 1 3#: mknod -m 644 dev/random c 1 8 #: mknod dev/urandom c 1 9# Create the '''var/lock/rpm''' folder.# If you wish to disable IPv6, do the following:## Edit '''etc/sysconfig/network''' and set '''NETWORKING_IPV6''' to '''no'''.## Add the following lines to '''etc/modprobe.d/blacklist''':#: blacklist ipv6#: blacklist net-pf-10# Disable any physical NICs by modifying the '''etc/sysconfig/network-scripts/ifcfg-ethX''' files (where '''X''' is the interface number starting from '''0''') and setting '''ONBOOT''' to '''no'''.# Check etc/sysconfig/init to see if PROMPT=yes, and then change to no. Otherwise when startup init script rc will enter interactive mode and wait there forever
4. Now create a new folder called /vz/template/centos/5.0/<ARCH>/config again where <ARCH> represents the system architecture.5. Create a file in the folder called rpm and add the following line: 43 6. Create a file called yum.conf in the folder and add the following lines: [main]cachedir=/vz/template/centos/5.0/<ARCH>/yum-cache/reposdir=/dev/nullinstallonlypkgs='' [centos5-base]name=CentOS 5 - <ARCH> - Basebaseurl=http://mirror.centos.org/centos/5/os/<ARCH>/enabled=1gpgcheck=1 [centos5-updates-released]name=CentOS 5 - <ARCH> - Released Updatesbaseurl=http://mirror.centos.org/centos/5/updates/<ARCH>/enabled=1gpgcheck=17. Copy /etc/vz/dists/centos-4.conf to /etc/vz/dists/centos-5.0.conf.8. Change to the /vz/private/50 folder and then run the command gunzip –dc /vz/template/cache/centos-5.0-<ARCH>-<DISTRO>-image.tar.gz | tar –xvf – to unpack the base image to the folder.9. Make sure you are in the /vz/private/50 folder.10. Edit etc/shadow and remove the replace the root password with !! instead of the hashed value.11. Edit the etc/inittab file and comment out the lines that respawn /sbin/mingetty on tty1 through tty6. Just put a # at the beginning of the line.12. Remove the etc/mtab file and then create a symbolic link by typing ln –s /proc/mounts etc/mtab.13. Remove all of the lines from etc/fstab except for the line that mounts /dev/pts.14. Edit etc/rc.d/rc.sysinit and comment out the line that starts /sbin/start_udev by placing a # at the beginning of the line.15. Now create device nodes by typing: mknod dev/ptmx c 5 2mkdir dev/pts/sbin/MAKEDEV –d /vz/private/50/dev ttyp ptypmknod dev/null c 1 3mknod dev/urandom c 1 9 16. Create the var/lock/rpm folder.17. If you wish to disable IPv6, do the following:a. Edit etc/sysconfig/network and set NETWORKING_IPV6 to no.b. Add the following lines to etc/modprobe.d/blacklist: blacklist ipv6blacklist net-pf-10 18. Disable any physical NICs by modifying the etc/sysconfig/network-scripts/ifcfg-ethX files (where X is the interface number starting from 0) and setting ONBOOT to no.19. Now you’re ready to start the template. Type '''vzctl start 50 ''' and wait for it to start.20. # You can install additional packages into the VPS container by typing '''vzyum 50 install <package> ''' at the prompt where <'''package'''> represents the name of the software package you wish to install.21. # Finally, you should turn off unnecessary services.a. ## Enter the VPS container by typing '''vzctl enter 50'''.b. ## View the services that are set to run at startup by typing '''chkconfig --list | grep 5:on'''.c. ## Disable any unwanted service by typing '''chkconfig --levels 2345 <service> ''' off where <'''service'''> represents the service to disable.#: Services that you can (and should) turn off without harm are acpid, apmd, kudzu, and microcode_ctl.22. # Exit the VPS container by typing '''exit ''' at the prompt.23. # Stop the VPS container by typing '''vzctl stop 50'''.24# Make sure you are in the '''/vz/private/50''' folder. # Finally, package up the new template by typing '''tar –czvf /vz/template/cache/centos-5.0-<ARCH>-<DISTRO>.tar.gz ./'''.25. # The template is ready for use.
1
edit

Navigation menu