Kernel compile and install on Debian systems

Share your own howto's etc. Not for support questions!

Kernel compile and install on Debian systems

Postby Lavene » 2006-04-05 14:19

Please note: This howto is starting to show some sign of old age. Although most of it still applicable there are more up to date howtos out there. When time permits I'll update this one.
Tina


This HOWTO describes how to compile and install the Linux kernel on Debian systems. The method described in this HOWTO is just one of several approaches one can use and does not claim neither to be the best nor the most effective way to compile the kernel. Although the described method should be safe it's always a good idea to make a backup of important data before doing major changes to the system. This HOWTO is licensed under the terms of the GNU Free Documentation License. It has been written in the hope that it will be useful to the community but it comes with no warranty; use it at your own risk.

Debian GNU/ Linux has a lot of advantages, one of them being the precompiled kernels. This enable users to easily install new kernels without the need to compile. However, sometimes it's necessary to compile a custom kernel and it can seem like a rather daunting task for beginners. But compiling your own kernel is actually not that hard and it is a useful skill to master.

Preparation:
First you'll need to install the necessary tools. You might have some or all of these already installed on your system:
Code: Select all
# apt-get install kernel-package ncurses-dev bzip2 module-init-tools initrd-tools procps


Getting the kernel source:

There are basically two ways to get the kernel source.

From Debian repositories
From kernel.org

From the Debian repositories:
The preferred method of acquiring the kernel source is from the Debian repositories simply by installing it through apt-get:
Code: Select all
# apt-get install kernel-source-x.x.x

A note on Debian kernel naming: The 2.4 and 2.6 kernels in Sarge are named 'kernel-source' whereas 2.6 kernels Etch and onwards are named 'linux-source'. So in order to install the source for kernel 2.4.27 you would do:
Code: Select all
# apt-get install kernel-source-2.4.27

But if you want the source for kernel 2.6.15 you would do:
Code: Select all
# apt-get install linux-source-2.6.15

The source will then be placed in your /usr/src directory as a bz2 archive. So if you installed the 2.6.15 kernel source you will see:
/usr/src/linux-source-2.6.15.tar.bz2

From kernel.org:
The standard kernel is released on http://www.kernel.org/. Kernel.org holds all kernels that has been released plus all patches. If you require the absolute bleeding edge kernel this is the place to get it. Navigate to the kernel you wish to install and download the bz2 archive. For example the kernel 2.6.15.1 will be downloaded from the URL:
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.15.1.tar.bz2

If you downloaded the bz2 archive to your home directory or some temporary folder move it, as root, to /usr/src/

Unpack and configure the kernel:
Now you have the compressed kernel source in your /usr/src/ directory and it's time to unpack it. From now on I'll use the 2.6.15 as my sample kernel through out this howto. You will of course have to substitute that for your kernel.

Change to /usr/src/ (cd /usr/src)
Do
Code: Select all
# ls -la

to verify that the file is indeed where it should be. You should get something like:
-rw-r--r-- 1 root root 39315716 2006-03-06 12:32 linux-source-2.6.15.tar.bz2

So let us unpack our kernel source by entering:
Code: Select all
# tar xjf linux-source-2.6.15.tar.bz2

This may take a few seconds and when it's done, change to the newly created directory:
Code: Select all
# cd linux-source-2.6.15

Now we will configure our new kernel. You have basically two different interfaces to choose from; one text based and one X GUI. (There are a few other ways but for most people the two mentioned here is regarded as the most suitable and 'easy')
Use
Code: Select all
# make menuconfig

for the text based interface or
Code: Select all
# make xconfig

for a X GUI.
Edit: xconfig require a QT library. If you get an error you probably don't have it installed. Install it with
Code: Select all
# apt-get install libqt3-mt-dev
(Thanks to nayoo for pointing that out)
Both do the same job so it's just a matter of taste.

This will bring up the kernel configuration screen.

If you already have a working configuration you only want to tweak a bit you can load it by scrolling down to “Load an alternative configuration file” and enter the path (normally /boot/config.x.x.x).

Now you can scroll up and down, changing the settings you want to change. There is a vast amount of things to include in the kernel but that is outside the scope of this howto. There are however lots of information about the Linux kernel both on the web and in books.

