Linux boot sequence

Linux Boot Sequence:

——————————————————–

Power on the machine to initialize firmware
Pick one CPU as bootstrap processor
System is now in real mode only 1MB memory can be addressed
Use EIP and hidden offset to execute first instruction in reset vector
Jump to BIOS flash memory entry location routed by memory map on chip-set

——————————————————–

Now CPU run BIOS code
Invoke POST to test system components
Search bootable device through CMOS
Load MBR the first sector in that device to memory address 0x7c00
MBR contains primary boot loader and partition table

——————————————————–

Now CPU jump to 0x7c00 and run MBR code
First stage: search active partition and load its boot sector
This boot sector could understand Linux file system format
Use MBR’s plus boot sector’s boot loader to load another boot loader
Second stage: run the newest loaded boot loader
It read a boot configuration file e.g. grub.conf to show boot choices to user
All above boot loaders combined are called GRUB
Finally GRUB would load pick system’s image to memory
The image is split into two pieces:
small one in real-mode and compressed large one in protected-mode
GRUB could pass parameters to kernel header then jump to kernel entry point in real-mode

——————————————————–

Boot loader finished and Kernel stage start
The function flow:
start_of_setup(): basic hardware setup (arch/x86/boot/header.S)
go_to_protected_mode(): set CPU to protected mode (arch/x86/boot/main.c)
startup_32(): basic register setting (arch/x86/boot/compressed/head_32.s)
decompress_kernel(): decompress image (arch/x86/boot/compressed/misc.c)
Jump to kernel enry point in protected-mode
startup_32(): also called process 0, creat IDT and GDT, enable paging and initialize page table etc. (arch/x86/kernel/head_32.s)
start_kernel(): architecture-independent kernel start-up (init/main.c)

——————————————————–
start_kernel() do long list of initialization and then call rest_init()
rest_init(): (init/main.c)
-> kernel_thread(kernel_init): active remaining CPUs and creat first user-space process 1 to call init_post() and run /sbin/init .etc.(init/main.c)
-> kernel_thread(kthread): create kernel thread process 2 (init/main.c)
-> schedule(): context switch kick in p1 to invoke other process by checking configuration file (init/main.c)
-> cpu_idle(): when there is work to do it would be switched out (init/main.c)

resource:
http://duartes.org/gustavo/blog/post/kernel-boot-process
http://www.ibm.com/developerworks/linux/library/l-linuxboot/
http://duartes.org/gustavo/blog/post/how-computers-boot-up

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: