How to Compile your own Kernel in SAM Linux

For most, this is not necessary. However, sometimes the default kernel doesn't support certain pieces of hardware (like my mobo), so compiling a new kernel is needed. For this guide, I will use the plain vanilla sources from, but you could use the pre-patched kernel-source from the repo's as well.

Installing compiler tools

The first thing that is needed is a compiler. Open synaptic (or via apt-get on the CLI) and install the package "rpmbuild". It contains everything you will need to complete the compile.

Getting the source

Now to get the source code, go to and, assuming you want the latest version of the kernel, on the front page is a link to the latest full sources (make sure you get the full… the archive you download should be about 41 MB). If you need an older version please browse the mirror on top of the page. Untar/zip this into the folder /usr/src. If there is a symlink /usr/src/linux, rename it linux.old (if you fail on the compile and don't use the new kernel, you should restore this link later). Now create a new symlink /usr/src/linux to the folder you just untarred (/usr/src/linux- in my case).

Configuring the kernel

Here comes the tedious part. This is where you configure all the options that will be built into your kernel. You have the option of trimming it to leave out what you do not need (should increase system responsiveness), or also adding whatever it is that you do need. These first two commands are supposed to get the config files for the current kernel as a place to start. I was running a Fedora kernel from another partition so this did not work for me, but as it gives you a nice place to start from, I am including it. Also note that if this fails, you just have to configure the whole thing, its not that big of a deal. From here on out, unless specified, all commands are run while you are in the folder /usr/src/linux, and that you will have to be root (use "su -" not "su" so you are actually root, not just having root's powers) to work in this directory.

make clean && make mrproper
cp /boot/config-`uname -r` ./.config

Now this command will start the config dialog:

make menuconfig

You will now go through and select the options you want… there are a lot. I try to hit every category to at least look at them, but it can take forever, so I tend to skip over sections that don't affect me. A couple things… make sure that you include support for all your devices (graphics - if using nvidia proprietary drivers don't select framebuffer support, ethernet card, sound, etc.). Also, in the filesystems section you MUST select the type of filesystem root is on to be compiled directly into the kernel, and not as a module (otherwise it won't be able to mount it to get to the module). If you are ever unsure, select the help option and it usually recommends what to do if you are don't know. Ok, once that is done exit and save.

Compiling the Kernel

We are ready to compile and build the rpm's. Run this command to do the build:

make rpm

Thats it. It will do its thing and take anywhere from 20 minutes to two hours, depending on your processor and the options you selected.

Installing the new kernel

Ok, once you get your prompt back, scroll up a little and it should tell you where the RPMs it made are. There is a source RPM which you don't need (you already have the source installed) and the kernel RPM. My kernel RPM was located at /usr/src/rpm/RPMS/i386/. Cd to this directory and then install the RPM with this command (substituting your RPM file for mine):

rpm -ivh kernel-

This command should build the new initrd. This failed for me, but I used the file generated by the RPM instead and it worked fine. If it doesn't work for you and you need an initrd, there is probably a package to install the tool to build this

mkinitrd /boot/initrd-

This probably won't build a grub entry, so you will need to edit grub to boot it. Open the file /boot/grub/menu.lst and copy the entire entry pertaining to your current kernel, but change any references to the old kernel to the new one. DO NOT OVERWRITE THE CURRENT ENTRY UNTIL YOU KNOW THE NEW KERNEL WORKS PROPERLY. Change the intrd file in the same way (if your mkinitrd failed before, use the proper file instead). Make sure you also give it a different title so you can differentiate it on the list. Save and exit.

Success!!! (hopefully)

Ok, that should be it. Time to cross your fingers. Save your work and reboot. When grub comes up, select your new kernel, and if all went well it will be smooth sailing. If you get errors on boot up, reboot to your old kernel and it will work fine. Try #sam-linux on or the SAM forums for help.

A few more notes

If you use any proprietary drivers that have their own kernel modules you will need to reinstall them (MadWiFi, ndiswrapper, NVIDIA etc.). In fact if you are using the NVIDIA driver X will fail to load. You need to install these drivers manually as well. Since the repo's contain kernel modules prebuilt for the kernels in the repos, if you use a custom kernel you need to build the modules/drivers yourself.

I hope this was helpful, if you need more assistance try #sam-linux or our forums!

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.