<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Asiby</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Asiby"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Asiby"/>
	<updated>2026-05-15T19:56:39Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6783</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6783"/>
		<updated>2008-12-08T15:56:01Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Fixed Path */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /var/lib/vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /var/lib/vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /var/lib/vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /var/lib/vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /var/lib/vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /var/lib/vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/&lt;br /&gt;
tar czf /var/lib/vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6782</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6782"/>
		<updated>2008-12-08T15:55:16Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Fixed Path */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /var/lib/vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /var/lib/vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /var/lib/vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /var/lib/vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/&lt;br /&gt;
tar czf /var/lib/vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6781</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6781"/>
		<updated>2008-12-08T15:54:57Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Fixed Path */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /var/lib/vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /var/lib/vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /var/lib/vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/&lt;br /&gt;
tar czf /var/lib/vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6780</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6780"/>
		<updated>2008-12-08T15:54:13Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Fixed Path */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /var/lib/vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /var/lib/vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /var/lib/vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/&lt;br /&gt;
tar czf /var/lib/vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6779</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6779"/>
		<updated>2008-12-08T15:53:45Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Fixe Path */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /var/lib/vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /var/lib/vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /var/lib/vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /var/lib/vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/&lt;br /&gt;
tar czf /var/lib/vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6778</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6778"/>
		<updated>2008-12-08T15:53:15Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Fixed Path */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /var/lib/vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /var/lib/vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /var/lib/vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/&lt;br /&gt;
tar czf /var/lib/vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6777</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6777"/>
		<updated>2008-12-08T15:52:32Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Fixed path */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/var/lib/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /var/lib/vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /var/lib/vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /var/lib/vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/&lt;br /&gt;
tar czf /var/lib/vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6776</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6776"/>
		<updated>2008-12-08T15:51:03Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Making distfiles and portage tree of the host system available in a container */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /var/lib/vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /var/lib/vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /var/lib/vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/&lt;br /&gt;
tar czf /var/lib/vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6775</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6775"/>
		<updated>2008-12-08T15:50:10Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Create the template cache file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /var/lib/vz/private/777/&lt;br /&gt;
