Difference between revisions of "Kernel build"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
(added info on modifying kernel configs when using source-RPM)
m (fixed info on modifying kernel configs, corrected ksubrelease (may not contain "-" character))
Line 39: Line 39:
 
in appropriate places where similar text lines are.
 
in appropriate places where similar text lines are.
  
=== Modifying configs ===
+
=== Adjust kernel version ===
If you want to modify kernel configs, you need to do the changes via the kernel spec file. Insert your modifications after the following part of the spec file:
 
<pre>
 
# now run oldconfig over all the config files
 
for i in *.config*
 
do
 
        mv $i .config
 
</pre>
 
You can add kernel settings for example in the following way:
 
<pre>
 
        echo "YOUR_KERNEL_OPTION=m" >> .config
 
</pre>
 
If you try to modify the config files directly (not through the spec file), running rpmbuild will fail with the following error:
 
<pre>
 
make[1]: *** [nonint_oldconfig] Error 1
 
make: *** [nonint_oldconfig] Error 2
 
</pre>
 
Some information on this can be found in the following thread:  http://www.redhat.com/archives/fedora-list/2005-October/msg00921.html
 
 
 
=== Building RPMs ===
 
 
Before rebuilding the kernel make sure that you adjusted the kernel version in <code>kernel-ovz.spec</code>.
 
Before rebuilding the kernel make sure that you adjusted the kernel version in <code>kernel-ovz.spec</code>.
 
This will help you to distinguish binaries then from already existing kernels
 
This will help you to distinguish binaries then from already existing kernels
Line 67: Line 48:
 
with something like
 
with something like
 
<pre>
 
<pre>
%define ksubrelease 1-my.kernel.v1
+
%define ksubrelease 1my.kernel.v1
 
</pre>
 
</pre>
  
 +
=== Modifying configs ===
 +
If you want to modify the kernel config, you need to do the following before you continue with the next step "Building RPMs".
 +
<pre>
 +
# cd $TOPDIR/SPECS
 +
# rpmbuild -bp kernel-ovz.spec
 +
# cd $TOPDIR/BUILD/kernel-2.6.16/linux-2.6.16
 +
</pre>
 +
There you will find the configuration files in the subdirectory <code>config/*.config</code>. Copy the one you want to modifiy to <code>$TOPDIR/BUILD/kernel-2.6.16/linux-2.6.16/.config</code>. Then you can do a make menuconfig or something similar to adjust the kernel configuration. Afterwards copy
 +
<code>$TOPDIR/BUILD/kernel-2.6.16/linux-2.6.16/.config</code> to the <code>$TOPDIR/SOURCES</code> directory, but use the corresponding file name in the target directory.
 +
Some background information on this procedure can be found in the following thread:  http://www.arcknowledge.com/gmane.comp.audio.planetccrma.general/2004-11/msg00018.html
  
 +
=== Building RPMs ===
 
To rebuild the kernel, type the following commands:
 
To rebuild the kernel, type the following commands:
 
<pre>
 
<pre>

Revision as of 13:45, 19 February 2007

This FAQ will help you in case you want to apply some patches to the kernel on your own or rebuild it from sources. On RPM based distros such as RedHat Enterprise Linux/CentOS, Fedora Core or SUSE one can simpy rebuild kernel from SRPM. For other distros it is required to install sources, build and install kernel manually. The below are given the details for both cases.

Rebuilding kernel from SRPM

Note: some of the paths below include $TOPDIR, which is distribution-dependent and can be further redefined by user. To find out the proper location on your system, issue this command:

rpm --eval "%{_topdir}"

Download

Source RPMS for different OpenVZ kernel branches can be downloaded from http://openvz.org/download/kernel/. You can also access http://download.openvz.org/kernel/ directly, or use one of the mirrors.

Installation

Install the downloaded SRC RPM with the following command:

# rpm -ihv ovzkernel-2.6.16-026test018.1.src.rpm

After successfull installation, you can usually find kernel sources in $TOPDIR/SOURCES/ and kernel spec file (kernel-ovz.spec) in $TOPDIR/SPECS.

Adding your own patches

To modify the kernel one needs just to add specific patches to the kernel spec file and put this patch into $TOPDIR/SOURCES directory.

Put your patch into SOURCES directory with the following command:

# cp <patch> $TOPDIR/SOURCES/

Then open spec file $TOPDIR/SPECS/kernel-ovz.spec in the editor and add the following lines:

Patch10000: <patch-name>

and

%patch10000 -p1

in appropriate places where similar text lines are.

Adjust kernel version

Before rebuilding the kernel make sure that you adjusted the kernel version in kernel-ovz.spec. This will help you to distinguish binaries then from already existing kernels (or from the official OpenVZ kernels). To do so, edit the $TOPDIR/SPECS/kernel-ovz.spec file and replace the following line:

%define ksubrelease 1

with something like

%define ksubrelease 1my.kernel.v1

Modifying configs

If you want to modify the kernel config, you need to do the following before you continue with the next step "Building RPMs".

# cd $TOPDIR/SPECS
# rpmbuild -bp kernel-ovz.spec
# cd $TOPDIR/BUILD/kernel-2.6.16/linux-2.6.16

There you will find the configuration files in the subdirectory config/*.config. Copy the one you want to modifiy to $TOPDIR/BUILD/kernel-2.6.16/linux-2.6.16/.config. Then you can do a make menuconfig or something similar to adjust the kernel configuration. Afterwards copy $TOPDIR/BUILD/kernel-2.6.16/linux-2.6.16/.config to the $TOPDIR/SOURCES directory, but use the corresponding file name in the target directory. Some background information on this procedure can be found in the following thread: http://www.arcknowledge.com/gmane.comp.audio.planetccrma.general/2004-11/msg00018.html

Building RPMs

To rebuild the kernel, type the following commands:

# cd $TOPDIR/SPECS
# rpmbuild -ba --target=i686 kernel-ovz.spec

After successfull kernel compilation binary RPMs can be found at $TOPDIR/RPMS/i686.

Rebuilding kernel from sources

Download

To compile OpenVZ linux kernel one need to download the original linux kernel sources and OpenVZ patches for it.

Linux kernel can be found at kernel.org, e.g. 2.6.16 kernel can be downloaded from linux-2.6.16.tar.bz2.

Appropriate OpenVZ patches for this kernel version can be found at http://openvz.org/download/kernel/<version>/patches/. For example, at the moment there is a patch patch-026test018-combined.gz available.

Kernel configs are also available at OpenVZ download site. Most frequently SMP config is used, so let's download kernel-2.6.16-026test018-i686-smp.config.ovz for this example.

Building

First, extract the kernel sources from archive:

# tar vjxf linux-2.6.16.tar.bz2
# cd linux-2.6.16

Apply OpenVZ patches to the kernel:

# gzip -dc patch-026test018-combined.gz | patch -p1

Now we need to place the config and build the kernel:

# cp kernel-2.6.16-026test018-i686-smp.config.ovz .config
# make oldconfig
# make
# make modules

Installation

After successfull build of kernel it can be installed on the machine with the following commands run under root user:

# make install
# make modules_install

Also you need to edit your GRUB or LILO config to make your kernel available for boot.