Methods vary across distributions and within distributions there are also different ways to compile the kernel.
I am going to show you how I compile a kernel on OpenSUSE 11.2.
Important: It is assumed proprietary ATi or Nvidia drivers are not installed. If you have such drivers installed and boot into your new kernel, X will crash!
Here we go...
First we need the kernel source and various development tools such as GCC.
Yast > Software Management > View patterns > tick 'Linux Kernel Development' > Accept
This will download and install what you need. At the time of writing the current OpenSUSE Kernel source was version 2.6.31.12-0.2.1, reference to such has been made throughout.
Open a terminal and type the following
su -
cd /usr/src/linux
We are now into our Linux source directory with root privileges and must create a config file for our kernel.
It is a good idea to use the same config that is being used by the OpenSUSE kernel which you are using right now, then fine tune it to your needs later on.
To use the same config file type the following,
make cloneconfig
With our config file we can now start editing the kernel by typing the following,
make menuconfig
This is the fun part, you can go through all the kernel options and change whatever you wish. I won't tell you what to change, that is completely down to you.
Changing some options may cause a broken kernel and / or Kernel Panic!
Tip: Highlight any option and press h. This will show information about the selected option.
When you have finished playing around, exit and save your changes.
Remember to give your kernel a different name, edit the following kernel option
General Setup ---> Local version - append to kernel release
Type anything you wish, for example
-modified
Building the Kernel
This part can take a while depending on your processor. Compiling also puts a high load on your processor as well as stressing the system, causing temperatures and power consumption to increase.
If you are unable to successfully compile a 100% default and unchanged kernel due to a compilation error, there is a high possibility your system has a weakness.
It could be due to many things, for example a hot running processor, motherboard chipset, PWM circuitry, memory, combination of all these, faulty memory, poor power supply.
To build your kernel as an RPM package type the following,
make rpm
You can watch the compile if you wish, maybe have a cup of tea...and biscuits!
When the compile has finished, the new kernel needs to be installed.
cd /usr/src/packages/RPMS/x86_64
If you are using the 32-bit OpenSUSE the new kernel will be located in the i386 folder.
cd /usr/src/linux/packages/i386
If you type in dir, you will see an rpm file, for example kernel-2.6.31.120.2modified-1.x86_64.rpm
To install it type the following,
zypper install NAME_OF_FILE.rpm
example, zypper install kernel-2.6.31.120.2modified-1.x86_64.rpm
Once it has been installed, type
cd /boot
mkinitrd
Now if you type dir whilst still in the /boot directory you should have the following 2 files,
vmlinuz-2.6.31.12-0.2-modified
initrd-2.6.31.12-0.2-modified
The NAME_OF_KERNEL in this example is 2.6.31.12-0.2-modified
The final part, is to edit the grub loader (using your favourite editor) to add our new kernel.
gedit /boot/grub/menu.lst
Example menu.lst
# Modified by YaST2. Last modification on Thu Apr 8 16:21:47 BST 2010
# THIS FILE WILL BE PARTIALLY OVERWRITTEN by perl-Bootloader
# Configure custom boot parameters for updated kernels in /etc/sysconfig/bootloader
default 0
timeout 8
##YaST - generic_mbr
gfxmenu (hd0,0)/boot/message
##YaST - activate
###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.2 - 2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-desktop root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 resume=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part2 splash=silent quiet showopts vga=0x31a
initrd /boot/initrd-2.6.31.12-0.2-desktop
###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- openSUSE 11.2 - 2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-desktop root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 showopts apm=off noresume edd=off powersaved=off nohz=off highres=off processor.max_cstate=1 x11failsafe vga=0x31a
initrd /boot/initrd-2.6.31.12-0.2-desktop
Use the default OpenSUSE kernel entry as a template. In the above example menu.lst the green text will be our template.
Modify it to suit your needs.
###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.2 - 2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-NAME_OF_KERNEL root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 resume=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part2 splash=silent quiet showopts vga=0x31a
initrd /boot/initrd-NAME_OF_KERNEL
The red parts must be changed with the exact name of your kernel.
For example, 2.6.31.12-0.2-modified
The orange bits can be left alone but to avoid confusion I suggest you change them. It can be anything you wish.
Then add the new entry to the menu.lst file.
# Modified by YaST2. Last modification on Thu Apr 8 16:21:47 BST 2010
# THIS FILE WILL BE PARTIALLY OVERWRITTEN by perl-Bootloader
# Configure custom boot parameters for updated kernels in /etc/sysconfig/bootloader
default 0timeout 8
##YaST - generic_mbr
gfxmenu (hd0,0)/boot/message
##YaST - activate
###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.2 - 2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-desktop root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 resume=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part2 splash=silent quiet showopts vga=0x31a
initrd /boot/initrd-2.6.31.12-0.2-desktop
###Don't change this comment - YaST2 identifier: Original name: My custom kernel###
title Desktop -- openSUSE 11.2 - 2.6.31.12-0.2-modified
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-modified root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 resume=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part2 splash=silent quiet showopts vga=0x31a initrd /boot/initrd-2.6.31.12-0.2-modified
###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- openSUSE 11.2 - 2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-desktop root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 showopts apm=off noresume edd=off powersaved=off nohz=off highres=off processor.max_cstate=1 x11failsafe vga=0x31a
initrd /boot/initrd-2.6.31.12-0.2-desktop
Exit the editor, reboot your machine.
When you see the grub menu, select your new kernel. If you want it to load by default, change the default option in the menu.lst file to 1.
I have highlighted the default option in purple.
0 corresponds to the 1st entry, 1 will correspond to the 2nd entry and so on.
Before recompiling another Kernel
If you wish to compile again, issue the following command whilst in the /usr/src/linux directory
make mrproper
This will clear any rubbish left from the previous compile and is necessary to prevent a make error.
How to remove your custom Kernels
You can use zypper to remove your kernel by typing,
zypper remove NAME_OF_PACKAGE
example, zypper remove kernel-2.6.31.120.2modified-1.x86_64
The .rpm at the end is not required and will result in a package not found error.
Next delete the initrd file created when we issued the mkinitrd command,
rm /boot/2.6.31.12-0.2-modified
And finally delete the now obsolete entry in the /boot/grub/menu.lst file.
Enjoy compiling your own Kernels!
Excelent and clean how-to.
ReplyDeleteThx :)
I finally managed to compile the kernel in opensuse, thank your help
ReplyDeleteA very good article, thank you, however I had one issue:
ReplyDeleteafter: make rpm
it stopped after just a few lines complaining:
rpm --target i386
unknown option
and would not go on at all. So I had to compile the kernel with 'make' only.
any idea how to fix that?
Its been a while since using 11.2, from memory make sure the rpmbuild scripts/tools are installed.
ReplyDelete11.2 is EOL, and trying the above steps with a newer version is most likely to fail.
Later this week I will write a guide for 12.2, that doesnt require compiling as root.