Compile and install the new kernel
When you are done configuring the kernel you can use esc to exit. Answer yes to save the new configuration. To start compiling the kernel issue the following commands:
Note: make dep for 2.4.x kernels only!
Code: Select all
# make dep

Code: Select all
# make-kpkg clean
# make-kpkg kernel_image

(Alternatively you can add a revision flag that will show with uname -r. If you want the revision flag set you issue the command
Code: Select all
# make-kpkg --revision=custom.0.1 kernel_image

The revision flag can be whatever you want, just no 'funny' characters and no spaces)

Now you should see a lot of text flickering by on your screen. This is the compile in progress. Please note that compiling the kernel takes quite some time depending on your system (approx 30-60 minutes give or take) so be patient. And if everything goes well you are rewarded with a nice .deb file in your /usr/src/ that will look something like:
/usr/src/kernel-image-2.6.15_i386.deb

Install the kernel:
Code: Select all
# dpkg -i kernel-image-2.6.15_i386.deb

The kernel will be installed and added to the GRUB bootloader. Now you are basically done unless your system require initrd RAM disk:
Code: Select all
# cd /boot/
# mkinitrd -o /boot/initrd.img-2.6.15 2.6.15

Open /boot/grub/menu.lst in your favorite editor and add the initrd to the new entry added by the kernel installer:

Code: Select all
title      Debian GNU/Linux, kernel 2.6.15-1-486 (on /dev/hda1)
root      (hd0,0)
kernel      /boot/vmlinuz-2.6.15-1-486 root=/dev/hda1 ro
initrd      /boot/initrd.img-2.6.15-1-486
savedefault
boot

Reboot and select your new kernel.

Remember that your old kernel is preserved so if your new kernel for some reason don't work you can always boot your old kernel and investigate what went wrong.

Enjoy!
Tina :)

Edit: Adapted to new Etch release.
Last edited by Lavene on 2008-05-10 05:50, edited 4 times in total.
Lavene
Site admin
 
Posts: 5098
Joined: 2006-01-04 04:26
Location: Oslo, Norway

Re: Kernel compile and install on Debian systems

Postby nayoo » 2006-04-14 03:45

First of all, I would like to thank Lavene for writing this Kernel Compile How To Notes. This is indeed helpful.

By following the steps, I have successfully upgraded my Sarge 3.1 Default kernel 2.4.27-2-386 to 2.6.15.1 within one month after I first installed Debian. (I am a Linux beginner.)
Code: Select all
debian:/# uname -a
Linux debian 2.6.15.1 #1 SMP PREEMPT Wed Apr 12 21:12:29 SGT 2006 i686 GNU/Linux
debian:/#


The following are the add-ons notes from my expereince when trying to download and recompile the kernel.
Lavene wrote:
Code: Select all
# make xconfig

for a X GUI. Both do the same job so it's just a matter of taste.

I did not have QT package in my system. Ref: Forum help. (Thanks lacek) So I installed it.
Code: Select all
apt-get install libqt3-mt-dev


After that, I used the Linux Kernel Configuration Archive website: http://kernel.xc.net/ to determine the correct configuration settings for my new kernel. My purpose of upgrading kernel was that I want to use ALSA so I added it into the kernel and also I removed OSS completely.

However, I got one problem regarding initrd (Initial RAM Disks).
Lavene wrote:Now you are basically done unless your system require initrd RAM disk:
Code: Select all
# cd /boot/
# mkinitrd -o /boot/initrd.img-2.6.15 2.6.15


When I did that, system prompted me the following:
Code: Select all
debian:/boot# mkinitrd -o /boot/initrd.img-2.6.15 2.6.15
/usr/sbin/mkinitrd: /lib/modules/2.6.15: Not a directory
/usr/sbin/mkinitrd: MODULES needs to be set to none?
debian:/boot#
By observation, I realized that I downloaded the 2.6.15.1 kernel form kernel.org http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.15.1.tar.bz2 but not 2.6.15. This time, I added .1 into the command
Code: Select all
debian:/boot# mkinitrd -o /boot/initrd.img-2.6.15.1 2.6.15.1
debian:/boot#
It worked. After that, as for the final step, I modified the /boot/grub/menu.lst as described in Lavene's post.

And rebooted the system and now I am using 2.6.15.1.

Thank you.
N.O
nayoo
 
Posts: 320
Joined: 2006-03-28 01:51

