Configure, Build and Install a Custom Linux Kernel

From openSUSE

Version 10.3.

Contents


  • Status: 20071125 1.05 Rough Draft

Introduction


About this Guide

This guide is simplified and targeted for beginners, not veterans, but should work fine for everyone.

The first half of this guide is mostly notes and information to help prepare you for some possible issues or problems that you might have along the way. Please take some time to read through all of the notes so you are prepared.

I have chosen to use the recommended tweaks for "Enemy Territory Quake Wars" (ETQW) for use in this guide to provide a basic example of how to make changes to an existing kernel configuration.

Many people claim that the tweaks mentioned for ETQW are not necessary and that you don't have to build a custom kernel if you have bleeding edge hardware.

Where is the fun in that?!?  :)


Overview

We will install the latest possible openSUSE kernel and kernel source, then we will boot to the new kernel.

If everything works correctly with the new kernel, we will then copy the currently loaded (and newest possible) kernel configuration for use as the initial configuration for the custom kernel we are going to build.

Finally we will configure, build and install the new custom kernel and then boot from it.

In the end, your system should work identically as before except now it will have a decent performance boost and the recommended settings for ETQW.

From the ETQW Readme

  • You need a low latency kernel for optimal performance (this applies to both client and server installations).
  • Make sure your kernel is configured with CONFIG_HZ_1000=y.
  • You should also enable other low latency settings, such as the various preemption settings.
  • Kernel 2.6, configured for 1000Hz tick and other low latency settings.

References

The official readme for working with the 2.6.x linux kernel can be found in: /usr/scr/linux/README.SUSE. This file is only available if you installed the kernel sources.

I have also added the official readme for reference here:

http://en.opensuse.org/Official_openSUSE_Kernel_2.6.22.12-0.1_Readme

Realtime (RT) Kernel Instructions are HERE: http://en.opensuse.org/Rt_Kernel_Instructions


Notes

The remainder of this page is currently unofficial. Mileage may vary.

This document was prepared for openSUSE 10.3 - ONLY.

At the time of this writing, the current openSUSE Linux Kernel version is linux-2.6.22.12-0.1. This exact version (2.6.22.12-0.1) will be used throughout this howto for all of my examples. This version may not match your kernel version. Substitute your kernel version wherever you see '2.6.22.12-0.1' below.


Development Packages

All developer packages (Make, GCC, C++, etc.) must all be installed (and updated - next section) before you proceed.

In YaST Community Repositories, add the openSUSE 10.3 Update Repository:

http://download.opensuse.org/update/10.3/

In YaST Software Management, select "Patterns" from the "Filter" drop-down selector (top left).

At minimum, check ALL of these:

  • Base Development
  • KDE Development
  • C/C++ Development
  • Linux Kernel Development

Also locate and install the main Xorg/X11 Development packages such as xorg-x11-devel.


System Updates

Make sure your system is as close to 100% current as humanly possible. Install all updates, particularly the newest kernel(s), kernel-source(s) and developer packages (Make, GCC, C++, etc.) before attempting anything on this page.

In YaST Community Repositories, add the openSUSE 10.3 Update Repository:

http://download.opensuse.org/update/10.3/

Then use YaST Online Updates (YOU) to install all possible updates.

After that, use YaST Software Management to upgrade all of the items mentioned at the top of this section.

Important: If you have a kernel update available in YaST Online Updates (YOU), you should install it ASAP, including the newest possible kernel sources. After installing the updated kernel, you must reboot using the new kernel before proceeding. Doing this will guarantee that the custom kernel you are going to build later will be based on the newest possible openSUSE kernel and sources.


Notices

Important: Make sure you keep a working version of the openSUSE -default kernel installed.

Before you start... realize that the first time you boot from your new kernel you will probably see a very small number of new "red" error/failed messages. These new errors will probably be normal and should be limited to a few third party applications that (in the past) had installed their own custom kernel modules.

Examples: NVIDIA, ATI, VirtualBox, VMware, and possibly others. TrueCrypt didn't seem to complain when I used my new kernel.

Fixing these things after the new kernel is installed and being used is covered below in the section titled "Step 9 - Fixing Things".

