Open main menu

OpenVZ Virtuozzo Containers Wiki β

Creating a CentOS 5.0 Template

Revision as of 19:46, 2 November 2007 by Josh.hogle (talk | contribs)

Creating a CentOS 5.0 Template for OpenVZ<o:p></o:p>

<o:p> </o:p>

  1. 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.<o:p></o:p>
  2. Once the OS has been installed, you need to tar the contents of the OS.<o:p></o:p>
    1. First, create a file called /tmp/exclude and add the following lines to it:<o:p></o:p>

<o:p> </o:p>

.bash_history<o:p></o:p>

lost+found<o:p></o:p>

/dev/*<o:p></o:p>

/mnt/*<o:p></o:p>

/tmp/*<o:p></o:p>

/proc/*<o:p></o:p>

/sys/*<o:p></o:p>

/usr/src/*<o:p></o:p>

<o:p> </o:p>

    1. Now, tar the OS file up by typing:<o:p></o:p>

<o:p> </o:p>

tar –czvf /tmp/centos-5.0-<ARCH>-<DISTRO>-image.tar.gz / –X  /tmp/exclude<o:p></o:p>

      <o:p></o:p>

where <ARCH> represents the system architecture (i386 or x86_64) and <DISTRO> represents the distribution (default, minimal, etc.).<o:p></o:p>

    1. Now transfer the file over to the OpenVZ server into /vz/template/cache folder.<o:p></o:p>
  1. On the OpenVZ server create a “dummy” VPS 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.<o:p></o:p>

<o:p> </o:p>

NOTE:<o:p></o:p>

50 is the VEID for the VPS.  You can choose any unused VEID on the OpenVZ server.<o:p></o:p>

<o:p> </o:p>

  1. Now create a new folder called /vz/template/centos/5.0/<ARCH>/config again where <ARCH> represents the system architecture.<o:p></o:p>
  2. Create a file in the folder called rpm and add the following line:<o:p></o:p>

<o:p> </o:p>

43<o:p></o:p>

<o:p> </o:p>

  1. Create a file called yum.conf in the folder and add the following lines:<o:p></o:p>

<o:p> </o:p>

[main]<o:p></o:p>

cachedir=/vz/template/centos/5.0/<ARCH>/yum-cache/<o:p></o:p>

reposdir=/dev/null<o:p></o:p>

installonlypkgs=<o:p></o:p>

<o:p> </o:p>

[centos5-base]<o:p></o:p>

name=CentOS 5 - <ARCH> - Base<o:p></o:p>

baseurl=http://mirror.centos.org/centos/5/os/<ARCH>/<o:p></o:p>

enabled=1<o:p></o:p>

gpgcheck=1<o:p></o:p>

<o:p> </o:p>

[centos5-updates-released]<o:p></o:p>

name=CentOS 5 - <ARCH> - Released Updates<o:p></o:p>

baseurl=http://mirror.centos.org/centos/5/updates/<ARCH>/<o:p></o:p>

enabled=1<o:p></o:p>

gpgcheck=1<o:p></o:p>

  1. Copy /etc/vz/dists/centos-4.conf to /etc/vz/dists/centos-5.0.conf.<o:p></o:p>
  2. 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.<o:p></o:p>
  3. Make sure you are in the /vz/private/50 folder.<o:p></o:p>
  4. Edit etc/shadow and remove the replace the root password with !! instead of the hashed value.<o:p></o:p>
  5. 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.<o:p></o:p>
  6. Remove the etc/mtab file and then create a symbolic link by typing ln –s /proc/mounts etc/mtab.<o:p></o:p>
  7. Remove all of the lines from etc/fstab except for the line that mounts /dev/pts.<o:p></o:p>
  8. 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.<o:p></o:p>
  9. Now create device nodes by typing:<o:p></o:p>

<o:p> </o:p>

mknod dev/ptmx c 5 2<o:p></o:p>

mkdir dev/pts<o:p></o:p>

/sbin/MAKEDEV –d /vz/private/50/dev ttyp ptyp<o:p></o:p>

mknod dev/null c 1 3<o:p></o:p>

mknod dev/urandom c 1 9<o:p></o:p>

<o:p> </o:p>

  1. Create the var/lock/rpm folder.<o:p></o:p>
  2. If you wish to disable IPv6, do the following:<o:p></o:p>
    1. Edit etc/sysconfig/network and set NETWORKING_IPV6 to no.<o:p></o:p>
    2. Add the following lines to etc/modprobe.d/blacklist:<o:p></o:p>

<o:p> </o:p>

blacklist ipv6<o:p></o:p>

blacklist net-pf-10<o:p></o:p>

<o:p> </o:p>

  1. 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.<o:p></o:p>
  2. Now you’re ready to start the template.  Type vzctl start 50 and wait for it to start.<o:p></o:p>
  3. You can install additional packages into the VPS by typing vzyum 50 install <package> at the prompt where <package> represents the name of the software package you wish to install.<o:p></o:p>
  4. Finally, you should turn off unnecessary services.<o:p></o:p>
    1. Enter the VPS by typing vzctl enter 50.<o:p></o:p>
    2. View the services that are set to run at startup by typing chkconfig --list | grep 5:on.<o:p></o:p>
    3. Disable any unwanted service by typing chkconfig --levels 2345 <service> off where <service> represents the service to disable.<o:p></o:p>

Services that you can (and should) turn off without harm are acpid, apmd, kudzu, and microcode_ctl.<o:p></o:p>

  1. Exit the VPS by typing exit at the prompt.<o:p></o:p>
  2. Stop the VPS by typing vzctl stop 50.<o:p></o:p>
  3. Finally, package up the new template by typing tar –czvf /vz/template/cache/centos-5.0-<ARCH>-<DISTRO>.tar.gz .<o:p></o:p>
  4. The template is ready for use.<o:p></o:p>

<o:p> </o:p>

<o:p> </o:p>

</body>

</html>