Tuesday, March 31, 2009

How to compile a slackware kernel

There are many reasons to build a new kernel in a distro like slackware. It could be that you bought a new usb camera or printer that the new kernel supports. Or perhaps a newer kernel has better support for your wifi card. Whatever the reason, we'll cover here how to build the latest and greatest on your box. At the time of this writing it's the first release of the 2.6.29 tree.

The first thing we need to do is to download the source from kernel.org. The 2.6 tree is found here.

Scroll down to the desired version to be compiled and select "copy link location". Then open a terminal and become root and change to your build environment. We'll use /usr/src as the default.

su -
cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.29.tar.bz2

now we need to unpack the tar ball.

tar -jxf linux-2.6.29.tar.bz2

Next we're going to remove the current symlink to the linux directory and link to the new directory.

rm linux
ln -s linux-2.6.29 linux

Now we'll move into the build directory.

cd linux

To get this far means that you have a working kernel. So we're going to utilize the current kernel config to build our new kernel.

zcat /proc/config.gz > .config
make oldconfig

New additions to the kernel will be displayed and you can choose which ones you want to keep and in what form. It will ask you to keep them in module form (m), or you can select y for it to be built in to the kernel, or n for it to be left out. Simply hitting enter will do the default action, which the dialog will tell you what that is.

Next we can alter anything we want in the kernel itself.

make menuconfig

There are a couple of things I always change here. One is the processor support. Scroll to processor type and features, and then processor family. For my celeron M on this laptop I pick the pentium M option. For my core 2 duo system, I choose the core 2/ newer xeon option.

We then exit from the processor type and features menu back to the main menu.

Next we scroll down to Device Drivers and select it. Then we select usb support. Finally we modularize "USB Mass Storage Support" by pressing "m" while it is highlighted.

We click exit to exit out of our submenus all the way back to the main menu. Hitting exit one more time, will ask if you want to save the kernel configuration, to which we reply yes.

Now we want to build the kernel so we type

make all

This can take a while, depending on your processor, so grab a cup of coffee, read the paper and come back in a little while.

Once that completes, we'll grab a nice script by Dagmar to install the kernel in /boot.

wget http://dagmar.droplinegnome.org/experimental/installkernel
install -m 755 installkernel /sbin/

Then we execute the following to be able to use the new kernel

make modules_install
make install

These commands will install the new modules and copy the config, system.map, and kernel to the proper locations in /boot.

now we'll change to the /boot directory to modify a few things.

cd /boot

It's time to remove the current symlinks to config, System.map, and vmlinuz.

rm config
rm System.map
rm vmlinuz

and then link them to the new kernel.

ln -s config-2.6.29-smp config
ln -s System.map-2.6.29-smp System.map
ln -s vmlinuz-2.6.29-smp vmlinuz

At this point it's a good idea to create an initrd. For ext3 we use the following command. Note that sda3 is my root partition. be sure to alter yours accordingly.

mkinitrd -c -k 2.6.29-smp -m mbcache:jbd:ext3 -f ext3 -r /dev/sda3

For reiser it would be

mkinitrd -c -k 2.6.29-smp -m reiserfs

next, we'll edit lilo to use the initrd.gz. we add the following line above "root = /dev/sda3"
initrd = /boot/initrd.gz

so it will look something like this.

image = /boot/vmlinuz
initrd = /boot/initrd.gz
root = /dev/sda3
label = Linux

Now we need to run lilo to update it.


That's it. upon rebooting you should now be utilizing your shiny new 2.6.29 kernel. If you somehow messed something up, and you end up with a kernel panic, you can use your slackware 12.2 cd to boot your system in a pinch.

Good luck and happy slacking!

I borrowed heavily from this excellent guide on the dropline wiki.


Anonymous said...

Thanks a lot for this. I am using Slackware for quite a long time, maybe 3 years, and more and more I see that issues like the whole kernel thing are as easy as I never expected... looking forward for more inputs :-)

Salutations and keep up the great work

Anthony said...

Thanks, best tutorial ever, AND IT WORKS. I've tried compiling a new kernel in slackware about 20-30 times, every time there was a new error, now i succeeded.

Thanks again! :)

harley said...

Much thanks for this. I'm in the middle of an issue with my Atheros AR9280 wireless card and thought re-compiling the kernel could help (hasn't produced yet). But, this tutorial got me through building a new kernel and is appreciated. One thing I'm confused about is, when is that installkernel script being utilized. Is it used by 'make install' at some point? I never called it directly and everything seems to be going smooth. And a note to nvidia card users: If you use the drivers from nvidia download the latest drivers from nvidia and compile them against the new kernel (I did this after reboot, but I'm sure there is a way to get it done before).

marquisor said...

a small addition you should mention. "make -j X all", where X means number of jobs, i.e. number of CPUs used.
on a quadcore it's faster. and a kernel takes some time! why not at least half it on quadcore and a speedup on dualcores.

muaythaimaster said...

Marquisor has a nice tip regarding make and multicore processors... at the time that I wrote this guide, I was using single core processors.

Anonymous said...

Highly useful, thank you very much!

(although my slack install didn't include cpio and had to install in order for mkinitrd to work, which incidentally created a ramdisk to large for lilo, so i omitted that option from my lilo.conf and all is rosy)

Anonymous said...

Thanks a lot!

Your post is still relevant and highly useful today. With some modifications I was able to make this work for kernel 2.6.39-4. I'm using the ext4 filesystem so I tinkered the initrd command a bit...

mkinitrd -c -k $(uname -r) -f ext4 -r /dev/sda7 -m crc16:jbd2:mbcache:ext4 -o /boot/initrd-$(uname -r).gz

(source: http://www.linuxquestions.org/questions/slackware-14/dev-root-with-ext4-fs-being-mounted-as-ext2-fs-797354/)

The script you linked was unfortunately not available (is it down forever?) ... You may want to update this for future readers. I fortunately was able to find a copy at archive.org ...


First kernel compile ever, and your post helped a tonne. Cheers :)

muaythaimaster said...

Thanks for the props! I'm glad it was helpful to ya.. it's been a while since I've been involved in the slack community, so thanks for giving the update on how to utilize with ext4, and the link to dagmar's script. I'll update the original post with the new info when time permits... thanks!

Unknown said...

I looked all over the net for a correct slackware kernel compile guide. For years I used to compile my own kernels. I've gotten lazy and forgotten how to do it. Your guide is the right stuff, the way I remember. It's frustrating to know that I forgot how and that other guides had a lot of unnecessary steps. Unnecessary steps that are very unslackware. Again thank you.

Anonymous said...

Thank you, I've flopped from Slack to Kali many times in 2013, having used Slack years ago (1994-1999) when ext2 was the standard. Flusterated, I flip between both flavours as I am ... flustered. This information is correct and standard!