<?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=Jschmidt</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=Jschmidt"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Jschmidt"/>
	<updated>2026-05-15T16:24:12Z</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=11599</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=11599"/>
		<updated>2011-11-15T13:11:22Z</updated>

		<summary type="html">&lt;p&gt;Jschmidt: /* Make /etc/mtab a symlink to /proc/mounts */&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 /vz/private/777&lt;br /&gt;
tar -xjf /root/stage3-i686-2008.0_beta2.tar.bz2 -C /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;
Creation of container at end of this HowTo obeys quota limits and might exceed &lt;br /&gt;
those limits set in &amp;lt;code&amp;gt;vps.basic&amp;lt;/code&amp;gt; by default (at least encountered with Gentoo &lt;br /&gt;
10.1 release). Thus it might be required to increase limits now. The following &lt;br /&gt;
values are providing 2 GiByte soft limit with 2.5 GiByte hard limit:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DISKSPACE=&amp;quot;2097152:2621440&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After that you copy that configuration file turning it into a sample configuration for later use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# cp /etc/vz/conf/777.conf /etc/vz/conf/ve-gentoo.conf-sample&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;. You will, however, have an error on boot (in &amp;lt;code&amp;gt;/var/log/init.log&amp;lt;/code&amp;gt;) that can be safely ignored: &amp;lt;code&amp;gt;* /etc/mtab is not updateable [ !! ]&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 and /etc/init.d/halt.sh ==&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;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/init.d/halt.sh&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;sulogin -t 10 /dev/console&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=&amp;quot;/sbin/rc&amp;quot;&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;
== Edit /etc/pam.d/chpasswd ==&lt;br /&gt;
&lt;br /&gt;
Some changes are required for successful setting user's password with &amp;lt;code&amp;gt;vzctl&amp;lt;/code&amp;gt; util.&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/vz/private/777/etc/pam.d/chpasswd&amp;lt;/code&amp;gt; and change the &amp;lt;code&amp;gt;password&amp;lt;/code&amp;gt; lines to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
password required pam_unix.so md5 shadow&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.&lt;br /&gt;
&lt;br /&gt;
Enable SSH daemon if required:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-update add sshd default&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Warning|'''Do not start sshd''' in template container as it would create server's pair of keys then shared among all containers instantiated later.}}&lt;br /&gt;
&lt;br /&gt;
Next leave container pressing Ctrl+D and stop it:&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;
&lt;br /&gt;
== Dedicated installation of portage ==&lt;br /&gt;
&lt;br /&gt;
If you decide not to share portage with host as described before, you'll still need a portage installed into your container.&lt;br /&gt;
&lt;br /&gt;
Get latest snapshot of portage tree from your favourite mirror (http://www.gentoo.org/main/en/mirrors.xml) and extract it into &amp;lt;code&amp;gt;/vz/private/777/usr&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# wget &amp;lt;your-mirro&amp;gt;/snapshots/portage-latest.tar.bz2&lt;br /&gt;
# tar xjf portage-latest.tar.bz2 -C /vz/private/777/usr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Host system portage tree and distfiles in read-only mode ==&lt;br /&gt;
&lt;br /&gt;
You can safely share portage tree from the host system among all Gentoo VPSs by mounting it in read-only mode and defining dedicated &amp;lt;code&amp;gt;distfiles&amp;lt;/code&amp;gt; directory. All files in regular &amp;lt;code&amp;gt;distfiles&amp;lt;/code&amp;gt; directory will be also available to guest containers.&lt;br /&gt;
&lt;br /&gt;
Create &amp;lt;code&amp;gt;/etc/vz/conf/vps.mount&amp;lt;/code&amp;gt; to mount RO portage to all Gentoo guests or &amp;lt;code&amp;gt;/etc/vz/conf/&amp;lt;vps id&amp;gt;.mount&amp;lt;/code&amp;gt; to mount portage tree only to particular container:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
source /etc/vz/vz.conf&lt;br /&gt;
source ${VE_CONFFILE}&lt;br /&gt;
if [ -d /vz/root/$VEID/usr/portage ]; then&lt;br /&gt;
    mount -n --bind -o ro /vz/portage /vz/root/$VEID/usr/portage&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make it executable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chmod u+x /etc/vz/conf/vps.mount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following strings to the &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;&lt;br /&gt;
PORTAGE_RO_DISTDIRS=&amp;quot;/usr/portage/distfiles&amp;quot;&lt;br /&gt;
DISTDIR=&amp;quot;/usr/portage_distfiles&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should update host-node portage tree on regular basis to keep it up to date because &amp;lt;code&amp;gt;emerge --sync&amp;lt;/code&amp;gt; won't work inside guest 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 --numeric-owner -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 --config 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 enter it using &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl enter 800&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
congratulations, you've got a working Gentoo template!&lt;br /&gt;
&lt;br /&gt;
== Log in over SSH ==&lt;br /&gt;
&lt;br /&gt;
Leave container by hitting Ctrl+D. To log in over SSH now, you need to set root's password in running container first:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 800 --userpasswd root:secret&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, you should use different password (replacing &amp;lt;code&amp;gt;secret&amp;lt;/code&amp;gt; above) obeying common rules for strong passwords. After that container is ready for login over SSH&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh root@192.168.0.10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Gentoo]]&lt;/div&gt;</summary>
		<author><name>Jschmidt</name></author>
		
	</entry>
</feed>