How To make a Kernel on Debian

 

This was originally written by Christoph Schug for the C&W Hosting department,
to ease the installation handling for his collegues. Since I could not find a better
description and couldn't do it better myself 
, you get here the original version:

 

First of all, please check the number of CPUs and the amount of memory.

Ensure that you have a sane root user environment. Especially check the
PATH settings. If unsure, set them

# PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
# export PATH

Go to /usr/src/ and check available disk space. Ensure that at least 250 MB
are available on 
/usr/src/. Also /tmp/ should have at lease some bytes in
spare.

# cd /usr/src/
# df -h . /tmp

Fetch the kernel sources off the FTP server and extract the files. After that,
adjust file ownerships

# wget ftp://ftp.net/pub/linux/kernel/v2.4/linux-2.4.25.tar.bz2
# bzip2 -dc linux-2.4.25.tar.bz2 | tar -xf -
# chown -R root:src linux-2.4.25

Adjust or create the symbolic link /usr/src/linux to point it to the current
kernel sources

# [ -L linux ] && rm -vf linux
# ln -s linux-2.4.25 linux

Enter the kernel source directory and ensure a sane build environment

# cd linux/
# make mrproper

Configure the kernel. There are three alternatives

a) do it from scratch using

# make menuconfig

b) use an existing config from the "old" kernel and only configure options
which has been added with the current kernel release

# cp /boot/config-2.4.24 .config
# make oldconfig

You will be asked about kernel features introduced since your last
kernel revision. Please keep in mind that the default is not always
save. If you're uncertain about a special feature and its setting
please gain further information first instead of doing a "good"
guess.

Optionally, to get a better picture after that, you can

# make menuconfig

to re-check your settings.

c) choose a preconfigured kernel configuration file suitable to your needs

# wget http://up/to/you/.config

Nevertheless you have to run

# make oldconfig

to prepare to kernel source tree for the build.

Build the kernel, choose an appropriate revision name, for example 'neu.0'/

# make-kpkg --revision=neu.0 kernel_image kernel_headers

After the build, take a look at the last lines of output and check that there
were no 'No space left on device' messages.

If something went wrong, clean up the build using and rebuild the kernel
again after you checked the problem which messed up the previous build.

# make-kpkg clean
# make-kpkg --revision=neu.0 kernel_image kernel_headers

After a clean build there should be two resulting Debian packages located
under 
/usr/src/

# cd /usr/src/
# ls -l \
kernel-{image,headers}-2.4.25_neu.0_{all,i386}.deb 2>/dev/null

First, we remove existing kernel header packages. We widen the output by
setting COLUMNS since dpkg sometime chops off the package names if the
columns are not wide enough. After that, remove the resulting package names

# COLUMNS=150 dpkg -l | sed -n 's;^ii *\(kernel-header[^ ]*\).*;\1;p'
# dpkg -r <INSERT-PACKAGE-NAMES-HERE>

FIXME:
# dpkg-query -W --showformat '${Status} ${Package} ${Version}\n' \
kernel\* | grep '^install'

Now we install the new kernel headers

# dpkg -i kernel-headers-2.4.25_neu.0_i386.deb

Next, we are going to install the kernel plus modules. If you already installed
a kernel of the same release (e.g. 2.4.25) you will have to remove it first.
Otherwise there will be file conflicts of the kernel modules located under
/lib/modules/...

To determine a list of installed kernels run

# COLUMNS=150 dpkg -l | sed -n 's;^ii *\(kernel-image[^ ]*\).*;\1;p'

Optionally, remove old kernels and purge old configurations

# dpkg -r <INSERT-PACKAGE-NAMES-HERE>
# dpkg -P <INSERT-PACKAGE-NAMES-HERE>

Install the new kernel and modules using

# dpkg -i kernel-image-2.4.25_neu.0_i386.deb

and confirm when asked whether to run LILO.

Before you reboot, be 100 % sure you have the correct root password for the
case of problems.

Keep in mind that file system checks may be forced after a long
uptime for example which might lead to expanded down time. Use
tune2fs on relevant block devices running ext2/ext3 file systems to
check the current status using

# tune2fs -l /dev/ida/c0d0p10

for example (check 'Mount count' vs. 'Maximum mount count', as well
as current date vs. 'Next check after').

To disable file system checking at all (not tested, might be wrong)

# touch /fastboot

To force file system checks

# touch /forcefsck

Now, reboot :-)

# shutdown -r now

After the reboot compare the number of CPUs and amount of memory the
number you noted at first. Secondly, check all network interfaces using
ethtool(8) and force them to proper settings if required.

For example, force a faulty setted eth0 to 100 Mbit full-duplex

# ethtool eth0
Settings for eth0:

Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Half
Port: MII
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Cannot get wake-on-lan settings: Operation not supported
# ethtool -s eth0 speed 100 duplex full autoneg off