Aside from these errors which are expected, if you see other failed messages during the boot process it could indicate that there is serious problem with the new kernel and that it might not be usable at all.


Video Drivers / Kernel Modules

If you have installed NVIDIA or ATI video drivers, please pay close attention.

If you installed your video drivers from the online repository or from a 1-click installer, you may not have to do anything for your drivers to work correctly after booting the new kernel. While I know this is true for official kernels (they always keep the video drivers on the online repositories current with the newest official kernels), I cannot guarantee the same will hold true for a custom built kernel - even though it will be "based" on the official kernel.

You should strongly consider changing your video driver in /etc/X11/xorg.conf back to the STOCK (original) video driver that was setup by openSUSE during installation. Typically the stock driver would be "nv" for NVIDIA users and either "radeon" or "vesa" for ATI users. I have no clue what to tell you for any other cards/chipsets other than: "good luck". Making this change to your xorg.conf means that when you boot your new kernel, graphical mode (runlevel 5) will work the way it did when you first installed openSUSE (without a third party video driver). The custom drivers won't be installed, but at least you won't be stuck in text mode (runlevel 3) on your first boot with the new kernel. This is particularly helpful for people that rely heavily on "easy" solutions such as the "1-click" installers. 1-click users might need to rerun the 1-click installer to install their drivers after booting to the new kernel.

If you do not change back to the stock video driver, your first boot with the new kernel might drop you into runlevel 3 (text mode) until you reinstall the kernel module for your video drivers, or reinstall the drivers. This is normal/expected/fine for advanced users, or for people that have been manually installing NVIDIA/ATI drivers for years.

So, heads up! Advanced users might want to download the NVIDIA/ATI drivers and place them in a known location before doing anything else.

Rebuilding video driver kernel modules and installing video drivers after the new kernel is installed and being used is covered below in the section titled "Step 9 - Fixing Things".


Proceedures


Step 1 - Kernel Sources

If you haven't already done this, do it now:

In YaST Community Repositories, add the openSUSE 10.3 Update Repository:

http://download.opensuse.org/update/10.3/

The most current kernel and kernel sources are always located here:

http://download.opensuse.org/repositories/Kernel:/HEAD/openSUSE_Factory/

Use YaST Software Management to install the EXACT kernel source package that matches your currently installed and running kernel, most likely from the openSUSE 10.3 Update Repository.

Informational: The /etc/sysconfig/kernel file is read to determine what modules will be used/built.

If you did upgrade your kernel in this step, check your /boot/grub/menu.lst file to make sure it looks right, then reboot your computer now and make sure you are using this new kernel.


Step 2 - Prepare

Final reminder... if you have not rebooted using the newest possible openSUSE linux kernel, stop what you are doing and boot to the new kernel NOW.

Open a terminal and type 'su' (plus your password) to become root. You will be here for awhile, so get comfortable.

su -

Make a backup of your menu.lst file, eg:

cp /boot/grub/menu.lst /boot/grub/menu.bak

Important: The /usr/src/linux symlink must point to the current kernel source. Please verify that with this command:

ls -l /usr/src/linux

You should see something like this:

lrwxrwxrwx 1 root root 19 2007-11-08 15:10 /usr/src/linux -> linux-2.6.22.12-0.1

Do not perform the next step unless it is absolutely needed. If the link shown above is not pointing correctly to your kernel source, you may need to fix it manually, example:

ln -sf /usr/src/linux-2.6.22.12-0.1 /usr/src/linux

Step 3 - Configure

NOTE... Many people suggest to SKIP the "make cloneconfig" step (between SKIP and END SKIP). Do what they say. I skipped this and had NO problems!

cd /usr/src/linux
make clean
make mrproper

SKIP

make cloneconfig

Note: The 'make cloneconfig' command copies your currently running kernel configuration to:

/usr/src/linux/.config

END SKIP

Open the configuration UI:

make xconfig

or

make menuconfig

Note: I prefer the graphical configuration (qconf), so I always use 'make xconfig'.

This will open the configuration screen so we can begin making changes. Please note, the current options that you see checked are what you kernel is currently using... this information was supplied when we used 'make cloneconfig' (above).


Step 4 - Customize

