Linux system startup process
1. First read the kernel file under boot:
2. The init process reads the configuration file:
pid=1, complete the transition from kernel mode to user mode
Linux kernel startup process:
Between 1 and 12, the linux kernel starts:
1. At 1, the self-extracting
kernel file of the kernel is loaded into the memory using the code kernel/arch/arm/boot/compressed , the page table data structure is established, and the address mapping is performed ,
2. Then enter the start_kernel function:
set the work related to the initialization of the architecture (x86, etc.)
Create the kernel page table, MMU, interrupt handling function, core process scheduler, clock interrupt handling mechanism, serial console, cache, memory management, system inter-process communication mechanism IPC and
then start to mount the root file system
3. Mount the root file system,
including etc, bin, sbin, lib, dev, etc., and mount it in a read-only mode.
(The five major file systems must be stored in the root file system)
Then find the init service in the file, and read the /etc/inittab file after the init service is started, and initialize according to the settings in /etc/inittab
(The kernel image is the kernel file, which refers to a form of kernel)
Detailed explanation of initramfs
Before the init process is started in the third, initramfs will be started. As an early user mode environment,
when initram is packaged, it is required to be packaged into a cpio file, which can be embedded in the kernel image or can be loaded by GRUB as a separate file during startup. The initrd.img-xxx (Ubuntu) or initramfs-xxx.img (CentOS) file in the /boot directory is the initramfs file for Linux.
Write a simple hello and compile it into a 32-bit program. If 64-bit cannot compile 32-bit, run the command:
sudo apt-get install gcc-multilib
gcc -static -o helloworld -m32 helloworld.c
echo helloworld | cpio -o --format=newc > hwinitramfs
qemu -kernel arch/x86/boot/bzImage -initrd hwinitramfs -append "console=ttyS0 rdinit=helloworld" -nographic
You can see that the hello world is successfully output and is held in user mode
GRUB detailed
GNU GRUB is a multi-operating system startup program, a multi-operating system startup manager,
you can select the kernel of the operating system, or you can pass parameters to the kernel