Friday, October 9, 2009

Building the Linux Kernel Image

Building the Linux Kernel Image
This section explains the steps taken during compilation of the Linux kernel and the output produced at each
stage. The build process depends on the architecture so I would like to emphasize that we only consider
building a Linux/x86 kernel.
When the user types 'make zImage' or 'make bzImage' the resulting bootable kernel image is stored as
arch/i386/boot/zImage or arch/i386/boot/bzImage respectively. Here is how the image is
built:
1. C and assembly source files are compiled into ELF relocatable object format (.o) and some of them
are grouped logically into archives (.a) using ar(1)
2. Using ld(1), the above .o and .a are linked into 'vmlinux' which is a statically linked, non−stripped
ELF 32−bit LSB 80386 executable file
3. System.map is produced by 'nm vmlinux', irrelevant or uninteresting symbols are grepped out.
4. Enter directory arch/i386/boot
5. Bootsector asm code bootsect.S is preprocessed either with or without −D__BIG_KERNEL__,
depending on whether the target is bzImage or zImage, into bbootsect.s or bootsect.s respectively
6. bbootsect.s is assembled and then converted into 'raw binary' form called bbootsect (or bootsect.s
assembled and raw−converted into bootsect for zImage)
7. Setup code setup,S (setup.S includes video.S) is preprocessed into bsetup.s for bzImage or setup.s for
zImage. In the same way as the bootsector code, the difference is marked by −D__BIG_KERNEL__
present for bzImage. The result is then converted into 'raw binary' form called bsetup
8. Enter directory arch/i386/boot/compressed and convert /usr/src/linux/vmlinux to $tmppiggy (tmp
filename) in raw binary format, removing .note and .comment ELF sections
9. gzip −9 < $tmppiggy > $tmppiggy.gz
10. Link $tmppiggy.gz into ELF relocatable (ld −r) piggy.o
11. Compile compression routines head.S and misc.c (still in arch/i386/boot/compressed directory) into
ELF objects head.o and misc.o

No comments: