Roll your own kernel
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
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):
sudo bzip2 ftp make 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
- First up, you'll need to have the SSH server installed (which we presuppose anyway)
- Next, you'll need a computer on your network running Microsoft Windows, on which you need to install WinSCP.
- 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).
- 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.
- Now, you download the kernel source from the famous kernel.org. 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-18.104.22.168.tar.bz2), 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.
- 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
- Log in to your server using your user account
- use ftp ftp.eu.kernel.org to connect to the kernel website; use username "anonymous" and password "whatever" (when you use username anonymous, the password doesn't get checked).
- if you type the command "lcd" the program should respond with "/home/<yourname>", which is your home directory on your server
- if you type the command "pwd" the program should respond with "/", to indicate you're at the root folder of the kernel.org FTP server
- if you type the command "cd pub/linux/kernel/v2.6" the program should respond with "250 Directory successfully changed.". Type pwd to check.
- dir lets you see the contents of the remote directory, and dir linux-2.6.2*.bz2 limits the listing to managable sizes
- get linux-22.214.171.124.tar.bz2 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."
- now you can exit the ftp client with exit
Extracting the kernel source
- 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)
- 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-126.96.36.199.tar.bz2 /usr/src cd /usr/src sudo tar xjvf linux-188.8.131.52.tar.bz2 sudo rm linux-184.108.40.206.tar.bz2 cd /usr/src/linux-220.127.116.11
Note that because we extract the kernel source using sudo, all of the extracted files are also owned by root.
Creating a kernel configuration file
First up, when you get to compiling the kernel, the compilation process will use this file: /usr/src/linux-18.104.22.168/.config. 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:
- create your .config from scratch;
- get a .config for your kernel version from elsewhere (another one of your machines, perhaps), put it in /usr/src/linux-22.214.171.124/, and edit it if necessary - a good place to start would be the configuration of the Debian stock kernel. This .config file can be found on this Debian site; another place to start would be from this list of SaruWiki .config files;
- get a .config from another (older) kernel version from elsewhere, upgrade it to your current kernel version, e.g. from another machine in your server park, and then edit it some more if necessary.
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.