Sgt-d

From openSUSE

Header

Bold

code

text

  • star'd

- dash'd


chapter


Kernel Hacking 101

November 13, 2007

By: sgt-d / mailto:sgt-d@sodpit.com?subject=kernel_hax_1.0

Credits: Thanks kukks and stittle for assistance in #opensuse-chat and #suse


Introduction

This guide is simplified and targeted for beginners, not veterans, but will work fine for anyone.

The official readme for working with the 2.6.x Linux Kernel can be found in: /usr/scr/linux/README.SUSE.

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

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.



Prerequisites

developer packages (make, gcc, c++, etc.) must all be installed before you proceed.

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.



Notices important note: if you do have a kernel update in yast online updates, you should install it asap. 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.

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 messages. these new errors will be limited to a few third party applications that installed their own custom kernel modules.

examples: nvidia, virtualbox, vmware, and possibly others. truecrypt didn't seem to complain when i used my new kernel.

nvidia fix after kernel update: simply re-install the nvidia drivers

virtualbox fix after kernel update, as root: /etc/init.d/vboxdrv setup

vmware fix after kernel update, as root: /usr/bin/vmware-config.pl

if you have installed nvidia or ati video drivers, please pay close attention.

before doing anything else, 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. 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 will need to reclick the 1-click thingie to install their drivers after booting to the new kernel.

if you don't change back to the stock video driver, your first boot with the new kernel will dump you into runlevel 3 (text mode) until you reinstall your drivers. this is normal/expected/fine for advanced users, or for people that have been manually installing nvidia/ati drivers for years. after the manual installation of these drivers, as root, simply type: rcxdm restart. so, heads up! advanced users might want to download the nvidia/ati drivers and place them in a known location before doing anything else.

note: nvidia users who normally install manually can reinstall the drivers fully, or they can just rebuild the kerne module, eg:

completely reinstall the nvidia driver: sh NVIDIA-Linux-x86_64-100.14.23-pkg2.run

only rebuild the nvidia kernel module: sh NVIDIA-Linux-x86_64-100.14.23-pkg2.run -K



step #1 - kernel sources

install the -exact- kernel source package for your currently installed kernel from either your cd/dvd or from the official 10.3 update repository.

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

note: the /etc/sysconfig/kernel file is read to determine what modules will be used/built

step #2 - prepare

open a terminal and type 'su' (plus password) to become root. you will be here for awhile.

su

backup your /boot/grub/menu.lst file, eg:

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

the /usr/src/linux symlink must point to the current kernel source, verify that with this command:

ls -l /usr/src/linux

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

only do this step if needed. if the link shown above is not pointing correctly to your kernel source, you may need to fix it manually, eg:

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

step #3 - configure

cd /usr/src/linux make clean make mrproper make cloneconfig

note: make cloneconfig copies your currently running kernel configuration to /usr/src/linux/.config

make xconfig -or- make menuconfig

note: i prefer graphical, so i use xconfig.

step #4 - customize

in xconfig or menuconfig:

make sure to change the "release" string!!!

change all settings needed, eg...

note: these optimizations are recommended for the enemy territory quake wars linux client...

general setup

 double click on "local version - append to kernel release" to change it - do not skip this step!
 enter a string value, eg: -sgt or -etqw

processor type and features

 processor family
   make sure your processor family is checked, mine were:
     home:  (x) generic-x86-64
     work:  (x) 586/k5/5x86/6x86/6x86mx
 preemption model
   (x) preemptible kernel (low-latency desktop)
 [*] preempt the big kernel lock
 timer frequency
   (x) 1000 hz

make sure that you save the config

make a quick backup of this configuration:

cp .config .config.bak

step #5 - verify release info

make prepare make kernelrelease # <- the only thing this does is verifies that a unique release string is being used!!!

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

do not continue unless the release string is displayed correctly.

step #6 - build

make

this will build the kernel and all modules and it will take a very long time. plan on at least 60 to 90 minutes on a decent system.

step #7 - install

everything is built, now we have to install it.

we are down to two final commands...

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_PATH=/boot make install

note: INSTALL_PATH probably needs to be caps

step #8 - confirm and boot

verify that the new /boot/grub/menu.lst looks correct, eg:

note: do NOT use this info in your menu.lst, this is just an example...

      1. Don't change this comment - YaST2 identifier: Original name: linux###

title openSUSE 10.3 [ETQW] - 2.6.22.12-0.1

   root (hd0,1)
   kernel /boot/vmlinuz-2.6.22.12-0.1-sgt root=/dev/disk/by-id/scsi-SATA_WDC_WD2500JD-00WD-WMAEP2899549-part2 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 and make sure you see your new -release kernel, system map and initrd there, eg:

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

if this all looks good, boot to your new custom kernel!

informational...


what i saw during install:


wenix:/usr/src/linux # INSTALL_PATH=/boot 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:

      1. Don't change this comment - YaST2 identifier: Original name: linux###

title openSUSE 10.3 [ETQW] - 2.6.22.12-0.1

   root (hd0,1)
   kernel /boot/vmlinuz-2.6.22.12-0.1-sgt root=/dev/disk/by-id/scsi-SATA_WDC_WD2500JD-00WD-WMAEP2899549-part2 vga=0x31a resume=/dev/sda1 splash=verbose showopts
   initrd /boot/initrd-2.6.22.12-0.1-sgt

after booting to the 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