SEASON 3
Build linux kernel

Get a copy of source code

Take a copy of the linux kernel source repository via git software
1
git clone --depth=1 https://github.com/torvalds/linux
Copied!
or download a zip file from this link - https://github.com/torvalds/linux/archive/refs/heads/master.zip

Generate .config file

1
make menuconfig
Copied!
Here are the images of the some menuconfig options chosen.
menuconfig
Options
kernel .config support
Module unloading
Kernel Function Tracer
Run make help to get the hints and options for building.

build a image

After that do, make bzImage.
1
/workspace/linux (master) $ make bzImage
2
3
SYSHDR arch/x86/include/generated/uapi/asm/unistd_32.h
4
...
5
GZIP arch/x86/boot/compressed/vmlinux.bin.gz
6
HOSTCC arch/x86/boot/compressed/mkpiggy
7
MKPIGGY arch/x86/boot/compressed/piggy.S
8
AS arch/x86/boot/compressed/piggy.o
9
CC arch/x86/boot/compressed/cpuflags.o
10
CC arch/x86/boot/compressed/early_serial_console.o
11
CC arch/x86/boot/compressed/kaslr.o
12
CC arch/x86/boot/compressed/ident_map_64.o
13
CC arch/x86/boot/compressed/idt_64.o
14
AS arch/x86/boot/compressed/idt_handlers_64.o
15
AS arch/x86/boot/compressed/mem_encrypt.o
16
CC arch/x86/boot/compressed/pgtable_64.o
17
CC arch/x86/boot/compressed/acpi.o
18
AS arch/x86/boot/compressed/efi_thunk_64.o
19
LD arch/x86/boot/compressed/vmlinux
20
ZOFFSET arch/x86/boot/zoffset.h
21
AS arch/x86/boot/header.o
22
CC arch/x86/boot/main.o
23
CC arch/x86/boot/memory.o
24
CC arch/x86/boot/pm.o
25
AS arch/x86/boot/pmjump.o
26
CC arch/x86/boot/printf.o
27
CC arch/x86/boot/regs.o
28
CC arch/x86/boot/string.o
29
CC arch/x86/boot/tty.o
30
CC arch/x86/boot/video.o
31
CC arch/x86/boot/video-mode.o
32
CC arch/x86/boot/version.o
33
CC arch/x86/boot/video-vga.o
34
CC arch/x86/boot/video-vesa.o
35
CC arch/x86/boot/video-bios.o
36
LD arch/x86/boot/setup.elf
37
OBJCOPY arch/x86/boot/setup.bin
38
OBJCOPY arch/x86/boot/vmlinux.bin
39
HOSTCC arch/x86/boot/tools/build
40
BUILD arch/x86/boot/bzImage
41
Kernel: arch/x86/boot/bzImage is ready (#1)
42
/workspace/linux (master) $
Copied!
Note Kernel: arch/x86/boot/bzImage is ready (#1).

Errors

fatal error: libelf.h: No such file or directory
1
/workspace/linux (master) $ make
2
SYSHDR arch/x86/include/generated/uapi/asm/unistd_32.h
3
...
4
DESCEND objtool
5
<stdin>:1:10: fatal error: libelf.h: No such file or directory
6
compilation terminated.
7
HOSTCC /workspace/linux/tools/objtool/fixdep.o
8
...
9
AR /workspace/linux/tools/objtool/libsubcmd.a
10
CC /workspace/linux/tools/objtool/arch/x86/special.o
11
In file included from /workspace/linux/tools/objtool/include/objtool/objtool.h:13,
12
from /workspace/linux/tools/objtool/include/objtool/arch.h:11,
13
from /workspace/linux/tools/objtool/include/objtool/check.h:11,
14
from /workspace/linux/tools/objtool/include/objtool/special.h:10,
15
from arch/x86/special.c:4:
16
/workspace/linux/tools/objtool/include/objtool/elf.h:10:10: fatal error: gelf.h: No such file or directory
17
10 | #include <gelf.h>
18
| ^~~~~~~~
19
compilation terminated.
20
make[4]: *** [/workspace/linux/tools/build/Makefile.build:97: /workspace/linux/tools/objtool/arch/x86/special.o] Error 1
21
make[3]: *** [/workspace/linux/tools/build/Makefile.build:139: arch/x86] Error 2
22
make[2]: *** [Makefile:56: /workspace/linux/tools/objtool/objtool-in.o] Error 2
23
make[1]: *** [Makefile:69: objtool] Error 2
24
make: *** [Makefile:1337: tools/objtool] Error 2
Copied!
Install libelf-dev package

Video