kernel package building

ICMP Request icmp.request at
Tue Jul 10 08:47:29 PDT 2007

Tijnema wrote:
> On 7/10/07, Ross Cameron <ross.cameron at> wrote:
>> Hi all Ive hit a bit of a stumbling block and cant seem to BASH script
>> my way out of it :(
>> As most of you will know when building binary packages for UNIX-like
>> systems the output of
>>         make install
>> is usually re-directed using something akin to
>>         make DESTDIR=<some temp folder> install
>> And then that temp folder is tarballed up, or what ever compression
>> the package manager uses, and a binary package is created from this.
>> I've tried this approach (and several variants of it) to attempt this
>> with the vanilla kernel sources from and its not
>> co-operating with me.
>> The guys at redhat/fedora use a whole lot of "cp" commands in their
>> kernel spec file to accomplish this but isn't there a simple way of
>> re-directing the kernel's Makefile's logic that says everything must
>> be installed under / ??????????
>> Any and all thoughts appreciated....
>> Ross
> Did you ever run a make install on the kernel? I don't think so...
> Just note what you install with a kernel, that is
> a) The headers (already installed before Glibc, and should be upgraded
> together with glibc)
> b) The kernel itself (arch/i386/boot/bzImage)
> c) If any, the modules that are compiled
> d) Optional, but recommended as in the LFS book, the and
> .config files
> e) Optional, the documentation
> Tijnema

Hello Ross! Well, I'll tell you exactly what I do to compile a new kernel:

1. Download the source from[version]

(Note that it's the kernel itself [linux-x.y.z.tar.gz/.tar.bz2] not the


2. Extract it to a dir, usually under /usr/src:

bash# cd /usr/src
bash# tar -zxf linux-x.y.z.tar.gz

(if it's a .tar.bz2, use 'tar -jxf')

OPTIONAL: Make a Symlink to "Linux" and remove any other previously created:

bash# rm -f linux
bash# ln -s linux-x.y.z linux

3. CD to the dir:

bash# cd linux
bash# make mrproper
bash# make clean && make distclean

make mrproper, make clean and make distclean clear any pre-made actions
to the kernel source. You don't really need this all because:

1. You just extracted the source.
2. Even if not, make 'mrproper' would be enough

But hey, I'm a cleaning paranoid! ^^

3.1 IF creating a brand new config:

bash# make allnoconfig

Usually, when you use 'make config' without this and without a config
file, the kernel comes with many pre-made supports. But if you are
building LFS I assume you want the kernel specifically for your
hardware, with nothing else. So by default all the many options are
"no". This can give you size and performance, together with a "clean"

bash# make menuconfig

The kernel has made a .config file (the configuration that your kernel
will use to build all the support and options). But the file is "all
no". Go through the menus and enable the options that most fit your
system. Specifically you can take a look at any dist. sample config file
to see what they got if you have doubt about enabling a feature or not.
This can be found on /proc/config.gz (needs to be gunzipped),
/boot/.config, /boot/config-xxx or /usr/src/old-kernel/.config . Also be
aware that there is a help feature for almost every item and the
recommendations about activating it or not (just go on "help" when
inside the item or press "h")

Items can be configured as modules or built-in. Modules are like
"hotplug" supports that kernel only loads when it needs. This is
generally a good idea, IMHO, to set everything possible as modules, but
there are some exceptions like the support for your root partition
(ext2, ext3, reiserfs, xfs, etc.) and your hard disk drivers.

3.2 IF creating through an old config file:

bash# make oldconfig
bash# make menuconfig

(Check for any updates or additional items you wish to enable or not)

(I'm not sure about this "3.2" item so I may be wrong hehehe)

4. Done! Now compile your kernel:

bash# make

5. Install the modules:

bash# make modules_install

The modules will be installed on /lib/modules/your-kernel-version

6. Make the kernel image and copy it to /boot, together with

bash# make bzImage
bash# cp arch/[your_arch]/boot/bzImage /boot/kernel-x.y.z
bash# cp /boot/

OPTIONAL: Copy your config file:

bash# cp .config /boot/config-x.y.z

7. Copy the kernel headers to /usr/include:

7.1 Using raw kernel headers (I do not recommend):

bash# cp -rp include/{asm-generic,asm-[your_arch],linux,mtd,scsci,sound} 

7.2 Using CLFS Headers (I recommend):

So far, the raw kernel headers are known for not being stable. There's a 
lot of discussion about this. CLFS is known for making sane headers so I 
recommend you to check the linux-headers-xyz package from:

It's RECOMMENDED that you do use the same headers-xyz version as your 
kernel version. See why I wanted you to read this before downloading the 
kernel? ;)

Untar, gunzip/bunzip it and copy the includes from the source of this 
package rather than the kernel ones to the same dir: /usr/include/

8. Making the needed symlinks:

bash# cd /usr/include
bash# ln -s asm-[your_arch] asm
bash# cd /boot

Usually, 'vmlinuz' is the alias used for kernel so backup your old and 
create a new one,:

bash# mv vmlinuz vmlinuz-old

(if you haven't vmlinuz and it outputs an error just ignore it)

bash# ln -s kernel-xyz vmlinuz

OPTIONAL: Create a symlink to the .config file:

bash# ln -s config-xyz .config

9. Your done! (?)

I think you're done now, just make sure to point to the right kernel in 
your bootloader config (/boot/grub/menu.lst for grub, /etc/lilo.conf for 
lilo). Either point it to kernel-xyz or, better, vmlinuz . If it's 
already pointed to vmlinuz no change is needed.

OPTIONAL: Make a failsafe option to your old vmlinuz for you to boot 
your system if your new kernel doesn't work. Just add a new entry just 
like the same for your kernel but point it to vmlinuz-old or the old 
kernel image it was used on /boot . If anything "evil" happens, you can 
still boot your old kernel one.

10. Reboot:

bash# reboot


11. Most 2 common problems I find:


"Kernel panic: unable to mount root fs on unknown-block..."

1. Check your bootloader config file if it's pointed for the right 

2. Check if the support for your root partition (ext2, ext3, reiserfs, 
xfs, etc.) and for your hard disk drivers are enabled as built-in and 
not as a module.*


The screen goes dark after booting:

Check if you are using framebuffer and if the support was enabled on 
kernel, together with the right driver for your video card.

*You may optionally use an initrd which loads the modules but it is, 
IMHO, the most complicated path if you really have no onther reason for 
using an initd.

This is just how I do it and it works fine for me. There are many other 
ways to compile the kernel.


ICMP Request - Don't forget to call me when you ping!

Mail/MSN: icmp.request at

x86 Intel Prescott 32-bit Platform - Linux

Registered Linux User #449464

More information about the lfs-support mailing list