Roll your own kernel

From SaruWiki
Jump to navigation Jump to search

PRO's and Con's

There are both advantages and disadvantages to compiling your own Linux kernel. This is an attempt at siding the pro's and con's, as we see them


  • It's fun! (no, really!)
  • Better performance than a stock Debian kernel, because of system specific optimizations
  • Better hardware support, because we can use a newer kernel with newer drivers <ref>note that if for instance the Debian stock kernel does not support your network card, then you really must do something with kernel compilation. You'd have the choice of either compiling a whole kernel, or compiling a module for your network card against the stock kernel</ref>
  • Extra features, because we can use a newer kernel with those newer features


  • No automatic security system à la APT: if there's a security issue in the kernel that you're using, you'll have to find out about it, and then compile a new kernel. As con's go, this is a pretty big one, we reckon. Still, we run our own kernels...
  • You'll need to delve into hardware specific things, expressed in obscure kernel-hacking terms (what's "sparse memory support" for, anyway?)
  • Like everything, this takes time to master, and time to implement. Time spent on kernel compiling tasks (be it learning or executing) cannot be spent on other tasks

Notes <references/>


To compile your own kernel, you'll need some software. First up, you'll need to install the following packages, using "apt-get install <package>" or aptitude. This is the list of packages we advise you to install (if they're not installed already):

libncurses5-dev (plus all its dependencies, including the gcc GNU C Compiler)

Now it's time to get that kernel. To get it on a base server, there are many ways; we'll outline two of them.

Putting a kernel source on your server using WinSCP

This is pretty easy, although it requires the following things

  1. First up, you'll need to have the SSH server installed (which we presuppose anyway)
  2. Next, you'll need a computer on your network running Microsoft Windows, on which you need to install WinSCP.
  3. After installing WinSCP, you start it up, fill in the host name or IP number of your server, your user name (as it exists on the Debian server, and which must have rights to use the SSH server), and click "save" (we advise you never to save your password in WinSCP for security reasons).
  4. After saving the SSH account, you can find it under "stored sessions"; select it and click "login". A login window should appear, and you're asked for your password. After providing that, you're presented with a GUI, that allows you to copy and move files from and to the server. While you can theoretically save to and read from any location on the server, restrictions apply that have to do with the rights of the ordinary user that you are, so for simplicity we assume you'll put files in your home directory (e.g. /home/saruman), and then from a shell on the server move the files to the proper location.
  5. Now, you download the kernel source from the famous From a European location, the latest v2.6 kernel source can be found in here. Download the newest file that is named "linux-2.6.xxxxxx.tar.bz2" (like linux-, or alternatively, the same file in .gz instead of .bz2. The bz2 files are compressed slightly better, but uncompressing it requires the bzip2 program, which is not available on every Unix platform - fortunately it is on Debian.
  6. Use WinSCP to upload the kernel source file to your home directory on the server

Getting the kernel source on your server straight from the 'Net

  1. Log in to your server using your user account
  2. use ftp to connect to the kernel website; use username "anonymous" and password "whatever" (when you use username anonymous, the password doesn't get checked).
    1. if you type the command "lcd" the program should respond with "/home/<yourname>", which is your home directory on your server
    2. if you type the command "pwd" the program should respond with "/", to indicate you're at the root folder of the FTP server
    3. if you type the command "cd pub/linux/kernel/v2.6" the program should respond with "250 Directory successfully changed.". Type pwd to check.
    4. dir lets you see the contents of the remote directory, and dir linux-2.6.2*.bz2 limits the listing to managable sizes
    5. get linux- will copy the indicated kernel source file to your home directory; the ftp client will end the transfer with a message like "226 File send OK."
  3. now you can exit the ftp client with exit

Extracting the kernel source

  1. Log on to the server using your user account, either onto the console, or on an SSH shell (e.g. using PuTTy on a Windows client)
  2. Move the kernel source file from your home directory to the directory /usr/src, change the owner of the file to root:root, and unpack the file using bzip2 (or gzip if you've downloaded the .tar.gz file):
sudo mv linux- /usr/src
cd /usr/src
sudo tar xjvf linux-
sudo rm linux-
cd /usr/src/linux-

Note that because we extract the kernel source using sudo, all of the extracted files are also owned by root.

Kernel compilation

Creating a kernel configuration file

First up, when you get to compiling the kernel, the compilation process will use this file: /usr/src/linux- It contains all directives for the compilation process: what parts to include, what to exclude, which parts of the kernel must be compiled as modules, etcetera. But the extracted kernel source does not contain this .config file. This means you have to create one yourself. For this, you have the following options:

However you choose to go about it, you should wind up with a .config file for precisely the kernel that you've downloaded that fits your hardware and your feature requirements.

The actual compiling

"Installing" the kernel