In our third, and final, installment on the Linux 2.6 Kernel, we get into the gnarly act of configuration. We also take a peek at patching the new kernel to keep things up-to-date.
When we last talked about Linux 2.6 Kernel
we left off at giving our new 2.6 kernel a unique name, so we can tell it apart from our other kernels. In our third, and final, salute to the new kernel, we'll get into the gnarly part configuration (and we'll also cover patching kernels, so you'll know how to keep your new kernels up-to-date).
Configuration is the most tedious, time-consuming part of the process. Howerver, it's extremely important, so don't gloss over it. If you leave things out, you'll have to go through all this again.
Now you may think of yourself an old Linux pro, but the steps for building a 2.6 kernel are different than 2.4, so pay attention.
Before we leap into the fun stuff, we need to review a couple of items from Part 1 of our trilogy. Remember the command for unpacking the compressed kernel archive:
$ bzcat linux-2.6.3.tar.bz2 | tar -xvf -
Yes, this is the olden way, as a kind reader pointed out. Use it if you have an elderly tar that does not support bzip2 archives. Modern editions of tar support bzip2 directly. The modern way:
$ tar xvjf linux-2.6.3.tar.bz2
Part 1 says to use gcc 2.95.3. I have received reports of using gcc versions up to 3.3 successfully. Your mileage may vary.
The Steps So Far
- 1. Obtain kernel source code, and download it into ~/src
- 2. Make sure gcc, GNU make, binutils, util-linux, and module-init-tools are up-to-date
- 3. Make hard copies of dmesg, lscpi, and lsusb
- 4. Backup any existing .config file (there may not be one)
- 5. Run make mrproper to restore the source directory to a pristine state
- 6. Edit ../linux-2.6.3/Makefile to give the new kernel a unique name, like EXTRAVERSION =new-name
in the 2.6 kernel. You can have both on your system. And, in addition to being well-armed with printouts of lscpi
, it is also wise to capture lsusb
$ lsusb -v | lpr
lsusb is part of usbutils.
This is the most tedious, time-consuming part. Howerver, it's extremely important, so don't gloss over it. If you leave things out, you'll have to go through all this again. It is tempting to recycle your 2.4 .config, and run make oldconfig, but don't. The 2.4 and 2.6 kernels are quite different, this is asking for trouble.
Configure From Scratch
There are two nice graphical configuration utilities: menuconfig, and xconfig. menuconfig is ncurses-based, so you don't need X. xconfig in 2.6 requires Qt and X. Let's use xconfig, because it is sleek and fast, and completely redesigned for 2.6:
$ make xconfig
This will putter and mutter for a bit, then spit out a menu. Have your printouts handy, because now you have to select the right drivers for your hardware, decide what features your kernel will have, and whether to load drivers as modules, or build them into the kernel. menuconfig and xconfig generate loads of information read all of it. Many things will be selected by default. The worst thing that can happen by saying "yes" too many times is you'll enable features that won't be used. This is not a bad thing. In contrast, if you leave something out that you need, you may need to rebuild the kernel. Here are few things which should be built into the kernel:
- module support
- a.out binaries, ELF binaries, and MISC binaries
- VGA text console
- All filesystems you'll be using, such as ext2/3, ReiserFS, JFS, XFS, loopback, vfat, NTFS, udf, etc.
These depend on your hardware; whatever you select should be built into the kernel, not a loadable module:
- IDE, ATA, and ATAPI Block Devices
- SCSI support (note that the 2.6 kernel does not need IDE-SCSI, so if you have no SCSI devices, you can omit this)
- USB support
- Any on-board controllers
- Sound support
These are OK to have as loadable modules:
- NIC drivers
- USB drivers
- sound card drivers
There are help files on almost every item.
Continued on Page 2: Building The Kernel And Modules
Continued From Page 1
Building The Kernel And Modules
Once you've finished and saved your configuration, 2.6 builds the kernel and modules all in one step:
On a slow system, this will take awhile. Go take a nice walk. Then come back and gaze upon your new kernel image, it should be ~/src/arch/i386/boot/bzImage (or whatever your architecture is).
You can have several versions of gcc installed, and select the one you want to use this way:
$ make CC=gcc-2.95
To view a whole raft of "make" targets, run make help first. When it's done, modules must be installed by the superuser:
# make modules_install
You will find your shiny new modules in /lib/modules/2.6.3.
Copy Kernel Image To /boot
Now your nice new kernel image must be moved to /boot, naming it whatever you like, I'll call mine bzImage-2.6.3-testkernel. The kernel name doesn't matter, as long as you tell your bootloader what it is.
# cp ~/src/arch/i386/boot/bzImage /boot/bzImage-2.6.3-testkernel
It is OK to stick with tradition, and call it vmlinuz-something, if you like. Now copy the new System.map:
# cp ~/src/System.map System.map-2.6.3-testkernel
And create a soft link in /boot:
$ ln -s /boot/System.map-2.6.3-testkernel /boot/System.map
Use ln -sf if necessary, to overwrite the existing link.
Finally, tell GRUB or LILO about your new kernel. Your GRUB config will look like this, using, of course, the appropriate values for your system.
title Kernel 2.6.3, test kernel
kernel /boot/bzImage-2.6.3-testkernel root=/dev/hda6 ro
LILO looks like this:
label=Kernel 2.6.3, test kernel
And remember to re-run LILO:
Now you can reboot, select the new kernel, and start testing it. If it doesn't work, simply reboot to your stock kernel.
Applying A Kernel Patch
When it's time to upgrade to 2.6.4, you don't need to download the whole works. All that's necessary is to apply a patch, or perhaps several patches, then rebuild the kernel using make oldconfig, instead of make xconfig. Be sure to save a copy of your current .config file as .config.bak, or make mrproper will overwrite it. Download the patch to ~/src, then unpack and apply the patch:
$ bzip2 -dc ../patch-2.6.4-test1.bz2 | patch -p1
If there is more than one patch, apply them in order. Clean up the source tree, then build the new kernel:
$ make mrproper
$ make oldconfig
Then install the new kernel, and you're in business.
Kernel Building As an Ordinary User
Many docs tell you to unpack sources into /usr/src/, and do the configuration and build process as root. Don't do that. All you're doing is building a usable kernel image, which does not require root privileges. Remember the cardinal Unix rule: Use the least possible privileges for any job, it's safer. All you need superuser powers for are running make modules_install, copying the new kernel image to the boot directory, and editing the bootloader.
This is the most comprehensive kernel-building how-to I've ever seen, with an extensive section on configuration. It was sent to me by an awesome reader thanks! Note that there is a section on 2.6 at the end: Compiling a Custom Linux Kernel
See also the extensive documentation in your kernel sources, under ../Documentation
See All Articles by CrossNodes contributor Carla Schroder