Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

Gentoo template creation

170 bytes added, 07:58, 19 May 2008
VE -> container; fixed headings level; some formatting fixes
This page is about making a template cache for OpenVZ VE container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.
===Download stage3===
We will make the template from a stage3 file. An OpenVZ OS template should be an archive (.tar.gz) of the root of a working system, but without the kernel and some files. You can download stage3 from the nearest mirror here: http://www.gentoo.org/main/en/mirrors.xml.
===Create directory for the new VE container and unarchive stage3 ===
<pre>
</pre>
===Create VE CT config===Now you need to create the configuration file for the VEcontainer, 777.conf:
<pre>
</pre>
===Edit VE CT config===
Add the following to <code>/etc/vz/conf/777.conf</code>:
<pre>
DISTRIBUTION="gentoo"
OSTEMPLATE="gentoo"
</pre>
===Make /etc/mtab a symlink to /proc/mounts===The VE container's root filesystem is mounted by the host system, not the guest -- and therefore root fs will not appear in <code>/etc/mtab</code>. It will lead to a non-working <code>df </code> command. To fix, link /etc/mtab to /proc/mounts.
<pre>
rm -f /vz/private/777/etc/mtab
After replacing <code>/etc/mtab</code> with a symlink to <code>/proc/mounts</code>, you will always have up-to-date information of what is mounted in <code>/etc/mtab</code>.
===Replace /etc/fstab===
<pre>
We need only <code>/proc</code> to be mounted at boot time.
===Edit /etc/inittab===
Edit <code>/vz/private/777/etc/inittab</code> and put a hash mark (#) at the beginning of the lines containing:
<pre>c?:1235:respawn:/sbin/agetty 38400 tty? linux</pre>
This prevents <code>getty</code> and login from starting on ttys that do not exist in VEscontainers.
===Edit /etc/shadow===
Edit <code>/vz/private/777/etc/shadow</code> and change root's password in the first line to an exclamation mark (!):
<pre>root:!:10071:0:::::</pre>
This will disable root login until the password is changed with <code>vzctl set VEID CTID --userpasswd root:password</code>.
===Disable unneeded init scripts===
The checkroot and consolefont init scripts should not be started inside VEscontainers:
<pre>
</pre>
===Edit /sbin/rc===
Edit <code>/vz/private/777/sbin/rc</code> and put a hash mark (#) at the beginning of line 244 (your line number may be different):
<pre># try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}</pre>
This prevents the VE container from attempting to mount <code>/sys</code>.
To ensure that this change isn't automatically overwritten on update, add the following to <code>/vz/private/777/etc/make.conf</code>:
<pre>CONFIG_PROTECT = /sbin/rc</pre>
===Set up udev===
<div class="previewnote"><p><strong>NOTE: udev-state does not exists anymore!! ../lib/udev/state and ../lib/udev/devices are empty directories now... maybe someone knows how to handle it the right way?</strong></p></div>
Delete <code>/lib/udev-state/devices.tar.bz2</code> and create some device nodes needed to enter a VEcontainer:
<pre>
</pre>
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message : <br> vzquota : (error) Quota on syscall for 777: Device or resource busy <br> vzquota on failed [3] <br>
<pre>
</pre>
===Test===
<pre>
</pre>
All services in boot and default runlevels must be started. If everything all right, stop the VEcontainer:
<pre>
</pre>
===Making distfiles and portage tree of the host system available in a VE=container ==
{{Warning|This step is optional and will result in shared files between VEscontainers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}
To install software into a VE container with portage, you should mount <code>/usr/portage</code> into the VE container with the "bind" option. Do the following on the host after the VE container is started:
<pre>
</pre>
Now, to install a package into a VEcontainer, you just need to enter the VE container using <code>vzctl enter</code> and run
<pre>
while you have all the needed files in the <code>/usr/portage/distfiles</code> of host system.
For security reasons, you should have these directories mounted only while installing software into a VEcontainer.
{{Note|you have to <code>umount /vz/root/777/usr/portage/distfiles</code> before trying to stop your VEcontainer.}}
===Create the template cache file===
<pre>
</pre>
===Test the new template cache file===
Create a new VE container from the template file:
<pre>
</pre>
If the VE container was created successfully, try to start it:
<pre>