Difference between revisions of "Creating a CentOS 5.0 Template"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
Line 1: Line 1:
<div style="font-size: 14pt"><strong>Creating a CentOS 5.0 Template for OpenVZ</strong></div>
+
<div class=Section1>
<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>
+
<p class=MsoNormal><b style='mso-bidi-font-weight:normal'><u><span
  <li>Once the OS has been installed, you need to tar the contents of the OS.
+
style='font-size:14.0pt;font-family:Tahoma'>Creating a <span class=SpellE>CentOS</span>
      <ol style="list-style-type: lower-alpha">
+
5.0 Template for <span class=SpellE>OpenVZ</span><o:p></o:p></span></u></b></p>
        <li>First, create a file called /tmp/exclude and add the following lines to it:<br />
+
 
            <code>.bash_history<br />lost+found<br />/dev/*<br />/mnt/*<br />/tmp/*<br />
+
<p class=MsoNormal><span style='font-size:10.0pt;font-family:Tahoma'><o:p>&nbsp;</o:p></span></p>
            /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>
+
<ol style='margin-top:0in' start=1 type=1>
        <li>Now transfer the file over to the OpenVZ server into the <strong>/vz/template/cache</strong> folder.</li>
+
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
      </ol></li>
+
    style='font-size:10.0pt;font-family:Tahoma'>Install a system (virtual or
  <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>.
+
    physical) with the default <span class=SpellE>CentOS</span> installation
 +
    that you wish to package.<span style='mso-spacerun:yes'>  </span>This
 +
    could be a minimal <span class=SpellE>distro</span> or the default <span
 +
    class=SpellE>distro</span> or even something custom.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Once the OS has been
 +
    installed, you need to <b style='mso-bidi-font-weight:normal'>tar</b> the
 +
    contents of the OS.<o:p></o:p></span></li>
 +
<ol style='margin-top:0in' start=1 type=a>
 +
  <li class=MsoNormal style='mso-list:l0 level2 lfo1;tab-stops:list 1.0in'><span
 +
      style='font-size:10.0pt;font-family:Tahoma'>First, create a file called <b
 +
      style='mso-bidi-font-weight:normal'>/<span class=SpellE>tmp</span>/exclude
 +
      </b>and add the following lines to it:<o:p></o:p></span></li>
 +
</ol>
 +
</ol>
 +
 
 +
<p class=MsoNormal style='margin-left:.75in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.25in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>.<span class=SpellE>bash_history</span><o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.25in;text-indent:-.25in'><span
 +
class=SpellE><span style='font-size:10.0pt;font-family:"Courier New"'>lost+found</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.25in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>/dev/*<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.25in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>/<span class=SpellE>mnt</span>/*<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.25in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>/<span class=SpellE>tmp</span>/*<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.25in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>/proc/*<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.25in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>/sys/*<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.25in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>/<span class=SpellE>usr/src</span>/*<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.75in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:Tahoma'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<ol style='margin-top:0in' start=2 type=1>
 +
<ol style='margin-top:0in' start=2 type=a>
 +
  <li class=MsoNormal style='mso-list:l0 level2 lfo1;tab-stops:list 1.0in'><span
 +
      style='font-size:10.0pt;font-family:Tahoma'>Now, <b style='mso-bidi-font-weight:
 +
      normal'>tar </b>the OS file up by typing:<o:p></o:p></span></li>
 +
</ol>
 +
</ol>
 +
 
 +
<p class=MsoNormal style='margin-left:.75in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.0in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>tar –<span class=SpellE>czvf</span>
 +
/tmp/centos-5.0-&lt;ARCH&gt;-&lt;DISTRO&gt;-<span class=SpellE>image.tar.gz</span>
 +
/ –X<span style='mso-spacerun:yes'>  </span>/<span class=SpellE>tmp</span>/exclude<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.75in;text-indent:-.25in'><span
 +
style='font-size:10.0pt;font-family:"Courier New"'><span style='mso-tab-count:
 +
2'>      </span><o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.0in'><span style='font-size:10.0pt;
 +
font-family:Tahoma'>where <b style='mso-bidi-font-weight:normal'>&lt;ARCH&gt;</b>
 +
represents the system architecture (<b style='mso-bidi-font-weight:normal'>i386</b>
 +
or <b style='mso-bidi-font-weight:normal'>x86_64</b>) and <b style='mso-bidi-font-weight:
 +
normal'>&lt;DISTRO&gt;</b> represents the distribution (<b style='mso-bidi-font-weight:
 +
normal'>default</b>, <b style='mso-bidi-font-weight:normal'>minimal</b>, etc.).<o:p></o:p></span></p>
 +
 
 +
<ol style='margin-top:0in' start=2 type=1>
 +
<ol style='margin-top:0in' start=3 type=a>
 +
  <li class=MsoNormal style='mso-list:l0 level2 lfo1;tab-stops:list 1.0in'><span
 +
      style='font-size:10.0pt;font-family:Tahoma'>Now transfer the file over to
 +
      the <span class=SpellE>OpenVZ</span> server into <b style='mso-bidi-font-weight:
 +
      normal'>/<span class=SpellE>vz</span>/template/cache </b>folder.<o:p></o:p></span></li>
 +
</ol>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>On the <span class=SpellE>OpenVZ</span>
 +
    server create a “dummy” VPS by creating a folder called <b
 +
    style='mso-bidi-font-weight:normal'>/vz/private/50</b> and copying the <b
 +
    style='mso-bidi-font-weight:normal'>/<span class=SpellE>etc/vz/conf/ve-vps.basic.conf-sample</span></b>
 +
    to <b style='mso-bidi-font-weight:normal'>/etc/vz/conf/50.conf</b>.<o:p></o:p></span></li>
 +
</ol>
 +
 
 +
<p class=MsoNormal style='margin-left:.25in'><span style='font-size:10.0pt;
 +
font-family:Tahoma'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><b style='mso-bidi-font-weight:
 +
normal'><span style='font-size:8.0pt;font-family:Tahoma;color:red'>NOTE:<o:p></o:p></span></b></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><b style='mso-bidi-font-weight:
 +
normal'><span style='font-size:8.0pt;font-family:Tahoma;color:red'>50</span></b><span
 +
style='font-size:8.0pt;font-family:Tahoma;color:red'> is the VEID for the
 +
VPS.<span style='mso-spacerun:yes'>  </span>You can choose any unused VEID on
 +
the <span class=SpellE>OpenVZ</span> server.<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:8.0pt;
 +
font-family:Tahoma'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<ol style='margin-top:0in' start=4 type=1>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Now create a new folder called
 +
    <b style='mso-bidi-font-weight:normal'>/vz/template/centos/5.0/&lt;ARCH&gt;/<span
 +
    class=SpellE>config</span></b> again where <b style='mso-bidi-font-weight:
 +
    normal'>&lt;ARCH&gt;</b> represents the system architecture.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Create a file in the folder
 +
    called <b style='mso-bidi-font-weight:normal'>rpm</b> and add the
 +
    following line:<o:p></o:p></span></li>
 +
</ol>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>43<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<ol style='margin-top:0in' start=6 type=1>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Create a file called <span
 +
    class=SpellE><b style='mso-bidi-font-weight:normal'>yum.conf</b></span> in
 +
    the folder and add the following lines:<o:p></o:p></span></li>
 
</ol>
 
</ol>
  
NOTE:
+
<p class=MsoNormal style='margin-left:.25in'><span style='font-size:10.0pt;
50 is the VEID for the VPS. You can choose any unused VEID on the OpenVZ server.
+
font-family:Tahoma'><o:p>&nbsp;</o:p></span></p>
  
4. Now create a new folder called /vz/template/centos/5.0/<ARCH>/config again where <ARCH> represents the system architecture.
+
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
5. Create a file in the folder called rpm and add the following line:
+
font-family:"Courier New"'>[main]<o:p></o:p></span></p>
  
43
+
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>cachedir</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>=/vz/template/centos/5.0/&lt;ARCH&gt;/yum-cache/<o:p></o:p></span></p>
  
6. Create a file called yum.conf in the folder and add the following lines:
+
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>reposdir</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>=/dev/null<o:p></o:p></span></p>
  
[main]
+
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
cachedir=/vz/template/centos/5.0/<ARCH>/yum-cache/
+
style='font-size:10.0pt;font-family:"Courier New"'>installonlypkgs</span></span><span
reposdir=/dev/null
+
style='font-size:10.0pt;font-family:"Courier New"'>=''<o:p></o:p></span></p>
installonlypkgs=''
 
  
[centos5-base]
+
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
name=CentOS 5 - <ARCH> - Base
+
font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
baseurl=http://mirror.centos.org/centos/5/os/<ARCH>/
+
 
enabled=1
+
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
gpgcheck=1
+
font-family:"Courier New"'>[centos5-base]<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>name=<span class=SpellE>CentOS</span> 5 - &lt;ARCH&gt;
 +
- Base<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>baseurl</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>=http://mirror.centos.org/centos/5/os/&lt;ARCH&gt;/<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>enabled=1<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>gpgcheck</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>=1<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>[centos5-updates-released]<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>name=<span class=SpellE>CentOS</span> 5 - &lt;ARCH&gt;
 +
- Released Updates<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>baseurl</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>=http://mirror.centos.org/centos/5/updates/&lt;ARCH&gt;/<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>enabled=1<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>gpgcheck</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>=1<o:p></o:p></span></p>
 +
 
 +
<ol style='margin-top:0in' start=7 type=1>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Copy <b style='mso-bidi-font-weight:
 +
    normal'>/etc/vz/dists/centos-4.conf</b> to <b style='mso-bidi-font-weight:
 +
    normal'>/etc/vz/dists/centos-5.0.conf</b>.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Change to the <b
 +
    style='mso-bidi-font-weight:normal'>/vz/private/50</b> folder and then run
 +
    the command </span><span class=SpellE><span style='font-size:10.0pt;
 +
    font-family:"Courier New"'>gunzip</span></span><span style='font-size:
 +
    10.0pt;font-family:"Courier New"'> –dc
 +
    /vz/template/cache/centos-5.0-&lt;ARCH&gt;-&lt;DISTRO&gt;-<span
 +
    class=SpellE>image.tar.gz</span> | tar –<span class=SpellE>xvf</span> –<b
 +
    style='mso-bidi-font-weight:normal'> </b></span><span style='font-size:
 +
    10.0pt;font-family:Tahoma'>to unpack the base image to the folder.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Make sure you are in the <b
 +
    style='mso-bidi-font-weight:normal'>/vz/private/50</b> folder.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Edit <b style='mso-bidi-font-weight:
 +
    normal'>etc/shadow</b> and remove the replace the <b style='mso-bidi-font-weight:
 +
    normal'>root</b> password with <b style='mso-bidi-font-weight:normal'>!!</b>
 +
    instead of the hashed value.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Edit the <b style='mso-bidi-font-weight:
 +
    normal'>etc/<span class=SpellE>inittab</span></b> file and comment out the
 +
    lines that <span class=SpellE>respawn</span> <b style='mso-bidi-font-weight:
 +
    normal'>/<span class=SpellE>sbin/mingetty</span></b> on <b
 +
    style='mso-bidi-font-weight:normal'>tty1</b> through <b style='mso-bidi-font-weight:
 +
    normal'>tty6</b>.<span style='mso-spacerun:yes'>  </span>Just put a <b
 +
    style='mso-bidi-font-weight:normal'>#</b> at the beginning of the line.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Remove the <b
 +
    style='mso-bidi-font-weight:normal'>etc/<span class=SpellE>mtab</span></b>
 +
    file and then create a symbolic link by typing </span><span class=SpellE><span
 +
    style='font-size:10.0pt;font-family:"Courier New"'>ln</span></span><span
 +
    style='font-size:10.0pt;font-family:"Courier New"'> –s /proc/mounts etc/<span
 +
    class=SpellE>mtab</span></span><span style='font-size:10.0pt;font-family:
 +
    Tahoma'>.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Remove all of the lines from <b
 +
    style='mso-bidi-font-weight:normal'>etc/<span class=SpellE>fstab</span></b>
 +
    except for the line that mounts <b style='mso-bidi-font-weight:normal'>/dev/pts</b>.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Edit <b style='mso-bidi-font-weight:
 +
    normal'>etc/<span class=SpellE>rc.d/rc.sysinit</span></b> and comment out
 +
    the line that starts <b style='mso-bidi-font-weight:normal'>/<span
 +
    class=SpellE>sbin/start_udev</span></b> by placing a <b style='mso-bidi-font-weight:
 +
    normal'>#</b> at the beginning of the line.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Now create device nodes by
 +
    typing:<o:p></o:p></span></li>
 +
</ol>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>mknod</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'> dev/<span class=SpellE>ptmx</span>
 +
c 5 2<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>mkdir</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'> dev/pts<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>/<span class=SpellE>sbin</span>/MAKEDEV –d
 +
/vz/private/50/dev <span class=SpellE>ttyp</span> <span class=SpellE>ptyp</span><o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>mknod</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'> dev/null c 1 3<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span class=SpellE><span
 +
style='font-size:10.0pt;font-family:"Courier New"'>mknod</span></span><span
 +
style='font-size:10.0pt;font-family:"Courier New"'> dev/<span class=SpellE>urandom</span>
 +
c 1 9<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<ol style='margin-top:0in' start=16 type=1>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Create the <span class=SpellE><b
 +
    style='mso-bidi-font-weight:normal'>var</b></span><b style='mso-bidi-font-weight:
 +
    normal'>/lock/rpm</b> folder.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>If you wish to disable IPv6,
 +
    do the following:<o:p></o:p></span></li>
 +
<ol style='margin-top:0in' start=1 type=a>
 +
  <li class=MsoNormal style='mso-list:l0 level2 lfo1;tab-stops:list 1.0in'><span
 +
      style='font-size:10.0pt;font-family:Tahoma'>Edit <b style='mso-bidi-font-weight:
 +
      normal'>etc/<span class=SpellE>sysconfig</span>/network</b> and set <b
 +
      style='mso-bidi-font-weight:normal'>NETWORKING_IPV6</b> to <b
 +
      style='mso-bidi-font-weight:normal'>no</b>.<o:p></o:p></span></li>
 +
  <li class=MsoNormal style='mso-list:l0 level2 lfo1;tab-stops:list 1.0in'><span
 +
      style='font-size:10.0pt;font-family:Tahoma'>Add the following lines to <b
 +
      style='mso-bidi-font-weight:normal'>etc/<span class=SpellE>modprobe.d</span>/blacklist</b>:<o:p></o:p></span></li>
 +
</ol>
 +
</ol>
 +
 
 +
<p class=MsoNormal style='margin-left:1.0in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.0in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>blacklist ipv6<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.0in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'>blacklist net-pf-10<o:p></o:p></span></p>
 +
 
 +
<p class=MsoNormal style='margin-left:1.0in'><span style='font-size:10.0pt;
 +
font-family:"Courier New"'><o:p>&nbsp;</o:p></span></p>
 +
 
 +
<ol style='margin-top:0in' start=18 type=1>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Disable any physical <span
 +
    class=SpellE>NICs</span> by modifying the <span class=SpellE><b
 +
    style='mso-bidi-font-weight:normal'>etc/sysconfig/network-scripts/ifcfg-ethX</b></span>
 +
    files (where <b style='mso-bidi-font-weight:normal'>X</b> is the interface
 +
    number starting from <b style='mso-bidi-font-weight:normal'>0</b>) and
 +
    setting <b style='mso-bidi-font-weight:normal'>ONBOOT</b> to <b
 +
    style='mso-bidi-font-weight:normal'>no</b>.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Now you’re ready to start the
 +
    template.<span style='mso-spacerun:yes'>  </span>Type </span><span
 +
    class=SpellE><span style='font-size:10.0pt;font-family:"Courier New"'>vzctl</span></span><span
 +
    style='font-size:10.0pt;font-family:"Courier New"'> start 50</span><span
 +
    style='font-size:10.0pt;font-family:Tahoma'> and wait for it to start.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>You can install additional
 +
    packages into the VPS by typing</span><span style='font-size:10.0pt;
 +
    font-family:"Courier New"'> <span class=SpellE>vzyum</span> 50 install
 +
    &lt;package&gt;</span><span style='font-size:10.0pt;font-family:Tahoma'>
 +
    at the prompt where <b style='mso-bidi-font-weight:normal'>&lt;package&gt;</b>
 +
    represents the name of the software package you wish to install.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Finally, you should turn off
 +
    unnecessary services.<o:p></o:p></span></li>
 +
<ol style='margin-top:0in' start=1 type=a>
 +
  <li class=MsoNormal style='mso-list:l0 level2 lfo1;tab-stops:list 1.0in'><span
 +
      style='font-size:10.0pt;font-family:Tahoma'>Enter the VPS by typing </span><span
 +
      class=SpellE><span style='font-size:10.0pt;font-family:"Courier New"'>vzctl</span></span><span
 +
      style='font-size:10.0pt;font-family:"Courier New"'> enter 50</span><span
 +
      style='font-size:10.0pt;font-family:Tahoma'>.<o:p></o:p></span></li>
 +
  <li class=MsoNormal style='mso-list:l0 level2 lfo1;tab-stops:list 1.0in'><span
 +
      style='font-size:10.0pt;font-family:Tahoma'>View the services that are
 +
      set to run at startup by typing </span><span class=SpellE><span
 +
      style='font-size:10.0pt;font-family:"Courier New"'>chkconfig</span></span><span
 +
      style='font-size:10.0pt;font-family:"Courier New"'> --list | <span
 +
      class=SpellE>grep</span> 5:on</span><span style='font-size:10.0pt;
 +
      font-family:Tahoma'>.<o:p></o:p></span></li>
 +
  <li class=MsoNormal style='mso-list:l0 level2 lfo1;tab-stops:list 1.0in'><span
 +
      style='font-size:10.0pt;font-family:Tahoma'>Disable any unwanted service
 +
      by typing </span><span class=SpellE><span style='font-size:10.0pt;
 +
      font-family:"Courier New"'>chkconfig</span></span><span style='font-size:
 +
      10.0pt;font-family:"Courier New"'> --levels 2345 &lt;service&gt; off</span><span
 +
      style='font-size:10.0pt;font-family:Tahoma'> where <b style='mso-bidi-font-weight:
 +
      normal'>&lt;service&gt;</b> represents the service to disable.<o:p></o:p></span></li>
 +
</ol>
 +
</ol>
 +
 
 +
<p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;
 +
font-family:Tahoma'>Services that you can (and should) turn off without harm
 +
are <span class=SpellE><b style='mso-bidi-font-weight:normal'>acpid</b></span>,
 +
<span class=SpellE><b style='mso-bidi-font-weight:normal'>apmd</b></span>, <b
 +
style='mso-bidi-font-weight:normal'>kudzu</b>, and <span class=SpellE><b
 +
style='mso-bidi-font-weight:normal'>microcode_ctl</b></span>.<o:p></o:p></span></p>
 +
 
 +
<ol style='margin-top:0in' start=22 type=1>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Exit the VPS by typing </span><span
 +
    style='font-size:10.0pt;font-family:"Courier New"'>exit</span><span
 +
    style='font-size:10.0pt;font-family:Tahoma'> at the prompt.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Stop the VPS by typing <span
 +
    class=SpellE>vzctl</span> stop 50.<o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>Finally, package up the new
 +
    template by typing </span><span style='font-size:10.0pt;font-family:"Courier New"'>tar
 +
    –<span class=SpellE>czvf</span>
 +
    /vz/template/cache/centos-5.0-&lt;ARCH&gt;-&lt;DISTRO&gt;.<span
 +
    class=SpellE>tar.gz</span> .</span><span style='font-size:10.0pt;
 +
    font-family:Tahoma'><o:p></o:p></span></li>
 +
<li class=MsoNormal style='mso-list:l0 level1 lfo1;tab-stops:list .5in'><span
 +
    style='font-size:10.0pt;font-family:Tahoma'>The template is ready for use.<o:p></o:p></span></li>
 +
</ol>
  
[centos5-updates-released]
+
<p class=MsoNormal><span style='font-size:10.0pt;font-family:Tahoma'><o:p>&nbsp;</o:p></span></p>
name=CentOS 5 - <ARCH> - Released Updates
 
baseurl=http://mirror.centos.org/centos/5/updates/<ARCH>/
 
enabled=1
 
gpgcheck=1
 
7. 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 2
+
<p class=MsoNormal style='margin-left:.75in;text-indent:-.25in'><span
mkdir dev/pts
+
style='font-size:10.0pt;font-family:Tahoma'><o:p>&nbsp;</o:p></span></p>
/sbin/MAKEDEV –d /vz/private/50/dev ttyp ptyp
 
mknod dev/null c 1 3
 
mknod dev/urandom c 1 9
 
  
16. Create the var/lock/rpm folder.
+
</div>
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 ipv6
+
</body>
blacklist 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.
+
</html>
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 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 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 by typing exit at the prompt.
 
23. Stop the VPS by typing vzctl stop 50.
 
24. 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.
 

Revision as of 19:46, 2 November 2007

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>