172
edits
Changes
Initial edition - not finished
This article is a step by step guide explaining how to add OpenVZ functionality to Centos 4.4 LiveCD.
As a result, you will have a LiveCD, that can boot in various OpenVZ kernels (rhel4-2.6.9, 2.6.18,
rhel5-2.6.18, 2.6.20) and in original CentOS kernel also. After booting from CD, you will be able
to create [[VE]]s, start them, enter them - i.e. perform [[Getting started with OpenVZ live CD | common OpenVZ activity]].
CentOS 5 LiveCD is already announced and as soon as it will be available we'll update the article.
== General actions ==
It is quite easy to add OpenVZ functionality to existent LiveCD. The most difficult work is already done
by the original LiveCD creators. But it requires pretty much hand job. Probably some day some good guy will
automatize this process. ;)
Actually you need to know the following general actions: everything else is only technical details.
* Get a copy of CentOS 4.4 LiveCD iso image
* Add <tt>squashfs</tt> support to your kernel (TODO: use unsquashfs instead)
* Extract the contents of *.mo files from CD using <tt>squashfs</tt> and construct LiveCD root filesystem.
* Compile OpenVZ kernels with <tt>squashfs</tt> and <tt>unionfs</tt> support
* Get OpenVZ user-space tools: vzctl, vzquota, vzpkg, ... and some precreated templates.
* Install OpenVZ kernel, tools and templates in LiveCD root filesystem
* Remove some packages from LiveCD root filesystem
* Modify initrd image: add there kernel modules for OpenVZ kernels
* Introduce some small changes to isolinux configuration file
* Create new iso image
== Technical details ==
This part contents detailed description of LiveCD creation. I've removed the output of some
commands in order to simplify the reading.
=== Creating booted LiveCD root filesystem ===
Create a directory, that will be our "workbench":
<pre>
# cd ~
# mkdir workbench
# cd workbench
</pre>
First of all we need some raw material - CentOS 4.4 LiveCD:
<pre>
# wget http://mirror.nsc.liu.se/CentOS/4.4/isos/i386/CentOS-4.4-i386-LiveCD.iso
# wget http://mirror.nsc.liu.se/CentOS/4.4/isos/i386/md5sum.livecd
# md5sum --check md5sum.livecd
CentOS-4.4-i386-LiveCD.iso: OK
</pre>
Copy the contents of CD to the directory, where we will form the OpenVZ LiveCD filesystem.
I named this directory "ovz-livecd":
<pre>
# mkdir ovz-livecd
# mkdir mount
# mount -o loop -t iso9660 CentOS-4.4-i386-LiveCD.iso mount/
# cp -a mount/* ovz-livecd/
# umount mount
# rm -rf mount
</pre>
You can see, that <tt>ovz-livecd/base/</tt> directory owns several *.mo files - images of squashfs filesystem,
and each image holds one directory of LiveCD root filesystem: <tt>bin</tt>, <tt>usr</tt> and so on:
<pre>
# ls -1 ovz-livecd/base
bin.mo etc.mo lib.mo root.mo sbin.mo usr.mo var.mo
</pre>
In order to decompress these images we need <tt>squashfs</tt> tools. The source archive of <tt>squashfs</tt> contents
patch for the kernel (to be able mount <tt>squashfs</tt>), and user-space tools for compressing/decomprassing usual filesytem
into squashfs filesystem. Well, we don't need the kernel patch right now (but we will need it later), we only want to install <tt>squashfs</tt> user-space tools:
<pre>
# wget wget http://switch.dl.sourceforge.net/sourceforge/squashfs/squashfs3.2-r2.tar.gz
# tar xzf squashfs3.2-r2.tar.gz
# cd squashfs3.2-r2/squashfs-tools/
# make
cc mksquashfs.o read_fs.o sort.o -lz -lpthread -lm -o mksquashfs
cc unsquashfs.o -lz -o unsquashfs
# cp mksquashfs /usr/bin/
# cp unsquashfs /usr/bin/
# cd ~/workbench
</pre>
Well, having the intruments in hand, why not extract the images? Create a directory, called <tt>livecd-root</tt>,
that will store the root filesystem for '''booted''' LiveCD. I.e. it will content <tt>/bin</tt>, <tt>/sbin</tt>,
<tt>/etc</tt> and other directories, which you will see after booting the LiveCD. Unfortunately <tt>unsquashfs</tt>
tool is not very convenient, and I found only this way to use it:
<pre>
# mkdir livecd-root
# unsquashfs ovz-livecd/base/bin.mo
# mv squashfs-root/bin/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/etc.mo
# mv squashfs-root/etc/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/lib.mo
# mv squashfs-root/lib/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/root.mo
# mv squashfs-root/root/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/sbin.mo
# mv squashfs-root/sbin/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/usr.mo # this action takes some time, be patient ;)
# mv squashfs-root/usr/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/var.mo
# mv squashfs-root/var/ livecd-root/
# rm -rf squashfs-root
</pre>
Yet we have nearly complete root filesystem of booted LiveCD in <tt>livecd-root</tt> directory. However some things
are missing, and I guess you know what are they: <tt>/dev</tt>, <tt>/proc</tt>, <tt>/sys</tt>, <tt>/tmp</tt> and <tt>/boot</tt> directories. We need them, because some tools (<tt>rpm</tt>, <tt>bash</tt>,...) will not work without them in chrooted environment later.
<pre>
# mkdir root/dev
# cp -a /dev/* root/dev
# mkdir root/proc
# mount -t proc proc root/proc/
# mkdir root/sys
# mount -t sysfs sysfs root/sys/
# mkdir root/tmp
# mkdir root/boot
</pre>
That's it. We have booted LiveCD root filesystem in <tt>livecd-root</tt> directory.
Now we can <tt>chroot</tt> in this directory and install all needed packages. But what
packages do we need?
* OpenVZ kernel
* OpenVZ tools: vzctl, vzquota, vzpkg, vzrpm43, vzrpm44, vzyum
* OpenVZ template metadatas: centos-4, fc-3, fc4 and fc-5
* Some OpenVZ precreated templates
* Some CentOS tools updates: sqlite package
Tools and templates related packages can be simply downloaded and installed.
But it is not so easy with kernel. Usual OpenVZ kernel won't work: it doesn't
support <tt>squashfs</tt>. The next chapter explains how to create RPM package with
OpenVZ kernel, that supports <tt>squashfs</tt>
=== Building OpenVZ kernels and kernel modules ===
To be continued...
=== Obrezki ===
TODO
rpms/
rpms/kernel
rpms/tools
rpms/update
Uninstall <tt>lsctp-tools</tt> package, because these tools they need kernel version prior to 2.6.10:
<pre>
rpm -e lksctp-tools-1.0.2-6.4E.1.i386
</pre>
Uninstall kernel-module-xfs package, because these modules are compiled against original
<pre>
rpm -e kernel-module-xfs-2.6.9-42.livecd.c4-0.1-3.i686
</pre>
cd /tmp/rpms/kernel
rpm -ivh kernel-smp-2.6.18-ovz028stab033.1.i686.rpm
rpm -e kernel-2.6.9-42.livecd.c4
cd /tmp/rpms/updates
rpm -Uvh sqlite-3.3.6-2.i386.rpm
<tt>
# rpm -ivh vz*
Preparing... ########################################### [100%]
1:vzrpm44 ########################################### [ 8%]
2:vzrpm44-python ########################################### [ 15%]
3:vzrpm43-python ########################################### [ 23%]
4:vzrpm43 ########################################### [ 31%]
5:vzyum ########################################### [ 38%]
6:vzquota ########################################### [ 46%]
7:vzctl-lib ########################################### [ 54%]
8:vzctl ########################################### [ 62%]
9:vzpkg ########################################### [ 69%]
10:vztmpl-centos-4 ########################################### [ 77%]
11:vztmpl-fedora-core-3 ########################################### [ 85%]
12:vztmpl-fedora-core-4 ########################################### [ 92%]
13:vztmpl-fedora-core-5 ########################################### [100%]
</tt>
== External Links ==
* [http://centos.org Official CentOS community website]
* [http://kernel.org Linux kernel website]
* [http://redhat.com RedHat Inc. website]
* [http://squashfs.sourceforge.net/ squashfs website]
* [http://www.filesystems.org/project-unionfs.html uninonfs official homepage]
As a result, you will have a LiveCD, that can boot in various OpenVZ kernels (rhel4-2.6.9, 2.6.18,
rhel5-2.6.18, 2.6.20) and in original CentOS kernel also. After booting from CD, you will be able
to create [[VE]]s, start them, enter them - i.e. perform [[Getting started with OpenVZ live CD | common OpenVZ activity]].
CentOS 5 LiveCD is already announced and as soon as it will be available we'll update the article.
== General actions ==
It is quite easy to add OpenVZ functionality to existent LiveCD. The most difficult work is already done
by the original LiveCD creators. But it requires pretty much hand job. Probably some day some good guy will
automatize this process. ;)
Actually you need to know the following general actions: everything else is only technical details.
* Get a copy of CentOS 4.4 LiveCD iso image
* Add <tt>squashfs</tt> support to your kernel (TODO: use unsquashfs instead)
* Extract the contents of *.mo files from CD using <tt>squashfs</tt> and construct LiveCD root filesystem.
* Compile OpenVZ kernels with <tt>squashfs</tt> and <tt>unionfs</tt> support
* Get OpenVZ user-space tools: vzctl, vzquota, vzpkg, ... and some precreated templates.
* Install OpenVZ kernel, tools and templates in LiveCD root filesystem
* Remove some packages from LiveCD root filesystem
* Modify initrd image: add there kernel modules for OpenVZ kernels
* Introduce some small changes to isolinux configuration file
* Create new iso image
== Technical details ==
This part contents detailed description of LiveCD creation. I've removed the output of some
commands in order to simplify the reading.
=== Creating booted LiveCD root filesystem ===
Create a directory, that will be our "workbench":
<pre>
# cd ~
# mkdir workbench
# cd workbench
</pre>
First of all we need some raw material - CentOS 4.4 LiveCD:
<pre>
# wget http://mirror.nsc.liu.se/CentOS/4.4/isos/i386/CentOS-4.4-i386-LiveCD.iso
# wget http://mirror.nsc.liu.se/CentOS/4.4/isos/i386/md5sum.livecd
# md5sum --check md5sum.livecd
CentOS-4.4-i386-LiveCD.iso: OK
</pre>
Copy the contents of CD to the directory, where we will form the OpenVZ LiveCD filesystem.
I named this directory "ovz-livecd":
<pre>
# mkdir ovz-livecd
# mkdir mount
# mount -o loop -t iso9660 CentOS-4.4-i386-LiveCD.iso mount/
# cp -a mount/* ovz-livecd/
# umount mount
# rm -rf mount
</pre>
You can see, that <tt>ovz-livecd/base/</tt> directory owns several *.mo files - images of squashfs filesystem,
and each image holds one directory of LiveCD root filesystem: <tt>bin</tt>, <tt>usr</tt> and so on:
<pre>
# ls -1 ovz-livecd/base
bin.mo etc.mo lib.mo root.mo sbin.mo usr.mo var.mo
</pre>
In order to decompress these images we need <tt>squashfs</tt> tools. The source archive of <tt>squashfs</tt> contents
patch for the kernel (to be able mount <tt>squashfs</tt>), and user-space tools for compressing/decomprassing usual filesytem
into squashfs filesystem. Well, we don't need the kernel patch right now (but we will need it later), we only want to install <tt>squashfs</tt> user-space tools:
<pre>
# wget wget http://switch.dl.sourceforge.net/sourceforge/squashfs/squashfs3.2-r2.tar.gz
# tar xzf squashfs3.2-r2.tar.gz
# cd squashfs3.2-r2/squashfs-tools/
# make
cc mksquashfs.o read_fs.o sort.o -lz -lpthread -lm -o mksquashfs
cc unsquashfs.o -lz -o unsquashfs
# cp mksquashfs /usr/bin/
# cp unsquashfs /usr/bin/
# cd ~/workbench
</pre>
Well, having the intruments in hand, why not extract the images? Create a directory, called <tt>livecd-root</tt>,
that will store the root filesystem for '''booted''' LiveCD. I.e. it will content <tt>/bin</tt>, <tt>/sbin</tt>,
<tt>/etc</tt> and other directories, which you will see after booting the LiveCD. Unfortunately <tt>unsquashfs</tt>
tool is not very convenient, and I found only this way to use it:
<pre>
# mkdir livecd-root
# unsquashfs ovz-livecd/base/bin.mo
# mv squashfs-root/bin/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/etc.mo
# mv squashfs-root/etc/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/lib.mo
# mv squashfs-root/lib/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/root.mo
# mv squashfs-root/root/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/sbin.mo
# mv squashfs-root/sbin/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/usr.mo # this action takes some time, be patient ;)
# mv squashfs-root/usr/ livecd-root/
# rm -rf squashfs-root
# unsquashfs ovz-livecd/base/var.mo
# mv squashfs-root/var/ livecd-root/
# rm -rf squashfs-root
</pre>
Yet we have nearly complete root filesystem of booted LiveCD in <tt>livecd-root</tt> directory. However some things
are missing, and I guess you know what are they: <tt>/dev</tt>, <tt>/proc</tt>, <tt>/sys</tt>, <tt>/tmp</tt> and <tt>/boot</tt> directories. We need them, because some tools (<tt>rpm</tt>, <tt>bash</tt>,...) will not work without them in chrooted environment later.
<pre>
# mkdir root/dev
# cp -a /dev/* root/dev
# mkdir root/proc
# mount -t proc proc root/proc/
# mkdir root/sys
# mount -t sysfs sysfs root/sys/
# mkdir root/tmp
# mkdir root/boot
</pre>
That's it. We have booted LiveCD root filesystem in <tt>livecd-root</tt> directory.
Now we can <tt>chroot</tt> in this directory and install all needed packages. But what
packages do we need?
* OpenVZ kernel
* OpenVZ tools: vzctl, vzquota, vzpkg, vzrpm43, vzrpm44, vzyum
* OpenVZ template metadatas: centos-4, fc-3, fc4 and fc-5
* Some OpenVZ precreated templates
* Some CentOS tools updates: sqlite package
Tools and templates related packages can be simply downloaded and installed.
But it is not so easy with kernel. Usual OpenVZ kernel won't work: it doesn't
support <tt>squashfs</tt>. The next chapter explains how to create RPM package with
OpenVZ kernel, that supports <tt>squashfs</tt>
=== Building OpenVZ kernels and kernel modules ===
To be continued...
=== Obrezki ===
TODO
rpms/
rpms/kernel
rpms/tools
rpms/update
Uninstall <tt>lsctp-tools</tt> package, because these tools they need kernel version prior to 2.6.10:
<pre>
rpm -e lksctp-tools-1.0.2-6.4E.1.i386
</pre>
Uninstall kernel-module-xfs package, because these modules are compiled against original
<pre>
rpm -e kernel-module-xfs-2.6.9-42.livecd.c4-0.1-3.i686
</pre>
cd /tmp/rpms/kernel
rpm -ivh kernel-smp-2.6.18-ovz028stab033.1.i686.rpm
rpm -e kernel-2.6.9-42.livecd.c4
cd /tmp/rpms/updates
rpm -Uvh sqlite-3.3.6-2.i386.rpm
<tt>
# rpm -ivh vz*
Preparing... ########################################### [100%]
1:vzrpm44 ########################################### [ 8%]
2:vzrpm44-python ########################################### [ 15%]
3:vzrpm43-python ########################################### [ 23%]
4:vzrpm43 ########################################### [ 31%]
5:vzyum ########################################### [ 38%]
6:vzquota ########################################### [ 46%]
7:vzctl-lib ########################################### [ 54%]
8:vzctl ########################################### [ 62%]
9:vzpkg ########################################### [ 69%]
10:vztmpl-centos-4 ########################################### [ 77%]
11:vztmpl-fedora-core-3 ########################################### [ 85%]
12:vztmpl-fedora-core-4 ########################################### [ 92%]
13:vztmpl-fedora-core-5 ########################################### [100%]
</tt>
== External Links ==
* [http://centos.org Official CentOS community website]
* [http://kernel.org Linux kernel website]
* [http://redhat.com RedHat Inc. website]
* [http://squashfs.sourceforge.net/ squashfs website]
* [http://www.filesystems.org/project-unionfs.html uninonfs official homepage]