Make sure to change the "Local Version Release String"!

Changing the release string is extremely important. If you don't change it, your new kernel and modules will overwrite the '-default' kernel and modules. We do NOT want that to happen. I used '-sgt' for my release string, so when I was done building and installing, my kernel and modules had a '-sgt' suffix, not '-default'. Example:

vmlinuz-2.6.22.12-0.1-sgt

In xconfig or menuconfig:

Change all settings needed. Again, in this guide I am only focusing on the recommended changes for ETQW.

I didn't see any "other" preempt options than the ones I have shown below, there might be more.

The settings shown below now include additional optimizations. The new HPET settings that are shown are pretty much default for 64bit, but the new "Tickless System", "High Resolution Timer Support" and some of the HPET settings are disabled by default on 32bit. For best performance you should use the settings shown here.

General setup
  Local version - append to kernel release
  - Double click on this to change it
  - Do NOT skip this step!
  - Enter a 'dash' (-) and a string value, eg: -sgt or -etqw
Processor type and features
  (x) Tickless System (Dynamic Ticks) (NO_HZ) (32bit Only)
  (x) High Resolution Timer Support (HIGH_RES_TIMERS) (32bit Only)
  Processor family
    Make sure your processor family is checked, mine were:
      Home:  (x) AMD-Opteron/Athlon64 (MK8) (or: Generic-x86-64 (GENERIC_CPU))
      Work:  (x) Pentium-4/Celeron(P4-based)/Pentium-4 M/older Xeon (MPENTIUM4) (or: 586/K5/5x86/6x86/6x86MX (M586))
  (x) HPET Timer Support (HPET_TIMER) (32bit Only)
  Preemption model
    (x) Preemptible Kernel (Low-Latency Desktop) (PREEMPT)
  [*] Preempt The Big Kernel Lock (PREEMPT_BKL)
  Timer frequency
    (x) Timer frequency (HZ) <- 1000
Device Drivers
  Character devices
    (x) HPET - High Precision Event Timer (HPET)
    (x) Allow mmap of HPET (HPET_MMAP)
    ( ) HPET Control RTC IRQ (HPET_RTC_IRQ)

Make sure that you save the config.

Make a backup of your kernel configuration:

cp .config .config.bak

Step 5 - Verify Release Info (Skip)

M3phistopl3s told me today NOT to use 'make prepare' with openSUSE kernels.

I do not know what the implications of this command are, but I am researching it.

