2008年8月22日星期五

The Linux Boot Process

Keywords
loading GRUB initrd init

Booting Process
1.GRUB booting

+-----------------------+
| +---------+ |---------------+
| | V V V
+|+++++++++++++++++++++|++++++++++++++++++++++++++++++++
= ===================== ================================
| | ha1 | | hda2 |
| | | stage2/Linux
| | stage1.5/Boot sector of second partition
| Dos/Boot sector of first partition
GRUB stage1/LILO/MBR

Stage 1 is what is present in the main boot record and merely loads the next stage.Stage 1.5 is also quite sall, but is able to understand filesystems.Depending what filesystem contains the Stage 2 loader, a different stage 1.5 is used and is even optional in some circumstances.
Stage 2 is the meat of the loader and contains many features and options that can be explored. Because GRUB understands partitions and filesystem,it can load a kernel that it wasn't told about previously.

2.Follow up booting Kernel(kernel and initrd)

kernel
+->setup
+->switch to Protected Mode(PM)
+->decompress_kernel()
+->start_kernel() <- PID 0
+->kernel_thread()
+->init <- PID 1

kernel: base booting code,all kinds of hardware driver in initrd(boot loader initalized RAM disk).If booting not appointed initrd.img file,booting failed:"Kernel panic:VFS: Unable to mount root fs on 08:06". initrd.img is guzip -9 zip and ramdisk file. gunzip initrd.img ,You can see /bin/nash command and init script. nash(not a sheel)?nash is a very simple script interpretor designed to be as small as possible. init file is booting script.It's command see man nash.Line mkrootdev /dev/root,root is a GRUB root=,mount filesystem root.Next process init process can read /etc/inittab ,wreate syslog ...... See screen Outcome:Switching to new root. kernel booting end.

3.
init
It's run under the kernel.This program is always process 1.The kernel can be told which program to use as init by passing the "init=" boot parameter. If this paramenter is not specified, then the kernel will try to execute '/sbin/init','/etc/init','/bin/init' or '/bin/sh' in that order.
The init program read it's configuration from the '/etc/inittab'.

4.Runlevel Scripts
Read '/etc/inittab'.The inittab file describes which processes are started at bootup and during normal operation (e.g./etc/init.d/boot, /etc/init.d/rc, gettys...). Init(8) distinguishes multiple runlevels, each of which can have its own set of processes that are started. Valid runlevels are 0-6 plus A, B, and C for ondemand entries.


没有评论: