Building Your Own Linux Kernel, part 1
Configure and Build
The kernel folks at your favorite distro -- Ubuntu, Redhat, Debian, SuSE or whatever -- do a great job. Somehow, they come up with a kernel that works with just about machine, from 10-year-old klunkers to brand new 8-core speedsters. When you think about it, it's amazing your machine boots at all!
But writing a kernel for everyone means making compromises. You can get better performance, and sometimes bug fixes, by building your own kernel.
That's one reason to build your own kernel. But here are a few others:
- You can try out brand new kernel features, long before your distro includes them
- You can experiment with performance options, like different schedulers
- Extra "geek cred". Come on, admit it, you care!
Today I'll cover how to build and install a kernel. Upcoming articles will dive into the details of how to customize your kernel and put it on a diet.
Kernel source comes in two varieties. First, you can get the source package from your distro. But building a Debian or Ubuntu kernel package is different from building a Redhat or Fedora package. You can find howtos online, but in this article I'll be talking about the second option: a mainline kernel.
Kernel.org (Figure 1) is the official place to download the latest kernel releases. Start with the full source for the latest stable release (circled): it'll have a filename like linux-2.6.31.tar.bz2. Download it, unpack it, and cd into the directory it creates:
tar xvf linux-2.6.31.tar.bz2 cd linux-2.6.31
You can unpack it anywhere. You may hear about people building kernels in /usr/src/linux, but there's no advantage to it; you can build a kernel just as well under your home directory.
An initial configuration file
The first step in kernel building is to find an initial configuration that works, stored as .config inside the kernel source directory. You can configure kernels from scratch, but I don't recommend it. It's all to easy to make a tiny mistake early in the process and find out 45 minutes later that something is very wrong and you're not being shown the right options.
Where can you get an initial configuration? The easiest place to look is your distro kernel. Most modern distros, happily, give you a copy of their configuration file in /boot. Look for a file with "config" in the name, something like /boot/config-2.6.28-15-generic. Take the one with the latest version number you can find, and copy it to .config inside your new kernel source directory.
If you can't find a config file in /boot, you can try asking the currently running kernel. Look for a file named /proc/config.gz. If it exists, you can get the configuration this way:
zcat /proc/config.gz >.configUnfortunately, many distros don't enable this option in their kernels. If all else fails, try downloading your distro's kernel source package, or find someone who has a machine similar to yours and ask for their kernel config file.
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: GNOME 3.12 and New Betas for Ubuntu 14.04 and OpenMandriva Lx 2014.0
- 2Linux Top 3: Linus Lashes out, Linux 3.14 Gets PIE and Ubuntu One is Done.
- 3Linux Top 3: Ubuntu 14.04, Debian Gives Squeeze More Life and Red Hat Goes Atomic
- 4Linux Top 3: Linux 3.11, Kubuntu Goes Commercial
- 5Linux Top 3: RHEL 6.5, Debian 7.2 and EOL for Linux 3.0.x