If you are 100% certain that you set your "Local Version Release String" correctly in "Step #4" (above), it is SAFE to skip this current step (Step #5) entirely.

I will say that I ran this command several times and didn't have any problems with it, but you should avoid Step #5 until further notice.

--- SKIP TO STEP #6 ---

I am leaving the next few lines here for future reference, you should skip to Step #6 now.

<ignore>

The only thing the next commands do is verifies that a unique release string is being used.

make prepare
make kernelrelease

Example (my) output after running these commands:

2.6.22.12-0.1-sgt

If the release string is not displayed correctly, re-run 'make xconfig', add a release string or fix the problem(s), save, then run 'make prepare' and 'make kernelrelease' again.

Do not continue unless the release string is displayed correctly!

</ignore>


Step 6 - Build

make

This will build the kernel and all modules and it will take some time to complete. The build process can take anywhere from 20 to 60+ minutes.


Step 7 - Install

Everything was built in the previous step, now we have to install it.

We are down to two final commands...

Install the modules:

make modules_install

Note: 'make modules_install' will install modules to:

/lib/modules/2.6.22.12-0.1-your_release_string

Example:

/lib/modules/2.6.22.12-0.1-sgt

Install the kernel:

make install

Step 8 - Confirm and Boot

Verify that the new /boot/grub/menu.lst looks correct, example:

Note: Do NOT use this info in your menu.lst, this is just an example...

title openSUSE 10.3 [sgt] - 2.6.22.12-0.1
root (hd0,1)
kernel /boot/vmlinuz-2.6.22.12-0.1-sgt root=/dev/hda1 vga=0x31a resume=/dev/sda1 splash=verbose showopts
initrd /boot/initrd-2.6.22.12-0.1-sgt

Take a quick look at your /boot directory/partition and make sure you see your new '-release' kernel, system map and initrd there, example:

/boot/initrd-2.6.22.12-0.1-sgt
/boot/System.map-2.6.22.12-0.1-sgt
/boot/vmlinuz-2.6.22.12-0.1-sgt

If your menu.lst file looks good, and you see your new '-release' files (shown directly above) in /boot, restart your computer and boot to your new custom kernel!


Step 9 - Fixing Things

During the first boot from your new kernel you probably saw a very small number of new "red" error/failed messages. These new errors are probably be normal and should be limited to a few third party applications that (in the past) had installed their own custom kernel modules.

Examples: NVIDIA, ATI, VirtualBox, VMware, and possibly others. TrueCrypt didn't seem to complain when I used my new kernel.

NVIDIA Fix after Kernel Update

If you are NOT stuck in terminal mode (runlevel 3) when you boot up, and you want to rebuild the NVIDIA kernel module, you will need to do this first:

su -c "rcxdm stop"

or

su -c "init 3"

Either of those commands will drop you to text mode on TTY1.

If you ARE stuck in terminal mode, simply login on TTY1 as ROOT.

Rebuild the NVIDIA kernel module using the installer with the -K option:

su -c "sh NVIDIA-Linux-x86_64-100.14.23-pkg2.run -K"

After the manual rebuild / reinstallation of the NVIDIA or module or drivers, simply type:

su -c "rcxdm start"

or

su -c "init 5"

Either of the commands above will restart your normal X session on VT7.

For more help with NVIDIA drivers, please visit the openSUSE NVIDIA Page:

http://en.opensuse.org/NVIDIA

ATI Fix after Kernel Update

Unknown. I am assuming that if you installed via online repositories or using a 1-click installer, you might not have to do anything... it may just work on it's own. If not, you may have to reinstall or re-1-click.

For more help with ATI drivers, please visit the openSUSE ATI Page:

http://en.opensuse.org/ATI

VirtualBox Fix after Kernel Update

su -c "/etc/init.d/vboxdrv setup"

VMWare Fix after Kernel Update

su -c "/usr/bin/vmware-config.pl"

Informational

What I saw during installation...

wenix:/usr/src/linux # make install
sh /usr/src/linux-2.6.22.12-0.1/arch/x86_64/boot/install.sh 2.6.22.12-0.1-sgt arch/x86_64/boot/bzImage System.map "/boot"
Kernel image:   /boot/vmlinuz-2.6.22.12-0.1-sgt
Initrd image:   /boot/initrd-2.6.22.12-0.1-sgt
Root device:    /dev/disk/by-id/scsi-SATA_WDC_WD2500JD-00WD-WMAEP2899549-part2 (/dev/sdd2) (mounted on / as ext3)
Resume device:  /dev/sda1
Kernel Modules: processor thermal scsi_mod libata pata_amd sata_nv fan jbd mbcache ext3
edd sd_mod usbcore ohci-hcd uhci-hcd ehci-hcd ff-memless hid usbhid
Features:       block usb resume.userspace resume.kernel
Bootsplash:     SuSE (1280x1024)
47368 blocks

My menu.lst...

title openSUSE 10.3 [sgt] - 2.6.22.12-0.1
root (hd0,1)
kernel /boot/vmlinuz-2.6.22.12-0.1-sgt root=/dev/hda1 vga=0x31a resume=/dev/sda1 splash=verbose showopts
initrd /boot/initrd-2.6.22.12-0.1-sgt

After booting to my new kernel...

sgt-d@wenix:~> uname --all
Linux wenix 2.6.22.12-0.1-sgt #1 SMP PREEMPT Mon Nov 12 21:18:18 CST 2007 x86_64 x86_64 x86_64 GNU/Linux

Extras

Automate the Build Process

To help with the build process here is a script to run all the make commands needed

#!/bin/bash
echo "Starting kernel build. Please be Patient this will take at least 20 minutes."
echo "We advise you refrain from using your system till the cycle is complete. Thank you"
make && make modules_install && make install

save it as runmake.sh. To run it, change to the source directory using 'cd' and then run it using the full path to the script, like this

sh /home/meph/configs/kernel/runmake.sh