Difference between revisions of "Gentoo template creation"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
m (Downloading stage3)
(Categorized; more formatting; fixed headers to be in the simple form)
Line 1: Line 1:
+
This page is about making a template cache for OpenVZ VE from Gentoo Linux. The method is basically the same as described in [[Slackware template creation]] article.
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===
+
===Download stage3===
  
 
We shall make 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.
 
We shall make 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:===
+
===Create directory for the new VE and unarchive stage3 ===
  
 
<pre>
 
<pre>
Line 13: Line 12:
 
</pre>
 
</pre>
  
===Creating VE config===
+
===Create VE config===
 
Now you need to create the configuration file for the VE, 777.conf:  
 
Now you need to create the configuration file for the VE, 777.conf:  
  
Line 20: Line 19:
 
</pre>
 
</pre>
  
===Editing config===
+
===Edit config===
  
 
Add to the /etc/vz/conf/777.conf:
 
Add to the /etc/vz/conf/777.conf:
Line 28: Line 27:
 
</pre>
 
</pre>
  
===Make /etc/mtab a symlink to /proc/mounts.===
+
===Make /etc/mtab a symlink to /proc/mounts===
  
 
<pre>
 
<pre>
 +
rm -f /vz/private/777/etc/mtab
 
ln -s /proc/mounts /vz/private/777/etc/mtab
 
ln -s /proc/mounts /vz/private/777/etc/mtab
 
</pre>
 
</pre>
  
===Editing /etc/fstab===
+
===Edit /etc/fstab===
  
 +
<pre>
 +
echo "proc /proc proc defaults 0 0" > /vz/private/777/etc/fstab
 +
</pre>
  
<pre>echo "proc /proc proc defaults 0 0" > /vz/private/777/etc/fstab</pre>
+
We need only <code>/proc</code> to mounted at the boot time.
We need only /proc to mounted at the boot time.
 
  
===Editing inittab===
+
===Edit inittab===
  
