Changes

Jump to: navigation, search

Creating OpenVZ LiveCD based on Centos 4.4

1,838 bytes added, 14:54, 28 June 2007
additional information and fixes
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 the 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]].
automatize this process. ;)
Actually you need to know accomplish the following general actions - everything else is only technical details:* Get a copy of CentOS 4.4 LiveCD iso image * Use <tt>unsquashfs</tt> tool to extract the contents of *.mo files from CD and construct , located on the image* Construct '''booted ''' LiveCD root filesystem from extracted files* Create OpenVZ kernel RPM-packages with <tt>squashfs</tt> and support* Compile <tt>unionfs</tt> supportkernel modules against OpenVZ kernels* Get OpenVZ usertools RPM-space tools packages: vzctl, vzquota, vzpkg, etc... Get template metadatas and some precreated templates* Remove some RPM-packages from '''booted ''' LiveCD root filesystem (conflicting with OpenVZ kernel packages and unnecessary redundant packages - to free some disk space)* Install OpenVZ kernels, tools and templates in '''booted''' LiveCD root filesystem* Using <tt>mksquashfs</tt> tool compress '''booted ''' CD root filesystem
* Modify initrd image: add there kernel modules for OpenVZ kernels
* Introduce small modifications to isolinux configuration file
== Technical details ==
This part contents contains detailed description of LiveCD creation. I've removed the output of some
commands in order to simplify the reading.
</pre>
First of all we need some raw material - CentOS 4.4 LiveCDimage:
<pre>
# wget http://mirror.nsc.liu.se/CentOS/4.4/isos/i386/CentOS-4.4-i386-LiveCD.iso
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 '''booted ''' LiveCD root filesystem: <tt>bin</tt>, <tt>usr</tt> and so on:
<pre>
# ls -1 ovz-livecd/base
</pre>
In order to decompress these images we need <tt>squashfsunsquashfs</tt> toolstool. The source archive of <tt>squashfs</tt> contentssource archive containspatch patches for the various kernel versions (to be able mount <tt>squashfs</tt>), and user-space tools for compressing/decomprassing usual filesyteminto <tt>squashfs </tt> filesystemand for decompressing it back. Well, we don't need the kernel patch patches right now (but we will need it them 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
</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 of '''booted ''' LiveCD. I.e. it will content contain <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:
# 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>
</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 template metadatas: centos-4, fc-3, fc4 and fc-5
* Some OpenVZ precreated templates
* Some CentOS tools tool 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 ===
Let's consider, how to build <tt>2.6.18</tt> OpenVZ kernel RPM -package with <tt>squashfs </tt> support.
First download and install OpenVZ source RPM:
<pre>
# wget http://download.openvz.org/kernel/branches/2.6.18/028stab033028stab035.1/kernel-2.6.18-ovz028stab033ovz028stab035.1.src.rpm# rpm -ivh kernel-2.6.18-ovz028stab033ovz028stab035.1.src.rpm
</pre>
<tt>squashfs</tt> sources content contain the patch against <tt>2.6.18</tt>. Let's copy this patch to RPM build directory:
<pre>
# cp squashfs3.2-r2/kernel-patches/linux-2.6.18/squashfs3.2-patch /usr/src/redhat/SOURCES/
</pre>
Now we need to modify the spec-file (<tt>/usr/src/redhat/SPECS/kernel-ovz.spec</tt>) in order to add <tt>squashfs</tt> patch to build process. Below is are the changes you should add introduce in diff-based format.The meaning of changes is transparent:firstly, do not build UP, enterprise and debug kernels (our LiveCD will bebased on SMP kernel) and secondly, apply <tt>squashfs</tt> patch before compilation.
<pre>
--- kernel-ovz.spec.orig 2007-06-09 11:40:15.000000000 +0400
+++ kernel-ovz.spec 2007-06-28 17:42:41.000000000 +0400
@@ -5,13 +5,13 @@ Summary: The Linux kernel (the core of t
Patch2106: linux-2.6.18-drbd-8.0.2-8.0.3.patch
+# squashfssquashfs3.2-patch
+Patch2107: squashfs3.2-patch
+
+
# ----------------------------------------------------------------------------
 
mkdir configs
</pre>
We need one more tiny hack in order RPM-build process to walk smoothly.
There are config files for various OpenVZ kernel flavours
in <tt>/usr/src/redhat/SOURCES</tt> directory:
<pre>
# ls /usr/src/redhat/SOURCES/*.config.ovz
/usr/src/redhat/SOURCES/kernel-2.6.18-i686.config.ovz /usr/src/redhat/SOURCES/kernel-2.6.18-ppc64.config.ovz
/usr/src/redhat/SOURCES/kernel-2.6.18-i686-enterprise.config.ovz /usr/src/redhat/SOURCES/kernel-2.6.18-x86_64.config.ovz
/usr/src/redhat/SOURCES/kernel-2.6.18-i686-smp.config.ovz /usr/src/redhat/SOURCES/kernel-2.6.18-x86_64-smp.config.ovz
/usr/src/redhat/SOURCES/kernel-2.6.18-ia64.config.ovz
</pre>
'''All''' these files should contain information about <tt>squashfs</tt>.
In fact, only two additional lines are necessary:
<pre>
CONFIG_SQUASHFS=m
CONFIG_SQUASHFS_EMBEDDED=n
</pre>
I did it with the following command:
<pre>
# cd /usr/src/redhat/SOURCES/
# echo "CONFIG_SQUASHFS=m
> CONFIG_SQUASHFS_EMBEDDED=n" | tee -a *.config.ovz
CONFIG_SQUASHFS=m
CONFIG_SQUASHFS_EMBEDDED=n
# cd $OLDPWD
</pre>
Building After all efforts building the RPM-package is very easy:
<pre>
# rpmbuild --target=i686 -ba kernel-ovz.spec
</pre>
If everything goes oksmoothly, then in several tens of minutes depending on the power of your node you will willl have a ready rpm OpenVZ kernelRPM-package with <tt>squashfs</tt> support:
<pre>
# ls -l
</pre>
=== Unionfs kernel module === === Installing RPMs ===
We have the RPM package for the kernel. But we also need
<pre>
172
edits

Navigation menu