tar czf /var/lib/vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6774</id>
		<title>Gentoo template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Gentoo_template_creation&amp;diff=6774"/>
		<updated>2008-12-08T15:47:56Z</updated>

		<summary type="html">&lt;p&gt;Asiby: /* Create directory for the new container and unarchive stage3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is about making a template cache for OpenVZ container from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.&lt;br /&gt;
&lt;br /&gt;
== Download stage3 ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Create directory for the new container and unarchive stage3 ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /var/lib/vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /var/lib/vz/private/777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Create CT config ==&lt;br /&gt;
Now you need to create the configuration file for the container, 777.conf: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit CT config ==&lt;br /&gt;
&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;/etc/vz/conf/777.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OSTEMPLATE=&amp;quot;gentoo&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Make /etc/mtab a symlink to /proc/mounts ==&lt;br /&gt;
The container's root filesystem is mounted by the host system, not the guest — and therefore root fs will not appear in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;. It will lead to a non-working &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; command. To fix, link /etc/mtab to /proc/mounts.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm -f /vz/private/777/etc/mtab&lt;br /&gt;
ln -s /proc/mounts /vz/private/777/etc/mtab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After replacing &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt; with a symlink to &amp;lt;code&amp;gt;/proc/mounts&amp;lt;/code&amp;gt;, you will always have up-to-date information of what is mounted in &amp;lt;code&amp;gt;/etc/mtab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Replace /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
echo &amp;quot;proc /proc proc defaults 0 0&amp;quot; &amp;gt; /vz/private/777/etc/fstab&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We need only &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; to be mounted at boot time.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/inittab ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/inittab&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of the lines containing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;c?:1235:respawn:/sbin/agetty 38400 tty? linux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents &amp;lt;code&amp;gt;getty&amp;lt;/code&amp;gt; and login from starting on ttys that do not exist in containers.&lt;br /&gt;
&lt;br /&gt;
== Edit /etc/shadow ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/shadow&amp;lt;/code&amp;gt; and change root's password in the first line to an exclamation mark (!): &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root:!:10071:0:::::&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will disable root login until the password is changed with &amp;lt;code&amp;gt;vzctl set CTID --userpasswd root:password&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Disable unneeded init scripts ==&lt;br /&gt;
&lt;br /&gt;
The checkroot and consolefont init scripts should not be started inside containers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/checkroot&lt;br /&gt;
rm /vz/private/777/etc/runlevels/boot/consolefont&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Edit /sbin/rc ==&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/sbin/rc&amp;lt;/code&amp;gt; and put a hash mark (#) at the beginning of line 244 (your line number may be different):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This prevents the container from attempting to mount &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To ensure that this change isn't automatically overwritten on update, add the following to &amp;lt;code&amp;gt;/vz/private/777/etc/make.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;CONFIG_PROTECT = /sbin/rc&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Set up udev ==&lt;br /&gt;
&lt;br /&gt;
Using udev you will have problems since some devices nodes are not created.&lt;br /&gt;
For example sshd will fail to start since /dev/random and /dev/urandom are missing.&lt;br /&gt;
So it's recommended to disable udev.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; line to:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;static&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to enable udev read on.&lt;br /&gt;
&lt;br /&gt;
Create some device nodes needed to enter a container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /vz/private/777/lib&lt;br /&gt;
mknod udev/devices/ttyp0 c 3 0&lt;br /&gt;
mknod udev/devices/ptyp0 c 2 0&lt;br /&gt;
mknod udev/devices/ptmx c 5 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/conf.d/rc&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;RC_DEVICES&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RC_DEVICE_TARBALL&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
RC_DEVICES=&amp;quot;udev&amp;quot;&lt;br /&gt;
RC_DEVICE_TARBALL=&amp;quot;no&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You have to leave the directory you are in for the next step to be OK, otherwise you will get this error message:&lt;br /&gt;
 vzquota : (error) Quota on syscall for 777: Device or resource busy&lt;br /&gt;
 vzquota on failed [3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 777&lt;br /&gt;
vzctl enter 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can check running services:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-status -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All services in boot and default runlevels must be started. If everything all right, stop the container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl stop 777&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making distfiles and portage tree of the host system available in a container ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|This step is optional and will result in shared files between containers! These steps can save space on disk but trade isolation and security... consider your options carefully!}}&lt;br /&gt;
&lt;br /&gt;
To install software into a container with portage, you should mount &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; into the container with the &amp;quot;bind&amp;quot; option. Do the following on the host after the container is started:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir /vz/root/777/usr/portage&lt;br /&gt;
mount -o bind /usr/portage /vz/root/777/usr/portage&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; directory resides on a different partition than your &amp;lt;code&amp;gt;/usr/portage&amp;lt;/code&amp;gt; directory, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -n -o bind /usr/portage/distfiles /vz/root/777/usr/portage/distfiles&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, to install a package into a container, you just need to enter the container using &amp;lt;code&amp;gt;vzctl enter&amp;lt;/code&amp;gt; and run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
emerge package_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
while you have all the needed files in the &amp;lt;code&amp;gt;/usr/portage/distfiles&amp;lt;/code&amp;gt; of host system.&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should have these directories mounted only while installing software into a container.&lt;br /&gt;
&lt;br /&gt;
{{Note|you have to &amp;lt;code&amp;gt;umount /vz/root/777/usr/portage/distfiles&amp;lt;/code&amp;gt; before trying to stop your container.}}&lt;br /&gt;
&lt;br /&gt;
== Create the template cache file ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /vz/private/777/&lt;br /&gt;
tar czf /vz/template/cache/gentoo.tar.gz *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Test the new template cache file ==&lt;br /&gt;
&lt;br /&gt;
Create a new container from the template file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the container was created successfully, try to start it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl start 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Asiby</name></author>
		
	</entry>
</feed>