3
edits
Changes
no edit summary
This page is about making a template cache for OpenVZ VE from Gentoo linux. The method is basically the same as described in article Slackware template creation.
===Downloading stage3===
We shall do the template from stage3 file. OpenVZ OS template should be an archive of root of the working system, but without the kernel and some files. You can download stage3 from the nearest mirror here: http://www.gentoo.org/main/en/mirrors.xml.
===Create directory for the new VPS and unarchive stage3 there:===
<pre>
mkdir /vz/private/777
tar -xjf /root/stage3-i686-2006.0.tar.bz2 -C /vz/private/777
</pre>
===Creating VE config===
Now you need to create the configuration file for the VE, 777.conf:
<pre>
vzctl set 777 --applyconfig vps.basic --save
</pre>
===Editing config===
Add to the /etc/vz/conf/777.conf:
<pre>
DISTRIBUTION="gentoo"
OSTEMPLATE="gentoo"
</pre>
===Make /etc/mtab a symlink to /proc/mounts.===
<pre>
ln -s /proc/mounts /vz/private/777/etc/mtab
</pre>
===Editing /etc/fstab===
<pre>echo "proc /proc proc defaults 0 0" > /vz/private/777/etc/fstab</pre>
We need only /proc to mounted at the boot time.
===Editing inittab===
Edit /etc/inittab, put a hashmark (#) before the lines containing:
<pre>c?:1235:respawn:/sbin/agetty 38400 tty? linux</pre>
This prevents from starting getty and login.
===Editing /etc/shadow===
Edit /vz/private/777/etc/shadow, change root's password in the first line to an exclamation mark (!):
<pre>root:!:10071:0:::::</pre>
This will disable the root login until the password changed with vzctl set 777 --userpasswd root:password.
===Editing /etc/init.d/checkroot===
We have to clean this script and make them dummy, because we don't need mount or check root.
<pre>
cat > /etc/init.d/checkroot
#!/sbin/runscript
depend()
{
}
start()
{
}
end()
{
}
</pre>
===Editing /sbin/rc===
Comment line number 141:
<pre>try mount -n ${mntcmd:--t sysfs sysfs /sys}</pre>
This prevents from attepting to mount /sys.
===Setting up udev===
Delete /lib/udev-state/devices.tar.bz2 and create some device nodes needed to enter VPS:
<pre>
rm /lib/udev-state/devices.tar.bz2
mknod /lib/udev/devices/ttyp0 c 3 0
mknod /lib/udev/devices/ptyp0 c 2 0
mknod /lib/udev/devices/ptmx c 5 2
</pre>
===Testing===
<pre>
vzctl start 777
vzctl enter 777
</pre>
You can check running services.
<pre>
rc-status -a
</pre>
All services in boot and default runlevels must be started. If everything all right, stop it
<pre>
vzctl stop 777
</pre>
===Making distfiles и portage of the host system available in VPS.===
To install software into VPS with portage you should mount /usr/portage into VPS with "bind" option. Do this after VPS starts:
<pre>
mkdir /vz/root/777/usr/portage
mount -o bind /usr/portage /vz/root/777/usr/portage
</pre>
If your /usr/portage/distfiles placed on the other partition do:
<pre>
mount -o bind /usr/portage/distfiles /vz/root/777/usr/portage/distfiles
</pre>
Now, to install package into VPS you just need enter there by chroot or vzctl enter and
<pre>
emerge package_name
</pre>
while you have all needed files in the /usr/portage/distfiles of host system.
For security reasons hold this directories mounted only while you are installing software into VPS.
===Creating the cache file===
<pre>
cd /vz/private/777/
tar czf /vz/template/cache/gentoo.tar.gz *
</pre>
===Testing the new cache file===
<pre>
vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps
</pre>
If created successfully, try to start it:
<pre>
vzctl start 555
</pre>
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!