Difference between revisions of "Kernel build"
(Put gzip and patch in a pipe in →Building) |
(Fixed kernel download URLs, added <code> tag pairs, some rewording) |
||
Line 1: | Line 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. | |
== Rebuilding kernel from SRPM == | == Rebuilding kernel from SRPM == | ||
=== Download === | === Download === | ||
− | Source | + | 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 === | === Installation === | ||
Install the downloaded SRC RPM with the following command: | Install the downloaded SRC RPM with the following command: | ||
<pre> | <pre> | ||
− | # rpm -ihv ovzkernel-2.6.16- | + | # rpm -ihv ovzkernel-2.6.16-026test014.4.src.rpm |
</pre> | </pre> | ||
− | After successfull installation you can find kernel sources in /usr/src/<distro>/SOURCES/ | + | After successfull installation, you can usually find kernel sources in <code>/usr/src/<distro>/SOURCES/</code> |
− | and kernel spec file (kernel-ovz.spec) in /usr/src/<distro>/SPECS, where <distro> is your distribution-specific directory. | + | and kernel spec file (<code>kernel-ovz.spec</code>) in <code>/usr/src/<distro>/SPECS</code>, where <code><distro></code> is your distribution-specific directory. |
− | For example, for | + | For example, for Red Hat based distros it is <code>redhat</code>, for SUSE it is <code>packages</code>. |
=== Adding your own patches === | === 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 SOURCES directory. | + | To modify the kernel one needs just to add specific patches to the kernel spec file and put this patch into <code>SOURCES</code> directory. |
+ | |||
Put your patch into SOURCES directory with the following command: | Put your patch into SOURCES directory with the following command: | ||
<pre> | <pre> | ||
Line 26: | Line 26: | ||
</pre> | </pre> | ||
− | Then open spec file /usr/src/<distro>/SPECS/kernel-ovz.spec in the editor and add the following lines: | + | Then open spec file <code>/usr/src/<distro>/SPECS/kernel-ovz.spec</code> in the editor and add the following lines: |
<pre> | <pre> | ||
Patch10000: <patch-name> | Patch10000: <patch-name> | ||
Line 37: | Line 37: | ||
=== Building RPMs === | === Building RPMs === | ||
− | 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>/usr/src/<distro>/SPECS/kernel-ovz.spec</code> file and replace the following line: |
<pre> | <pre> | ||
%define ksubrelease 1 | %define ksubrelease 1 | ||
</pre> | </pre> | ||
− | with | + | with something like |
<pre> | <pre> | ||
%define ksubrelease 1-my.kernel.v1 | %define ksubrelease 1-my.kernel.v1 | ||
Line 49: | Line 49: | ||
− | To rebuild the kernel type the following commands | + | To rebuild the kernel, type the following commands: |
<pre> | <pre> | ||
# cd /usr/src/<distro>/SPECS | # cd /usr/src/<distro>/SPECS | ||
Line 55: | Line 55: | ||
</pre> | </pre> | ||
− | After successfull kernel compilation binary RPMs can be found at /usr/src/<distro>/RPMS/i686 | + | After successfull kernel compilation binary RPMs can be found at <code>/usr/src/<distro>/RPMS/i686</code>. |
== Rebuilding kernel from sources == | == Rebuilding kernel from sources == | ||
Line 64: | Line 64: | ||
Linux kernel can be found at [http://www.kernel.org/ kernel.org], e.g. 2.6.16 kernel can be downloaded from [http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.16.tar.bz2 linux-2.6.16.tar.bz2]. | Linux kernel can be found at [http://www.kernel.org/ kernel.org], e.g. 2.6.16 kernel can be downloaded from [http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.16.tar.bz2 linux-2.6.16.tar.bz2]. | ||
− | Appropriate OpenVZ patches for this kernel version can be found at http://openvz.org/download/, | + | Appropriate OpenVZ patches for this kernel version can be found at http://openvz.org/download/kernel/. For example, at the moment there is a patch [http://download.openvz.org/beta/kernel/026test014.4/patches/patch-026test014-combined.gz patch-026test014-combined.gz] available. |
− | Kernel configs are also available at OpenVZ download site. Most | + | Kernel configs are also available at OpenVZ download site. Most frequently SMP config is used, so let's download [http://download.openvz.org/beta/kernel/026test014.4/configs/kernel-2.6.16-026test014-i686-smp.config.ovz kernel-2.6.16-026test014-i686-smp.config.ovz] |
for this example. | for this example. | ||
Line 78: | Line 78: | ||
Apply OpenVZ patches to the kernel: | Apply OpenVZ patches to the kernel: | ||
<pre> | <pre> | ||
− | # gzip -dc patch- | + | # gzip -dc patch-026test014-combined.gz | patch -p1 |
</pre> | </pre> | ||
Now we need to place the config and build the kernel: | Now we need to place the config and build the kernel: | ||
<pre> | <pre> | ||
− | # cp kernel-2.6.16- | + | # cp kernel-2.6.16-026test014-i686-smp.config.ovz .config |
# make oldconfig | # make oldconfig | ||
# make | # make |
Revision as of 14:07, 4 July 2006
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.
Contents
Rebuilding kernel from SRPM
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-026test014.4.src.rpm
After successfull installation, you can usually find kernel sources in /usr/src/<distro>/SOURCES/
and kernel spec file (kernel-ovz.spec
) in /usr/src/<distro>/SPECS
, where <distro>
is your distribution-specific directory.
For example, for Red Hat based distros it is redhat
, for SUSE it is packages
.
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 SOURCES
directory.
Put your patch into SOURCES directory with the following command:
# cp <patch> /usr/src/<distro>/SOURCES/
Then open spec file /usr/src/<distro>/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.
Building RPMs
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 /usr/src/<distro>/SPECS/kernel-ovz.spec
file and replace the following line:
%define ksubrelease 1
with something like
%define ksubrelease 1-my.kernel.v1
To rebuild the kernel, type the following commands:
# cd /usr/src/<distro>/SPECS # rpmbuild -ba --target=i686 kernel-ovz.spec
After successfull kernel compilation binary RPMs can be found at /usr/src/<distro>/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/. For example, at the moment there is a patch patch-026test014-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-026test014-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-026test014-combined.gz | patch -p1
Now we need to place the config and build the kernel:
# cp kernel-2.6.16-026test014-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.