Kernel Compilation: (Updated for Fedora 8) (the old howto is attached)
1. Reasons to recompile the kernel
2. Where to start
3. Configuring
4. Compiling
5. Installing
1. There are various reasons to recompile the kernel. For example:
- Include new drivers (that are not enabled by default)
- Just for fun
- Gain a performance boost
- And many more...
Recompiling the kernel is not for those who are regular Windows end-users. You need to know:
- Which hardware you have (and which drivers are required)
- What the system really needs
Things could go wrong, so always make a back-up of important data!
2. You start by preparing the system for the compilation. Your system needs several tools to build the kernel. Plus, you need the source of the kernel of course...
So, let's update the system to compile (you first become root (after opening a terminal of course), and you have to stay root during the entire howto):
su -Some of these programs are really required (yum-utils ncurses-devel gcc-c++ gcc binutils rpm-build m4 rpmdevtools make). Some might not even be touched (e2fsprogs jfsutils reiserfs-utils xfsprogs pcmciautils quota ppp isdn4k-utils nfs-utils procps oprofile libglade). But I included them so you don't have to hunt them down in case they are needed .yum -y install yum-utils ncurses-devel gcc-c++ gcc binutils rpm-build m4 rpmdevtools make sparse e2fsprogs jfsutils reiserfs-utils xfsprogs pcmciautils quota ppp isdn4k-utils nfs-utils procps oprofile libglade
Now, let's grab the source.
Now we only need to install the source so that it is ready for editing and compiling:yumdownloader --source kernel
rpmdev-setuptreerpm -Uvh /root/kernel-*src.rpm
3. Configuring (I will add patching later if I have time)
These sections are important (look closely (plus they may vary in each kernel version)):gedit /root/rpmbuild/SPECS/kernel.spec
>>>
%define fedora_build %(R="$Revision: 1.294 $"; R="${R%% \$}"; R="${R##: 1.}"; expr $R - %{fedora_cvs_origin})
<<<
-----------------------------------------------------------------------^ Place any extra stuff after this (in our case 1.294...) to seperate this kernel from the stock kernel. You must do this, or you will overwrite your default kernel.
<<<
# The following build options are enabled by default.
# Use either --without <opt> in your rpmbuild command or force values
# to 0 in here to disable them.
#
# standard kernel
%define with_up %{?_without_up: 0} %{?!_without_up: 1}
# kernel-smp (only valid for ppc 32-bit, sparc64)
%define with_smp %{?_without_smp: 0} %{?!_without_smp: 0} # %{?!_without_smp: 0} will mean no SMP kernel same as the others below.
# kernel-PAE (only valid for i686)
%define with_pae %{?_without_pae: 0} %{?!_without_pae: 0}
# kernel-xen
%define with_xen %{?_without_xen: 0} %{?!_without_xen: 0}
# kernel-kdump
%define with_kdump %{?_without_kdump: 0} %{?!_without_kdump: 0}
# kernel-debug
%define with_debug %{?_without_debug: 0} %{!?_without_debug: 0}
# kernel-doc
%define with_doc %{?_without_doc: 0} %{?!_without_doc: 0}
# kernel-headers
%define with_headers %{?_without_headers: 0} %{?!_without_headers: 0} # Assuming you stay x86, you don't need new headers.
# kernel-debuginfo
%define with_debuginfo %{?_without_debuginfo: 0} %{!?_without_debuginfo: 0}
>>>
>>>
%define debugbuildsenabled 1 # Set this to 0 to disable the annoying debug kernel.
<<<
Now we can start building to generate a .config:
Note, I use --target=i686. This is for the architecture of your computer. If you have a normal computer (PC) then you should always use i686. Unless you have a mac, then use 'ppc' (not tested). You can view your arch by typing:rpmbuild -bp --target=i686 /root/rpmbuild/SPECS/kernel.spec
Now creat your config:arch
cd /root/rpmbuild/BUILD/*/linux*Now, create and save your .config inside menuconfig in your root directory: (save it as: /root/config)make menuconfig
AND, save your kernel.spec in your root directory (this is done below) and clean up the mess:
cp /root/rpmbuild/SPECS/kernel.spec /root/specrm -rf /root/rpmbuild/Now we have to reinstall the source (we do this to keep the building environment in good condition):cd /root/
rpmdev-setuptreeCopy back your spec file:rpm -Uvh /root/kernel-*src.rpm
Now your /root/config file, this one is a little more complicated:cp /root/spec /root/rpmbuild/SPECS/kernel.spec
One of these configs are used for your kernel (defined by --target=i686). If you build an i686 (normal and SMP) kernel you need:dir /root/rpmbuild/SOURCES | grep "config-"
So you copy your config over that config:config-i686
cp /root/config /root/rpmbuild/SOURCES/config-i686
4. Compiling
Finally you can start compiling (again replace i686 with your architecture):
rpmbuild -bb --target=i686 /root/rpmbuild/SPECS/kernel.spec
5. Installing
You can find the .rpms inside:
/root/rpmbuild/RPMS/`arch`/
This will install the newly build kernel on an i686 system:
And the development package:rpm -i /root/rpmbuild/RPMS/i686/kernel-2.6.*.rpm
Your new kernel is now installed, reboot to test it . (Chose the new entry in grub during boot)rpm -i /root/rpmbuild/RPMS/i686/kernel-devel-2.6.*.rpm
To remove (RPM requires and exact match (so no wildcards) before it will delete packages):
To see all installed kernels (and development and headers) do:
The output will list the installed kernels. Yours has the same name as the packages in /root/rpmbuild/RPMS/`arch`/rpm -aq | grep kernel
The following example will delete the current stock kernel from Fedora (and devel): (So replace it with your kernel!)
rpm -e kernel-2.6.23.9-85.fc8If there are any questions, feel free to ask them...rpm -e kernel-devel-2.6.23.9-85.fc8
Thanks to the people who gave feedback and some really good tips