rlh   img   mp3   nfo   pro  
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).

2006-12-02 by Bruce Hill

-----[This should be executed as a regular user]-----
1  - download the kernel source from http://kernel.org/mirrors/
2  - save the kernel source in your /home directory
     example: /home/mingdao/kernel/
3  - extract the source: tar -xf linux-
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" (still as a normal user)
8  - su to root
-----[do the following steps as root]-----
9  - copy the System.map file to /boot as System.map-kernel-version and update the
     /boot/System.map symlink:
     "cp System.map /boot/System.map- ; ln -sf /boot/System.map- 
10 - run "make modules_install" which will install the modules
     to /lib/modules/$VERSION
11 - Now copy the kernel itself to /boot under some new name:
     "cp arch/i386/boot/bzImage /boot/vmlinuz-"
12 - Edit "/etc/lilo.conf" and add a new section for your new kernel similar to:
     image = /boot/vmlinuz-
       initrd = /boot/
       root = /dev/cryptvg/root
       label = Slack-
       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.) Now run "lilo" and
     add it to the bootloader.

That's my entry for my current kernel in /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=15" to /etc/lilo.conf, you system will be rebooted in 15 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. ;)

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. Then issue "make
modules_install"  to install your new Linux kernel. Other than copying the links,
and running "lilo"  after editing /etc/lilo.conf, those are the only 2 commands
you need with 2.6 kernels.

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. You can also read
the Changelog in the new kernel source.

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.26/.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. There are at least 4 of them in the /boot/ directory to
choose from. 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 >
.config which will create the file .config from your running kernel. Then run
"make xconfig" and change options to suit your computer.

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. And for
all of those of you who *still* wrongly think that you need your new kernel's
header files in /usr/lib/include etc, please stop that. The kernel headers in that
location and elsewhere should match your *glibc*, so leave the kernel headers your
distribution put in place alone - and read the following link if you doubt me on
this point: http://uwsg.iu.edu/hypermail/linux/kernel/0007.3/0587.html

Some people will tell you it doesn't matter where you build your kernel, because
of the way Slackware's kernel headers and glibc package are setup. They will also
tell you that's a 5 year-old post by Linus. However, he still builds kernels under
/home, and he still has that advice in the latest kernel source README file. If
you don't build new kernels under /usr/src/, you won't mess up the original one.

mingdao@silas:~$ less kernel/linux-2.6.26/README
[quote]INSTALLING the kernel:

 - If you install the full sources, put the kernel tarball in a
   directory where you have permissions (eg. your home directory) and
   unpack it:

                gzip -cd linux-2.6.XX.tar.gz | tar xvf -

                bzip2 -dc linux-2.6.XX.tar.bz2 | tar xvf -

   Replace "XX" with the version number of the latest kernel.

   Do NOT use the /usr/src/linux area! This area has a (usually
   incomplete) set of kernel headers that are used by the library header
   files.  They should match the library, and not get messed up by
   whatever the kernel-du-jour happens to be.[/quote]

You can check the Changelogs at kernel.org, and the LKML for posts by other kernel
developers, and you will see their kernel build $PATH is under /home.

Another great book that has come out since I first wrote this is here:
url=http://www.kroah.com/lkn Linux Kernel in a Nutshell, by Greg Kroah-Hartman


This guide was adapted from a guide posted by Jesper Juhl. Since that link is
broken, and I can't refer to it anymore, this is hopefully a fair substitute.

2006-12-02 by Bruce Hill, Jr. <bruce at slackwarebox dot com>
Last edited 2008-08-10