Fast and easy kernel rebuild guide for a 2.6 Linux kernel the right way in Slackware
(a few of the last bits are Slackware Linux specific).
-----[This should be executed as a regular user]-----
1 - download the kernel source from http://kernel.org/mirrors/
2 - extract the kernel source in your /home directory
example: /home/mingdao/kernel/linux-2.6.32.2/
3 - unpack the source: tar -xf linux-2.6.32.2.tar.bz2
4 - cd into your kernel source directory and run "make xconfig"
(see the different choices in ./linux-2.6.x.y/README)
5 - configure all the kernel options to suit your needs
6 - save the kernel
7 - run "make -j3" (still as a normal user)
8 - su to root
-----[do the following steps as root]-----
9 - copy the new .config file to /boot
"cp .config /boot/config-2.6.32.2"
10 - copy the System.map file to /boot as System.map-kernel-version:
"cp System.map /boot/System.map-2.6.32.2"
11 - run "make modules_install" which will install the modules for the new kernel
to /lib/modules/$VERSION
12 - Now copy the kernel itself to /boot under some new name:
"cp arch/x86_64/boot/bzImage /boot/vmlinuz-2.6.32.2"
13 - Edit "/etc/lilo.conf" and add a new section for your new kernel similar to this:
image = /boot/vmlinuz-2.6.32.2
root = /dev/sda6
label = Slack-2.6.32.2
read-only # Partitions should be mounted read-only for checking
(Leave the old one in place as a fallback option. Your entry will be different if
you have a different root partition, etc.)
14 - Run "lilo" and add it to the bootloader.
That's my entry for my current 2.6.32.2 kernel in /etc/lilo.conf.
-----
OTHER USEFUL ENTRIES FOR /etc/lilo.conf:
You'll also want to make sure LILO has a timeout to allow you to pick the kernel you
want to boot (btw, the first one listed is the default kernel). So be certain you
have a line such as this one:
timeout = 50
The convention is that number divided by 10 = seconds, so that will give you a 5
second time period to choose which kernel to boot. If you feel you need more time,
just multiply the seconds you want by 10 and change this accordingly. If you prefer
to have a kernel other than the first entry as the default, you must add:
default=<label>
to /etc/lilo.conf, where label is the name of the desired default kernel.
If you have a kernel panic, after reading the message you must either press the
reset switch if you have one, or power off the computer if you don't. By adding:
append="panic=10"
to /etc/lilo.conf, you system will be rebooted in 10 seconds. This gives you time
to read the message relating to the kernel panic, so that you can boot into your
old kernel and fix the problem. (You did save your old kernel, didn't you?)
Also, make sure you have this line:
prompt
which will cause LiLO to show a menu with your kernel choices.
Now you should be able to reboot and select either your old kernel or the new kernel,
so if the one you just built won't boot, you can boot into your old kernel and fix
whatever is wrong with your new kernel. Always keep a working kernel in place. It
doesn't neccessarily have to be the kernel you installed with, but that one is always
left in place on my systems. I think it's good practice, because it's using the original
kernel headers and glibc your system was built with.
And just in case something goes badly wrong and neither your old nor new kernel will
boot, you can always use the Slackware CD1 to boot the installed system. Then at the
boot: prompt enter:
"hugesmp.s root=/dev/sda6 rdinit= ro"
where /dev/sda6 should be *your* / (root) partition.
NB: When you install Slackware, you should make a note/file where you list some
important things about your installed system, such as the partition table. So you
will know which partition contains your / (root) filesystem, for instance. ;)
-----
OTHER NOTES:
With the 2.6 kernels, make will build the kernel and all modules (for stuff you chose
to build as modules). Once it's done (hopefully without errors) it's time to install
the new kernel and associated modules. To do that you need to be root, so use "su" to
become root and you'll be in the same directory.
NB: If this is the first time for you to (re)build a kernel, I recommend you
read the help entry for every option. Yes, this will take hours, maybe even days,
but you will gain valuable knowledge; and it will ensure that you have a better
chance of getting a working kernel afterwards. You will learn about the many
kernel options, especially as they relate to your hardware. You'll also learn
more about _your_ hardware, in addition to hardware that you don't have.
Don't forget to build in (Y or check mark) support for your / filesystem, *NOT*
as a module (M).
(If you have a configuration file from an older, custom 2.6 kernel that you wish
to use as defaults - then you can copy that file to .config in your new kernel
source dir - i.e.: "cp /path/to/old/.config ~/kernel/linux-2.6.32.2/.config"
and then you can run "make silentoldconfig" to update it for the new kernel
version. Using the "make silentoldfconfig" option will _only_ ask you to make
choices about options that are new or have changed. If you make any changes, it
will overwrite .config with a new version suitable for the new kernel version.
Some people will advise you to use the kernel config file from your Slackware
system found at /usr/src/linux-2.6.x.y/.config as a starting place. You can do
this if you desire. However, those config files are huge. If your source there
is a huge*.s kernel, it will be over 4M and have almost everything possible
built into the kernel. If it is a generic kernel, it will be over 2M and have
almost everything possible built as a module. Neither one of those kernels is
a "custom" kernel. They are built to attempt to accomodate a very wide range of
present computer hardware. The philosophy behind such kernels is not what we are
thinking of when we build a "custom" kernel for our particular machine. Anyone
who tells you "that's not necessary today" has very limited experience and
understanding of building kernels. To use one of the default Slackware kernels as
a starting point to build a custom kernel is less desirable than using the source
from kernel.org as your starting point. If, however, you just want to get the new
kernel source installed with the least amount of work, you can use one of the
config files from your Slackware system. Even so, you still need to read all of
the [NEW] options in the kernel configuration and select appropriate choices.
Also, if you've never built a kernel and want to use the kernel you're running
now as a starting point, that is a good place to start. Issue:
zcat /proc/config.gz > 2.6.32.2.config
which will create the file 2.6.32.2.config from your running kernel. You
can change the name - I used the one with Slack-13.0 as an example. Either cat
it to ./linux-2.6.32.2/ as .config to begin with, or cp it there. Then run
"make oldconfig" and answer questions about NEW options. If you want to make more
changes, then run "make menuconfig" after you finished the first one and change
whatever you need.
Please do *NOT* use a configuration file from a 2.4 kernel for a 2.6 kernel. The
resulting configuration file is most likely to be subtly broken and the kernel
build as a result will most likely not work correctly.
Don't forget to read the README file in the top of the kernel source directory
for additional instructions. Also read Documentation/Changes for requirements.
I choose to build kernels under /home because that way I'm not going to mess
up anything in /usr/src/ and it will stay the same as it came with the install
of Slackware. Plus, my ~/ is backed up to the server every night, so I always
have my old kernel(s). And building under ~/ there is no need to su to root
until you install the kernel. You can take as long as you want configuring
and building it as a normal user.
Another great book that has come out since I first wrote this is here:
http://www.kroah.com/lkn Linux Kernel in a Nutshell, by Greg Kroah-Hartman
If you need help /join ##kernel on irc.freenode.net
-----
CREDIT:
This guide was adapted from Jesper Juhl's Kernel-2.6-Quick-Build-Guide:
http://www.chaosbits.net/Articles/Historical/Kernel-2.6-Quick-Build-Guide/
2006-12-02 by Bruce Hill, Jr. <bruce at slackwarebox dot com>
Last edited 2009-12-26