The Basic Boot Process
时间:2005-11-18 来源:rickyweiwei
Runlevels
There are six basic runlevels in Red Hat Enterprise Linux, as defined in /etc/inittab. Each runlevel is associated with a level of functionality. For example, in single-user mode, also known as runlevel 1, only one user is allowed to connect to that Linux system. X11 mode, also known as runlevel 5, starts Linux into a GUI login screen.
Red Hat Runlevels
Runlevel |
Description |
---|---|
0 |
Halt |
1 |
Single-user mode, for maintenance (backups/restores) and repairs |
2 |
Multiuser, without networking |
3 |
Multiuser, with networking |
4 |
Unused |
5 |
X11, defaults to a GUI login screen. Logins bring the user to a GUI desktop. |
6 |
Reboot (never set initdefault in /etc/inittab to this value!) |
1、Making each runlevel work is the province of a substantial number of scripts. Each script can start or stop fundamental Linux processes such as printing (cupsd), scheduling (crond), Apache (httpd), Samba (smbd), and more. The starting and stopping of the right scripts becomes part of the boot process.
It should go without saying that if you set your initdefault to 0, your system will shut down when Linux tries to boot. Likewise, if you set the initdefault to 6, Linux will enter a continuous reboot cycle.
2、The Boot Process
When you start your computer, the BIOS checks your system, and looks for a bootloader such as GRUB. It finds and installs the Linux kernel. Then Linux can start installing the services you have configured.
The kernel always starts by calling init. The init process in turn runs /etc/rc.d/rc.sysinit, which performs a number of tasks, The init process then determines which runlevel it should be in by looking at the initdefault entry in /etc/inittab. A runlevel is defined as a group of activities. For example, the entry:
id:5:initdefault:
shows a default starting point in runlevel 5. Next, init starts the appropriate scripts associated with runlevel 5, from the /etc/rc.d directory. That directory includes the following subdirectories:
init.d
rc0.d
rc1.d
rc2.d
rc3.d
rc4.d
rc5.d
rc6.d
If the default runlevel is 5, init will look in /etc/rc.d/rc5.d and run each 'kill' and 'start' script it finds in that directory. A kill script is any file or symbolically linked file with a name that begins with a 'K.' Likewise, start scripts start with 'S.' If you run an ls -l command in this directory, you'll see only symbolic links to the actual scripts in /etc/rc.d/init.d.
System V init knows to go to the directory associated with a particular runlevel. Once there, init runs the scripts in that directory that start with a K and then the scripts starting with an S. The K scripts stop processes that aren't supposed to operate in that runlevel. The S scripts start the processes associated with that runlevel. Within each category, scripts are run in numeric order; for example, K20nfs is run before K50tux, which is run before S10network.
Red Hat uses six different runlevels: 0, 1, 2, 3, 5, and 6. (Runlevel 4 is unused as of this writing.) Symbolic links allow the collection of all init scripts in one directory, /etc/init.d. Any changes to a start or kill script can be made in that directory.
You can run a start script yourself, with some key switches. For example, you can run the smbd (Samba) and sshd (secure shell daemon) scripts with the following options:
# /etc/rc.d/init.d/smb
Usage: /etc/rc.d/init.d/smb {start|stop|restart|reload|status|condrestart}
# service smb # service is a shortcut to the management scripts
This is used by the scripts at each runlevel. In other words, if there is a K script for the smbd daemon, init runs /etc/rc.d/init.d/smb stop. And naturally, an S script for the ssh daemon runs /etc/rc.d/init.d/sshd start.
Summarize:init & /etc/ inittab-------/etc/rc.d/rc.sysinit --------/etc/rc.d/rcx.d/