Edit /etc/inittab, put a hashmark (#) before the lines containing:
+
Edit <code>/etc/inittab</code>, putting a hashmark (#) before the lines containing:
  
 
<pre>c?:1235:respawn:/sbin/agetty 38400 tty? linux</pre>
 
<pre>c?:1235:respawn:/sbin/agetty 38400 tty? linux</pre>
  
This prevents from starting getty and login.
+
This prevents from starting <code>getty</code> and login.
  
===Editing /etc/shadow===
+
===Edit /etc/shadow===
  
Edit /vz/private/777/etc/shadow, change root's password in the first line to an exclamation mark (!):  
+
Edit <code>/vz/private/777/etc/shadow</code>, change root's password in the first line to an exclamation mark (!):  
  
 
<pre>root:!:10071:0:::::</pre>
 
<pre>root:!:10071:0:::::</pre>
  
This will disable the root login until the password changed with vzctl set 777 --userpasswd root:password.
+
This will disable the root login until the password changed with <code>vzctl set VEID --userpasswd root:password</code>.
 
 
  
===Editing /etc/init.d/checkroot===
+
===Edit /etc/init.d/checkroot===
  
 
We have to clean this script and make them dummy, because we don't need mount or check root.  
 
We have to clean this script and make them dummy, because we don't need mount or check root.  
Line 75: Line 76:
 
</pre>
 
</pre>
  
===Editing /sbin/rc===
+
===Edit /sbin/rc===
  
 
Comment line number 141:
 
Comment line number 141:
Line 81: Line 82:
 
<pre>try mount -n ${mntcmd:--t sysfs sysfs /sys}</pre>
 
<pre>try mount -n ${mntcmd:--t sysfs sysfs /sys}</pre>
  
This prevents from attepting to mount /sys.
+
This prevents from attepting to mount <code>/sys</code>.
  
===Setting up udev===
+
===Set up udev===
  
 
Delete /lib/udev-state/devices.tar.bz2 and create some device nodes needed to enter VPS:
 
Delete /lib/udev-state/devices.tar.bz2 and create some device nodes needed to enter VPS:
Line 94: Line 95:
 
</pre>
 
</pre>
  
===Testing===
+
===Test===
  
 
<pre>
 
<pre>
Line 113: Line 114:
 
</pre>
 
</pre>
  
===Making distfiles и portage of the host system available in VPS.===
+
===Make distfiles and portage tree of the host system available in a VE===
  
To install software into VPS with portage you should mount /usr/portage into VPS with "bind" option. Do this after VPS starts:
+
To install software into a VE with portage you should mount /usr/portage into VE with "bind" option. Do this after VE starts:
  
 
<pre>
 
<pre>
Line 128: Line 129:
 
</pre>
 
</pre>
  
Now, to install package into VPS you just need enter there by chroot or vzctl enter and
+
Now, to install package into a VE you just need enter there by <code>vzctl enter</code> and run
  
 
<pre>
 
<pre>
Line 134: Line 135:
 
</pre>
 
</pre>
  
while you have all needed files in the /usr/portage/distfiles of host system.
+
while you have all the needed files in the <code>/usr/portage/distfiles</code> of host system.
  
For security reasons hold this directories mounted only while you are installing software into VPS.
+
For security reasons hold this directories mounted only while you are installing software into a VE.
  
===Creating the cache file===
+
===Create the cache file===
  
 
<pre>
 
<pre>
Line 145: Line 146:
 
</pre>
 
</pre>
  
===Testing the new cache file===
+
===Test the new cache file===
  
 
<pre>
 
<pre>
Line 158: Line 159:
  
 
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!
 
If it started, and you can ssh in, congratulations, you've got a working Gentoo template!
 +
 +
[[Category: HOWTO]]
 +
[[Category: Templates]]

Revision as of 14:01, 27 July 2006

This page is about making a template cache for OpenVZ VE from Gentoo Linux. The method is basically the same as described in Slackware template creation article.

Download stage3

We shall make 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 VE and unarchive stage3

mkdir /vz/private/777
tar -xjf /root/stage3-i686-2006.0.tar.bz2 -C /vz/private/777

Create VE config

Now you need to create the configuration file for the VE, 777.conf:

vzctl set 777 --applyconfig vps.basic --save

Edit config

Add to the /etc/vz/conf/777.conf:

DISTRIBUTION="gentoo"
OSTEMPLATE="gentoo"

Make /etc/mtab a symlink to /proc/mounts

rm -f /vz/private/777/etc/mtab
ln -s /proc/mounts /vz/private/777/etc/mtab

Edit /etc/fstab

echo "proc /proc proc defaults 0 0" > /vz/private/777/etc/fstab

We need only /proc to mounted at the boot time.

Edit inittab

Edit /etc/inittab, putting a hashmark (#) before the lines containing:

c?:1235:respawn:/sbin/agetty 38400 tty? linux

This prevents from starting getty and login.

Edit /etc/shadow

Edit /vz/private/777/etc/shadow, change root's password in the first line to an exclamation mark (!):

root:!:10071:0:::::

This will disable the root login until the password changed with vzctl set VEID --userpasswd root:password.

Edit /etc/init.d/checkroot

We have to clean this script and make them dummy, because we don't need mount or check root.

cat > /etc/init.d/checkroot
#!/sbin/runscript
depend()
{
}
start()
{
}
end()
{
}

Edit /sbin/rc

Comment line number 141:

try mount -n ${mntcmd:--t sysfs sysfs /sys}

This prevents from attepting to mount /sys.

Set up udev

Delete /lib/udev-state/devices.tar.bz2 and create some device nodes needed to enter VPS:

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

Test

vzctl start 777
vzctl enter 777

You can check running services.

rc-status -a

All services in boot and default runlevels must be started. If everything all right, stop it

vzctl stop 777

Make distfiles and portage tree of the host system available in a VE

To install software into a VE with portage you should mount /usr/portage into VE with "bind" option. Do this after VE starts:

mkdir /vz/root/777/usr/portage
mount -o bind /usr/portage /vz/root/777/usr/portage

If your /usr/portage/distfiles placed on the other partition do:

mount -o bind /usr/portage/distfiles /vz/root/777/usr/portage/distfiles

Now, to install package into a VE you just need enter there by vzctl enter and run

emerge package_name

while you have all the needed files in the /usr/portage/distfiles of host system.

For security reasons hold this directories mounted only while you are installing software into a VE.

Create the cache file

cd /vz/private/777/
tar czf /vz/template/cache/gentoo.tar.gz *

Test the new cache file

vzctl create 800 --ostemplate gentoo --ipadd 192.168.0.10 --hostname testvps

If created successfully, try to start it:

vzctl start 800

If it started, and you can ssh in, congratulations, you've got a working Gentoo template!