Postby cataract » 2006-05-05 10:55

i usually do the following steps to compile a new kernel.


First become root on the command line and install the necessary tools:
Code: Select all
apt-get install kernel-package ncurses-dev fakeroot wget bzip2


Then go to /usr/src:
Code: Select all
cd /usr/src


Then download the kernel source wou need from:
http://www.kernel.org/pub/linux/kernel/

Code: Select all
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.****.tar.bz2


Then unpack the kernel pack
Code: Select all
tar xjf linux-2.6.****.tar.bz2
cd linux-2.6.***/


If you don't now how to configure the kernel, you can load the configuration from the previous kernel, that works, by making the following:
make menuconfig
then go and Select Load an Alternate Configuration File and enter the location of the configuration file of your current kernel: it will probably be in /usr/src/config-*****

make all the other configurations and then save and exit.

Then start to compile the kernel:

Code: Select all
make-kpkg clean
fakeroot make-kpkg --revision=custom.1.0 kernel_image


When the compilation successfully stops, you will find in /usr/src the kernel image in the folder /usr/src kernel-image-2.6.***_custom.1.0_i386.deb

then

Code: Select all
apt-get update
apt-get install module-init-tools initrd-tools procps


and install the new kernel:
Code: Select all
dpkg -i kernel-image-2.6.***_custom.1.0_i386.deb



And for the last two steps, create a ramdisk of your new kernel ,otherwise your system will most likely not boot:
Code: Select all
cd /boot/
mkinitrd -o /boot/initrd.img-2.6.*** 2.6.***


and last, cheack the /boot/grub/menu.lst

and add the line: initrd /boot/initrd.img-2.6.****
for example:

Code: Select all
  Debian GNU/Linux, kernel 2.6.***
root            (hd0,1)
kernel          /boot/vmlinuz-2.6.*** root=/dev/sda2 ro
initrd          /boot/initrd.img-2.6.***
savedefault
boot

title           Debian GNU/Linux, kernel 2.6.*** (recovery mode)
root            (hd0,1)
kernel          /boot/vmlinuz-2.6.*** root=/dev/sda2 ro single
initrd          /boot/initrd.img-2.6.***
savedefault
boot



then reboot and enjoy.
Debian--Etch
Image
User avatar
cataract
 
Posts: 29
Joined: 2006-03-31 12:24

Postby anon » 2006-05-05 11:29

The official debian kernel handbook http://kernel-handbook.alioth.debian.org/
anon
 

Postby bcinteractive » 2006-05-16 03:17

Hey, I've 'successfully' configured and 'installed' a linux kernel version 2.6.6.16 -- and I can see it in my grub boot loader... But there is kernel panic and the error I read is:

modprobe:FATAL: could not load /lib/modules/2.6.6.16/modules.dep:no such file or directory :!:

What did I miss?

Thanks.
:) Things Change
:) Just Do It
Heavy Gnome Desktop User
http://www.kalantasgardens.com
User avatar
bcinteractive
 
Posts: 275
Joined: 2005-11-03 15:15

Postby Foxmuldar » 2006-05-17 22:41

i did this ; apt-get install kernel-source-2.6.8

and got this: debian:/home# apt-get install kernel-source-2.6.8
Reading Package Lists... Done
Building Dependency Tree... Done
kernel-source-2.6.8 is already the newest version.

please help?

Thanks
foxmuldar,
Foxmuldar
 
Posts: 137
Joined: 2005-12-15 23:46
Location: Alabama

Postby bcinteractive » 2006-05-18 02:17

Foxmuldar wrote:i did this ; apt-get install kernel-source-2.6.8

and got this: debian:/home# apt-get install kernel-source-2.6.8
Reading Package Lists... Done
Building Dependency Tree... Done
kernel-source-2.6.8 is already the newest version.

please help?

Thanks
foxmuldar,


You're probably running Sarge the stable version. If I not mistaken, this means 2.6.8 is the best stable kernel version you'll get from this distribution. However, if you still want to get the 'latest' kernel regardless of Debian Sarge's dependencies -- go to backport.org to get the latest kernel or any other package or debian or go to kernel.org and get the latest there, too.

backport.org has the same style in updating - by using apt -- read its instructions how to set up.

as for kernel.org - manual download and read the instruction in chapter 8 of debian user manual or read the 1st post here.

