Difference between revisions of "Kernel build"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
(Marked this version for translation)
 
(34 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
<translate>
 +
<!--T:1-->
 
This FAQ will help you in case you want to apply some patches to the kernel on your own or rebuild it from sources.
 
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,
+
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.
+
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 ==
+
== Rebuilding kernel from SRPM == <!--T:2-->
  
=== Download ===
+
=== Find out $TOPDIR === <!--T:3-->
OpenVZ kernel SRC RPM can be download from the official downloads at http://openvz.org/download/kernel/.
+
'''Note''': paths in some of the commands below include $TOPDIR, which is distribution-dependent and can be further redefined by user. To find out the proper location of $TOPDIR on your system, issue this command:
Beta versions of kernels for different OS distributions can be also found at http://openvz.org/download/beta/.
 
  
=== Installation ===
+
<!--T:4-->
 +
TOPDIR=$(rpm --eval "%{_topdir}"); echo $TOPDIR
 +
 
 +
=== Download === <!--T:5-->
 +
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 [[download mirrors|mirrors]].
 +
 
 +
=== Installation === <!--T:6-->
 
Install the downloaded SRC RPM with the following command:
 
Install the downloaded SRC RPM with the following command:
<pre>
 
# rpm -ihv ovzkernel-2.6.16-026test012.1.src.rpm
 
</pre>
 
  
After successfull installation you can find kernel sources in /usr/src/<distro>/SOURCES/
+
<!--T:7-->
and kernel spec file (kernel-ovz.spec) in /usr/src/<distro>/SPECS, where <distro> is your distribution-specific directory.
+
# rpm -ihv ovzkernel-{{kver}}-{{krel}}.src.rpm
For example, for RedHat based distros it is 'redhat', for SUSE it is 'packages'.
 
  
=== Adding your own patches ===
+
<!--T:8-->
To modify the kernel one needs just to add specific patches to the kernel spec file and put this patch into SOURCES directory.
+
After successfull installation, you can usually find kernel sources in <code>$TOPDIR/SOURCES/</code>
 +
and kernel spec file (<code>kernel-ovz.spec</code>) in <code>$TOPDIR/SPECS</code>.
 +
 
 +
=== Adding your own patches === <!--T:9-->
 +
To modify the kernel one needs just to add specific patches to the kernel spec file and put this patch into <code>$TOPDIR/SOURCES</code> directory.
 +
 
 +
<!--T:10-->
 
Put your patch into SOURCES directory with the following command:
 
Put your patch into SOURCES directory with the following command:
<pre>
 
# cp <patch> /usr/src/<distro>/SOURCES/
 
</pre>
 
  
Then open spec file /usr/src/<distro>/SPECS/kernel-ovz.spec in the editor and add the following lines:
+
<!--T:11-->
<pre>
+
# cp <patch> $TOPDIR/SOURCES/
Patch10000: <patch-name>
+
 
</pre>
+
<!--T:12-->
 +
Then open spec file <code>$TOPDIR/SPECS/kernel-ovz.spec</code> in the editor and add the following lines:
 +
 
 +
<!--T:13-->
 +
Patch100000: <patch-name>
 +
 
 +
<!--T:14-->
 
and
 
and
<pre>
+
 
%patch10000 -p1
+
<!--T:15-->
</pre>
+
%patch100000 -p1
 +
 
 +
<!--T:16-->
 
in appropriate places where similar text lines are.
 
in appropriate places where similar text lines are.
  
=== Building RPMs ===
+
=== Adjust kernel version === <!--T:17-->
Before rebuilding the kernel make sure that you adjusted the kernel version in kernel-ovz.spec.
+
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
(or from official OpenVZ kernels). To do so, edit /usr/src/<distro>/SPECS/kernel-ovz.spec file and replace the following line:
+
(or from the official OpenVZ kernels). To do so, edit the <code>$TOPDIR/SPECS/kernel-ovz.spec</code> file and replace the following line:
<pre>
+
 
 +
<!--T:18-->
 
%define ksubrelease 1
 
%define ksubrelease 1
</pre>
 
with
 
<pre>
 
%define ksubrelease 1-my.kernel.v1
 
</pre>
 
  
 +
<!--T:19-->
 +
with something like
 +
 +
<!--T:20-->
 +
%define ksubrelease 1my.kernel.v1
 +
 +
=== Modifying configs === <!--T:21-->
 +
If you want to modify the kernel config, you need to do the following before you continue with [[#Building RPMs|the next step]].
 +
 +
<!--T:22-->
 +
# cd $TOPDIR/SPECS
 +
# rpmbuild -bp kernel-ovz.spec
 +
# cd $TOPDIR/BUILD/kernel-{{kver}}/linux-{{kver}}
 +
 +
<!--T:23-->
 +
'''Note''': Make sure all OpenVZ related options are set. See [[kernel configuration]]
 +
 +
<!--T:24-->
 +
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-{{kver}}/linux-{{kver}}/.config</code>. Then you can do a make menuconfig or something similar to adjust the kernel configuration. Note that some kernel configuration issues are described at [[kernel configuration]].
 +
 +
<!--T:25-->
 +
Next, copy <code>$TOPDIR/BUILD/kernel-{{kver}}/linux-{{kver}}/.config</code> to the <code>$TOPDIR/SOURCES</code> directory, but use the corresponding file name in the target directory.
 +
 +
=== Building RPMs === <!--T:26-->
 +
To rebuild the kernel, type the following commands:
 +
 +
<!--T:27-->
 +
# cd $TOPDIR/SPECS
 +
# rpmbuild -ba --target=i686 kernel-ovz.spec
 +
 +
<!--T:28-->
 +
After successfull kernel compilation binary RPMs can be found at <code>$TOPDIR/RPMS/i686</code>.
 +
 +
== Rebuilding kernel from sources == <!--T:29-->
 +
 +
=== Download === <!--T:30-->
 +
To compile OpenVZ linux kernel one need to download the original linux kernel sources and OpenVZ patches for it.
 +
 +
<!--T:31-->
 +
Linux kernel can be found at [http://www.kernel.org/ kernel.org], e.g. {{kver}} kernel can be downloaded [http://www.kernel.org/pub/linux/kernel/v2.6/linux-{{kver}}.tar.bz2 from here].
 +
 +
<!--T:32-->
 +
Appropriate OpenVZ patches for this kernel version can be found at <nowiki>http://openvz.org/download/kernel/branches/<branch>/<version>/patches/</nowiki>. For example, at the moment there is a patch [http://download.openvz.org/kernel/branches/{{kver}}/{{krel}}/patches/patch-ovz{{krel}}-combined.gz patch-ovz{{krel}}-combined.gz] available.
 +
 +
<!--T:33-->
 +
Kernel configs are also available at OpenVZ download site. Most frequently SMP config is used, so let's download [http://download.openvz.org/kernel/branches/{{kver}}/{{krel}}/configs/kernel-{{kver}}-i686-smp.config.ovz kernel-{{kver}}-i686-smp.config.ovz]
 +
for this example.
 +
 +
=== Prepare === <!--T:34-->
 +
First, extract the kernel sources from archive:
 +
 +
<!--T:35-->
 +
# tar vjxf linux-{{kver}}.tar.bz2
 +
# cd linux-{{kver}}
 +
 +
<!--T:36-->
 +
Apply OpenVZ patches to the kernel:
 +
 +
<!--T:37-->
 +
# gzip -dc patch-ovz{{krel}}-combined.gz | patch -p1
 +
 +
=== Configure === <!--T:38-->
 +
Now we need to place the config and build the kernel:
 +
 +
<!--T:39-->
 +
# cp kernel-{{kver}}-i686-smp.config.ovz .config
 +
# make oldconfig
 +
 +
<!--T:40-->
 +
On this stage, you can modify your kernel configuration to better suit your needs.
 +
 +
<!--T:41-->
 +
{{Note|Make sure all OpenVZ related options are set. See [[kernel configuration]].}}
 +
 +
=== Build === <!--T:42-->
 +
# make
 +
# make modules
  
To rebuild the kernel type the following commands then:
+
=== Installation === <!--T:43-->
<pre>
+
After a successful build of the kernel it can be installed on the machine with the following commands run under '''root''' user:
# cd /usr/src/<distro>/SPECS
 
# rpmbuild -ba --target=i686 kernel-ovz.spec
 
</pre>
 
  
After successfull kernel compilation binary RPMs can be found at /usr/src/<distro>/RPMS/i686
+
<!--T:44-->
 +
# make install
 +
# make modules_install
  
== Rebuilding kernel from sources ==
+
<!--T:45-->
 +
Also you need to edit your GRUB or LILO config to make your kernel available for boot.
 +
</translate>
  
FIXME
+
[[Category: HOWTO]]
 +
[[Category: Kernel]]
 +
[[Category: Installation]]

Latest revision as of 08:40, 26 December 2015

<translate> 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[edit]

Find out $TOPDIR[edit]

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

TOPDIR=$(rpm --eval "%{_topdir}"); echo $TOPDIR

Download[edit]

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[edit]

Install the downloaded SRC RPM with the following command:

  1. rpm -ihv ovzkernel-2.6.18-028stab056.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[edit]

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:

  1. cp <patch> $TOPDIR/SOURCES/

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

Patch100000: <patch-name>

and

%patch100000 -p1

in appropriate places where similar text lines are.

Adjust kernel version[edit]

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[edit]

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

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

Note: Make sure all OpenVZ related options are set. See kernel configuration

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.18/linux-2.6.18/.config. Then you can do a make menuconfig or something similar to adjust the kernel configuration. Note that some kernel configuration issues are described at kernel configuration.

Next, copy $TOPDIR/BUILD/kernel-2.6.18/linux-2.6.18/.config to the $TOPDIR/SOURCES directory, but use the corresponding file name in the target directory.

Building RPMs[edit]

To rebuild the kernel, type the following commands:

  1. 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[edit]

Download[edit]

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.18 kernel can be downloaded from here.

Appropriate OpenVZ patches for this kernel version can be found at http://openvz.org/download/kernel/branches/<branch>/<version>/patches/. For example, at the moment there is a patch patch-ovz028stab056.1-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.18-i686-smp.config.ovz for this example.

Prepare[edit]

First, extract the kernel sources from archive:

  1. tar vjxf linux-2.6.18.tar.bz2
# cd linux-2.6.18

Apply OpenVZ patches to the kernel:

  1. gzip -dc patch-ovz028stab056.1-combined.gz | patch -p1

Configure[edit]

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

  1. cp kernel-2.6.18-i686-smp.config.ovz .config
# make oldconfig

On this stage, you can modify your kernel configuration to better suit your needs.

Yellowpin.svg Note: Make sure all OpenVZ related options are set. See kernel configuration.

Build[edit]

# make
# make modules

Installation[edit]

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

  1. make install
# make modules_install

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