How To Compile A Kernel - The Debian (Sarge) Way - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Tue, 2006-12-05 16:33. ::

6 Build The Kernel

To build the kernel, execute these two commands:

make-kpkg clean
fakeroot make deb-pkg

Now be patient, the kernel compilation can take some hours, depending on your kernel configuration and your processor speed.

 

7 Install The New Kernel

After the successful kernel build, you can find your kernel .deb package in the /usr/src directory.

cd /usr/src
ls -l

On my test system it was called linux-2.6.18.3-default1_2.6.18.3-default1_i386.deb. I install it like this:

dpkg -i linux-2.6.18.3-default1_2.6.18.3-default1_i386.deb

(You can now even transfer the .deb file to other Debian Sarge systems and install it there exactly the same way, which means you don't have to compile the kernel there again.)

 

8 Create A Ramdisk

Now we must create a ramdisk for our new kernel. Normally we do this with mkinitrd, but our new kernel uses udev instead of devfs, and you'll most likely get this error message with an mkinitrd generated ramdisk during boot-up:

mount: unknown filesystem type 'devfs'

which might lead to a kernel panic.

The new way of creating ramdisks is with mkinitrd.yaird. Backports.org has a yaird package for Debian Sarge. Before we can install it, we must install two prerequisites:

apt-get install libhtml-template-perl libparse-recdescent-perl

Then we install yaird like this:

cd /tmp
wget http://downloads.howtoforge.com/files/yaird_0.0.12-8bpo1_i386.deb
dpkg -i yaird_0.0.12-8bpo1_i386.deb

(The original yaird package was located in http://backports.org/debian/pool/main/y/yaird/, but was removed in the meantime, so I've made the package available under http://downloads.howtoforge.com/files/yaird_0.0.12-8bpo1_i386.deb.)

Before we can create the new ramdisk, we must edit the configuration file of our new kernel which you can find in the /boot directory (run

ls -l /boot

to find out). In this tutorial it's called /boot/config-2.6.18.3-default1, and in that file we must comment out the line CONFIG_DEFCONFIG_LIST (towards the beginning of the file) because otherwise mkinitrd.yaird will throw an error like this at us:

yaird error: bad value in /boot/config-2.6.18.3-default1: CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" (fatal)

So we do this:

vi /boot/config-2.6.18.3-default1

[...]
# CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
[...]

Now we can finally create our ramdisk like this:

mkinitrd.yaird -o /boot/initrd.img-2.6.18.3-default1 2.6.18.3-default1

 

9 Configure The GRUB Boot Loader

Now we must configure our GRUB boot loader so that our new kernels gets booted when we restart the system. This is very easy, just run

update-grub

You can check /boot/grub/menu.lst to see if your new kernel has been added:

vi /boot/grub/menu.lst

It should look like this now (you should find two stanzas for your new kernel at the top of the kernel stnazas list):

# menu.lst - See: grub(8), info grub, update-grub(8)
#            grub-install(8), grub-floppy(8),
#            grub-md5-crypt, /usr/share/doc/grub
#            and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
default         0

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout         5

# Pretty colours
color cyan/blue white/blue

## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line)  and entries protected by the
# command 'lock'
# e.g. password topsecret
#      password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret

#
# examples
#
# title         Windows 95/98/NT/2000
# root          (hd0,0)
# makeactive
# chainloader   +1
#
# title         Linux
# root          (hd0,1)
# kernel        /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specifiv kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
# kopt=root=/dev/sda1 ro

## default grub root device
## e.g. groot=(hd0,0)
# groot=(hd0,0)

## should update-grub create alternative automagic boot options
## e.g. alternative=true
##      alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
##      lockalternative=false
# lockalternative=false

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
##      altoptions=(recovery mode) single
# altoptions=(recovery mode) single

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
##      howmany=7
# howmany=all

## should update-grub create memtest86 boot option
## e.g. memtest86=true
##      memtest86=false
# memtest86=true

## ## End Default Options ##

title           Debian GNU/Linux, kernel 2.6.18.3-default1
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18.3-default1 root=/dev/sda1 ro
initrd          /boot/initrd.img-2.6.18.3-default1
savedefault
boot

title           Debian GNU/Linux, kernel 2.6.18.3-default1 (recovery mode)
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18.3-default1 root=/dev/sda1 ro single
initrd          /boot/initrd.img-2.6.18.3-default1
savedefault
boot

title           Debian GNU/Linux, kernel 2.6.8-2-386
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.8-2-386 root=/dev/sda1 ro
initrd          /boot/initrd.img-2.6.8-2-386
savedefault
boot

title           Debian GNU/Linux, kernel 2.6.8-2-386 (recovery mode)
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.8-2-386 root=/dev/sda1 ro single
initrd          /boot/initrd.img-2.6.8-2-386
savedefault
boot

### END DEBIAN AUTOMAGIC KERNELS LIST

 

10 Reboot

Now reboot the system:

shutdown -r now

If everything goes well, it should come up with the new kernel. You can check if it's really using your new kernel by running

uname -r

This should display something like

2.6.18.3-default1

If the system doesn't start, restart it, and when you come to the GRUB boot loader menu, select your old kernel and start the system:

You can now try again to compile a working kernel. Don't forget to remove the two stanzas of the not-working kernel from /boot/grub/menu.lst.

 

11 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Mathieu (not registered) on Tue, 2010-09-28 20:19.

Hello,
the more "Debian way" (that means using very stable and *too* much tested packages) would be to use "initramfs-tools".
I actually avoid the most that I can to use packages not coming from main / contrib / non-free. You frequently end with problems at the end because of the libraries needed in a newer version.
 I had my ramdisk image for my custom kernel done with update-initramfs.


  1. Change directory to "/boot"
  2. update-initramfs -c -k 2.6.35-default1 (or whatever you called it)
  3. "update-grub"

initramfs-tools were already there on my today installed Debian.Otherwise, simply "apt-get install" it.
 You said to delete the older/official kernel, at least its entries in the grub configuration file. I always keep the newer official kernel from Debian. Just in case I missed a checkbox before compiling my custom kernel.
Note that you can also use "make xconfig" to get a GUI. (You probably need libqt4-dev for that)