Professional Documents
Culture Documents
3 - Build and Recompile Kernel
3 - Build and Recompile Kernel
• Step 3: Build the kernel’s loadable modules and Device Tree Blobs ->
create compressed kernel image file ([b|z|u]image), uncompressed
kernel image (vmlinux), system.map, kernel module objects & any
configured DTB files.
Build kernel from source
• Step 4: Install the just built kernel
• Step 5: Setup the GRUB bootloader and the initramfs (or initrd) image
under /boot (x86_64)
• This creates and install initramfs (or initrd) image under /boot
• It updates the bootloader configuration file to boot the new kernel
• Kconfig files
• Makefiles
• Via localmodconfig
-> lsmod > /tmp/lsmod.now
make LSMOD=/tmp/lsmod.now localmodconfig
make menuconfig
• [.]: in-kernel feature, Boolean state
• <.> tri-state feature
• <*>: on, feature compiled and built in
• <M>: module, feature compiled and built in as loadable kernel module
• <>: off
Câu hỏi: Các module được cài đặt vào folder nào?
Step 5: Bootloader setup
• For x86[64]
• Generating the initramfs (or initrd) image
• Initramfs allows to run user space applications (or scripts) before the
actual root filesystem has been mounted. E.g:
• Setup a console font
• Print a custom welcome message on the console device
• Load up kernel modules as require
Boot process on x86
• BIOS loads up the first sector of the first bootable disk into RAM
(stage one bootloader), next loads the stage two bootloader into RAM
• Load the GRUB (Grand Unified Bootloader) bootloader into memory
• GRUB bootloader
• Perform low-level hardware initialization
• Loads the compressed kernel image (vmlinuz) and initramfs image into RAM
• Jump to the kernel entry point
• The Linux kernel initialize the hardware and software environment.
Boot process on x86(cont.)
• The kernel locate and mount the initramfs as a temporary root
filesystem in RAM (RAMdisk), which perform the loading of required
kernel modules.
• The RAMdisk is then unmounted, let the real root filesystem replace
and initialize the system.
• System initialization proceeds, the kernel invokes the first user space
process (/sbin/init) with PID = 1
Exercises
• Redo the process and turn on those options in menuconfig -> Kernel
Hacking
• CONFIG_KASAN
Exercises
CONFIG_DEBUG_SHIRQ
CONFIG_SCHED_STACK_END_CHECK
CONFIG_PROVE_LOCKING
CONFIG_LOCK_STAT
CONFIG_DEBUG_ATOMIC_SLEEP
CONFIG_STACKTRACE
CONFIG_DEBUG_BUGVERBOSE
CONFIG_FTRACE
CONFIG_BUG_ON_DATA_CORRUPTION
CONFIG_KGDB (kernel GDB; optional)
CONFIG_UBSAN
CONFIG_EARLY_PRINTK
CONFIG_DEBUG_BOOT_PARAMS
CONFIG_UNWINDER_FRAME_POINTER (selects FRAME_POINTER and
CONFIG_STACK_VALIDATION)