good luck.
:) Things Change
:) Just Do It
Heavy Gnome Desktop User
http://www.kalantasgardens.com
User avatar
bcinteractive
 
Posts: 275
Joined: 2005-11-03 15:15

Postby Foxmuldar » 2006-05-18 02:23

I already have the latest kernel on my HD, i tried to install and you see what it told me...i rebooted my box, and it showed that i had kernel 2.4. something...
why will it not install the latest kernel?

Thanks,
foxmuldar,
Foxmuldar
 
Posts: 137
Joined: 2005-12-15 23:46
Location: Alabama

Postby Lavene » 2006-05-18 04:17

Have you installed the kernel source earlier and deleted it manually? If so, apt is unaware of it not being on your system. But I think you can work around it with
Code: Select all
apt-get install --reinstall kernel-source-2.6.8


But this is the kernel source as you probably know. It needs to be configured and compiled to actually be installed on your system. If you just want to install a precompiled kernel through apt-get you want a kernel image.

Tina
Lavene
Site admin
 
Posts: 5098
Joined: 2006-01-04 04:26
Location: Oslo, Norway

Postby Foxmuldar » 2006-05-18 14:49

I tried to install the kernel-image and got this:

debian:/usr/src# apt-get install kernel-image-2.6.8.1_custom.1.0_i386.deb
Reading Package Lists... Done
Building Dependency Tree... Done
E: Couldn't find package kernel-image-2.6.8.1_custom.1.0_i386.deb

thanks,
foxmuldar
Foxmuldar
 
Posts: 137
Joined: 2005-12-15 23:46
Location: Alabama

Postby Lavene » 2006-05-19 02:49

Foxmuldar wrote:I tried to install the kernel-image and got this:

debian:/usr/src# apt-get install kernel-image-2.6.8.1_custom.1.0_i386.deb
Reading Package Lists... Done
Building Dependency Tree... Done
E: Couldn't find package kernel-image-2.6.8.1_custom.1.0_i386.deb

thanks,
foxmuldar


You've lost me... that is not a debian package. You can not use apt-get to install files on your hd. Exactly what are you trying to do?
Also post the results of:
Code: Select all
uname -r

and
Code: Select all
ls -l /usr/src/


Tina :)
Lavene
Site admin
 
Posts: 5098
Joined: 2006-01-04 04:26
Location: Oslo, Norway

Postby Foxmuldar » 2006-05-19 02:53

I'm trying to upgade my kernel to 2.6.8,

fm@debian:~$ uname -r
2.4.27-2-386
fm@debian:~$ ls -l /usr/src/
total 79600
-rw-r--r-- 1 root src 10138378 2006-05-18 17:04 kernel-image-2.6.8.1_custom.1.0_i386.deb
drwxrwxr-x 20 500 500 4096 2006-05-18 17:04 linux-2.6.8.1
-rw-r--r-- 1 root src 35628066 2004-08-14 06:13 linux-2.6.8.1.tar.bz2
-rw-r--r-- 1 root src 35628066 2004-08-14 06:13 linux-2.6.8.1.tar.bz2.1
drwxr-xr-x 7 root root 4096 2006-05-17 09:32 rpm
Foxmuldar
 
Posts: 137
Joined: 2005-12-15 23:46
Location: Alabama

Postby Lavene » 2006-05-19 03:59

Ok :)
As root:
Code: Select all
cd /usr/src/
dpkg -i kernel-image-2.6.8.1_custom.1.0_i386.deb


This will install your 2.6.8 kernel. See my original post for making an initrd image if needed.

Tina
Lavene
Site admin
 
Posts: 5098
Joined: 2006-01-04 04:26
Location: Oslo, Norway

Postby Kaitlyn » 2006-05-24 06:32

You don't have to use --revision=custom.0.1 to get a custom version number. While doing my new kernel config, I noticed you can do the same with CONFIG_LOCALVERSION.
User avatar
Kaitlyn
 
Posts: 128
Joined: 2005-12-13 14:35
Location: Big Orange

Package Manager

Postby Foxmuldar » 2006-05-24 13:18

I used Package Manager to upgrade my 2.6.8 kernel to 2.6.14-2-386f

foxmuldar,
Foxmuldar
 
Posts: 137
Joined: 2005-12-15 23:46
Location: Alabama

Next

Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 8 guests

fashionable