Reconfigure, build, and install a custom kernel and kernel

Nick Urbanik

Objectives for 1.105.2

What is the kernel?

Compiling a Kernel

Reconfigure, build, and install a custom kernel and kernel

Subtopic Number: 1.105.2 LPIC 102

Nick Urbanik nicku@nicku.org

This document Licensed under GPL—see slide 13

2005 September

Nick Urbanik

Objectives for 1.105.2

What is the kernel?

Compiling a Kernel

Outline

Objectives for 1.105.2 What is the kernel?

Compiling a Kernel Getting the sources

Reconfigure, build, and install a custom kernel and kernel Nick Urbanik Objectives for 1.105.2 What is the kernel? Compiling a Kernel

Description of Objective

1.105.1 Reconfigure, build, and install a custom kernel and kernel

Candidates should be able to customize, build, and install a kernel and kernel loadable modules from source. This objective includes customizing the current kernel configuration, building a new kernel, and building kernel modules as appropriate. It also includes installing the new kernel as well as any modules, and ensuring that the boot manager can locate the new kernel and associated files (generally located under /boot, see objective 1.102.2 for more details about boot manager configuration).

Reconfigure, build, and install a custom kernel and kernel Nick Urbanik Objectives for 1.105.2 What is the kernel? Compiling a Kernel

Key files, terms, and utilities include:

/usr/src/linux/*
/usr/src/linux/.config
/lib/modules/kernel-version/*
/boot/*
make
make targets: config, menuconfig,
xconfig, oldconfig, modules, install,
modules_install dep
depmod

Reconfigure, build, and install a custom kernel and kernel

Nick Urbanik

Objectives for 1.105.2 What is the kernel? Compiling a Kernel

What is the kernel?

▶ The kernel consists of:

▶ the kernel itself:

▶ such as /boot/vmlinuz-2.6.12-1.1447_FC4smp

▶ The kernel modules:

▶ In /lib/modules/$(uname-r)

Reconfigure, build, and install a custom kernel and kernel Nick Urbanik Objectives for 1.105.2 What is the kernel? Compiling a Kernel

Kernel naming conventions

▶ In a name such as vmlinuz-2.6.12-1.1447_FC4smp,

there are the following parts of the name that identify the kernel: major number: here 2

▶ In the Makefile, called VERSION

minor number: here 6

▶ In the Makefile, called PATCHLEVEL

revision: here 12

▶ In the Makefile, called SUBLEVEL

vendor string: here -1.1447_FC4smp

▶ In the Makefile, called EXTRAVERSION ▶ Always change this in the top level makefile if you already have an existing kernel with the same name whose modules you do not want to overwrite

▶ The value that you choose for these variables in the top level Makefile determines what you see when you run the

program uname -r

▶ Consequently also determines the name of the modules directory.

Reconfigure, build, and install a custom kernel and kernel Nick Urbanik

Objectives for 1.105.2 What is the kernel? Compiling a Kernel

Types of Kernel Files

▶ The main kernel file can be produced by make zImage or

by make bzImage

▶ a zImage kernel is limited to about 508 kB in size ▶ a bzImage kernel can be up to about 2.5 MB in size ▶ Both are compressed using gzip compression ▶ the ‘b’ in “bzImage” means “big” rather than indicating bzip2

compression

Reconfigure, build, and install a custom kernel and kernel Nick Urbanik Objectives for 1.105.2 What is the kernel? Compiling a Kernel

Other Kernel Files in /boot

▶ System.map contains the addresses of kernel symbols

▶ Used by tools to interpret kernel error messages or OOPSes, to translate kernel addresses into names that mean more to us humans

    ▶ See http://www.dirac.org/linux/system.map/

▶ The initrd file, which is a compressed filesystem that is

mounted as a ram disk ▶ It contains the drivers (kernel modules) that the kernel

needs to access the hard disk. ▶ The memory used by the initial ram disk is freed up after

the modules have been loaded into the kernel ▶ It is nice to have the kernel .config configuration file

handy so that the administrator knows how the kernel was built

Reconfigure, build, and install a custom kernel and kernel Nick Urbanik Objectives for 1.105.2 What is the kernel? Compiling a Kernel

Kernel Modules

▶ Kernel modules usually provide one of the following: device driver: supporting a specific kind of hardware file system driver: supporting the ability to read/write

different file systems

system call extensions: most system calls are supported by the base kernel, but modules can extend or add system calls

network driver: implement particular network protocols executable loader: support loading and executing

additional executable file formats

Nick Urbanik

Objectives for 1.105.2

What is the kernel?

Compiling a Kernel

Getting the sources

Outline

Objectives for 1.105.2 What is the kernel?

Compiling a Kernel Getting the sources

Reconfigure, build, and install a custom kernel and kernel Nick Urbanik Objectives for 1.105.2 What is the kernel? Compiling a Kernel

Getting the sources

Getting the sources

$ ftp://lftp ftp.au.kernel.org/pub/linux/kernel/v2.6/
cd ok, cwd=/pub/linux/kernel/v2.6
lftp ftp.au.kernel.org:/pub/linux/kernel/v2.6> ls
-rw-rw-r–     1 ftp       ftp          12777 Dec 18  2003 ChangeLog-2.6.0
-rw-rw-r–     1 ftp       ftp         193569 Jan 09  2004 ChangeLog-2.6.1
-rw-rw-r–     1 ftp       ftp        1552868 Dec 25  2004 ChangeLog-2.6.10
-rw-rw-r–     1 ftp       ftp        1495678 Mar 03  2005 ChangeLog-2.6.11
-rw-r–r–     1 ftp       ftp           1221 Mar 09  2005 ChangeLog-2.6.11.1
...
-rw-rw-r–     1 ftp       ftp        4191691 Oct 19  2004 patch-2.6.9.gz
-rw-rw-r–     1 ftp       ftp             248 Oct 19  2004 patch-2.6.9.gz.sign
-rw-rw-r–     1 ftp       ftp             248 Oct 19  2004 patch-2.6.9.sign
drwxrwsr-x     2 ftp       ftp           8192 Dec 19  2003 pre-releases
drwxrwsr-x     4 ftp       ftp          28672 Sep 13 03:05 snapshots
drwxrwsr-x     4 ftp       ftp          24576 Sep 13 13:53 testing
lftp ftp.au.kernel.org:/pub/linux/kernel/v2.6> mget
  linux-2.6.13.1.tar.bz2*
 38375702 bytes transferred in 746 seconds (50.2K/s)
Total 2 files transferred
lftp ftp.au.kernel.org:/pub/linux/kernel/v2.6> bye

Nick Urbanik

Objectives for 1.105.2

What is the kernel?

Compiling a Kernel

Getting the sources

Reconfigure, build, and install a custom kernel and kernel Nick Urbanik Objectives for 1.105.2 What is the kernel? Compiling a Kernel

Getting the sources

License covering this document

Copyright \begin{matrix}c \\ ◯ \end{matrix} 2005 Nick Urbanik <nicku@nicku.org> You can redistribute modified or unmodified copies of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation — either version 2 of the License or (at your option) any later version.