Kernel

Reading

  1. Linux Kernel in a Nutshell (by Greg Kroah-Hartman)
  2. http://www.linux-tutorial.info/
  3. http://kernelnewbies.org/

Preparation

Install some required packages: sudo aptitude install build-essential libncurses-dev ketchup ccache

Then create a folder called linux_kernel, enter it, and run ketchup 2.6. This will download the latest kernel of the 2.6 stable tree (the same command will upgrade the kernel source when a new kernel is out). It might be a good idea to tell GoogleDesktop (or Tracker) not to index this folder.

If ketchup exits with the error message gpg: Can't check signature: public key not found then you need to import the gpg key for kernel.org:

 gpg --keyserver wwwkeys.pgp.net --recv-keys 0x517D0F0E

as indicated under http://kernel.org/signature.html (or run ketchup with the -G option to skip gpg signature verification). You will still get the warning gpg: WARNING: This key is not certified with a trusted signature! To resolve this you need to “build a trust path to the Linux Kernel Archives Verification Key“. i have not yet found how to do this…

Compiling

The first time you download the kernel, run make defconfig. Afterwards, every time you upgrade the kernel source, first run make silentoldconfig. To change the kernel configuration, run make menuconfig.

Usually I also create an alias make_=’make -j4 GCC=”ccache gcc”‘ (-j4 tells gcc to spawn 4 threads; the number should be double the number of your cores). Then, to compile the kernel, just type make_.

Installing the new kernel includes running sudo make install modules_install to install the kernel and its modules, sudo update-initramfs -k _version_ -c (-u instead of -c, if you’re changing the running kernel), and editing /boot/grub/menu.lst. If some of your hardware requires firmware to run, copy the subfolder under /lib/firmware to the new kernel version.

Drivers

If you already have a running kernel and the device works, to see which module is supporting it, run readlink /sys/class/_device_class_/_device_name_/device/driver/module, for example readlink /sys/class/net/eth0/device/driver/module. For some more info on the module, type modinfo _module_. Then type find -type f -name Makefile | xargs grep _module_name_.

If you don’t have a running kernel and you have to start from scratch, then:

  • for a usb device, get the vendor & product id from lsusb, then grep -iRl _vendor_ drivers/*
  • for a pci device, get the vendor & product id from lspci -nn, then lookup the vendor and device ids by grep -i _vendor_ include/linux/pci_ids.h and grep -i _device_ include/linux/pci_ids.h

Leave a Reply