Linux Init Process / PC Boot Procedure
上一篇 / 下一篇 2007-12-08 01:27:55 / 个人分类:软件开发
- BIOS: The Basic Input/Output System is the lowest level interface between the computer and peripherals.
$I @C`a$OC!@{*Wz0The BIOS performs integrity checks on memory and seeks instructions on the Master Boor Record (MBR) on the floppy drive or hard drive. - The MBR points to the boot loader (GRUB or LILO: Linux boot loader).
- Boot loader (GRUB or LILO) will then ask for the OS label which will identify which kernel to run and where it is located (hard drive and partition specified). The installation process requires to creation/identification of partitions and where to install the OS. GRUB/LILO are also configured during this process. The boot loader then loads the Linux operating system.
- See the YoLinux tutorial oncreating a boot diskfor more information on GRUB and LILO and also to learn how to put the MBR and boot loader on a floppy for system recovery.
- The first thing the kernel does is to executeinitprogram. Init is the root/parent of all processes executing on Linux.
- The first processes that init starts is a scrīpt/etc/rc.d/rc.sysinit
- Based on the appropriate run-level, scrīpts are executed to start various processes to run the system and make it functional.
The Linux Init Processes: |
g8e-k'\f3mg0The init process is the last step in the boot procedure and identified by process id "1". Init is responsible for starting system processes as defined in the/etc/inittabfile. Init typically will start multiple instances of "getty" which waits for console logins which spawn one's user shell process. Upon shutdown, init controls the sequence and processes for shutdown. The init process is never shut down. It is a user process and not a kernel system process although it does run as root.
&T:UD^[.w1W051Testing软件测试网t,N;_,sn vX3R,{System Processes:
QK1D5V;@~X0Process ID Descrīption 0 The Scheduler 1 The init process 2 kflushd 3 kupdate 4 kpiod 5 kswapd 6 mdrecoveryd
Init config file (Red Hat 7.3-9.0, Fedora Core 1-3):/etc/inittab
(U/Z+qC({j051Testing软件测试网Q,^Ci*{51Testing软件测试网A(di qA
# Author: Miquel van Smoorenburg,
51Testing软件测试网hK~)ipakl2z
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
l%] jikfQ;E*q051Testing软件测试网w,Qw.M\^RL$j
id:3:initdefault:
.e6Ms#K%eK051Testing软件测试网X E"O5D9CN
# System initialization.
@8C8o/SoM\M0si::sysinit:/etc/rc.d/rc.sysinit51Testing软件测试网rm4AY6k$cAW+s k
51Testing软件测试网$KH0H7an0o3d%Kz
l0:0:wait:/etc/rc.d/rc 051Testing软件测试网)T va0@Rv!]?
l1:1:wait:/etc/rc.d/rc 1
5l'S$i;~&Yq2f$X0l2:2:wait:/etc/rc.d/rc 2
,k5f]e(Rk,wb0l3:3:wait:/etc/rc.d/rc 3
u \YvK9_ b0l4:4:wait:/etc/rc.d/rc 451Testing软件测试网M'w#A9}4B*M
l5:5:wait:/etc/rc.d/rc 5
y5qhV6Nc x0l6:6:wait:/etc/rc.d/rc 6
8h~R9Lv7p7J Ed#O1nT0
XIN&vV0iGn_\3^0# Things to run in every runlevel.This line is only in Red Hat 7.X Used to flush disk buffers.
/v E#{ S5]l"]|0ud::once:/sbin/update51Testing软件测试网 m_oPx\(i
51Testing软件测试网5lP&C7s re
# Trap CTRL-ALT-DELETE51Testing软件测试网p!sA8W(Vn'VW:o7n]
ca::ctrlaltdel:/sbin/shutdown -t3 -r now51Testing软件测试网][T:B$wI
51Testing软件测试网u6j/A$ycYd
# When our UPS tells us power has failed, schedule a shutdown for 2 minutes from now.
7{kikQ%suC_0pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
3[+t4PL^A8` q0
o!UK#o3HH&WM ^0# If power was restored before the shutdown kicked in, cancel it.
"ul@ Wy#l1]kg0pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Canceled"51Testing软件测试网^K k,K8^I`]
6m` YpdmcZ.?0# Run gettys in standard runlevels51Testing软件测试网(O)I+\^2a%I+`6El
1:2345:respawn:/sbin/mingetty tty1
!yX7X|"Qt1}[02:2345:respawn:/sbin/mingetty tty2
2Xq9rd#?&i7d6k&T*}03:2345:respawn:/sbin/mingetty tty3
;O|6wD \6J5~ ~/Qi04:2345:respawn:/sbin/mingetty tty4
]Myke|Dv!B05:2345:respawn:/sbin/mingetty tty5
u\5V `d"]06:2345:respawn:/sbin/mingetty tty6
%e9s-z|[]C.A0
.O(yI0mN EFDA0# Run xdm in runlevel 5
!|K/V7`c7|5ZT"A0x:5:respawn:/etc/X11/prefdm -nodaemon
4]@$wJH#G.i0
b#k/M;BIL;K0Note that this config file directs the init process to run the shell scrīpt/etc/rc.d/rc.sysinit. This scrīpt should be used as is and NOT changed. Extendrc.localand NOT this scrīpt. This will (not in exact order):51Testing软件测试网H:X4BO]g(Vzj&H
- Run/sbin/initlog
- Run devfs to generate/manage system devices
- Run network scrīpts:/etc/sysconfig/network
- Start graphical boot (If so configured):rhgb
- Start console terminals, load keymap, system fonts and print console greeting:mingetty,setsysfonts
wr e J2} n-d0The various virtual console sessions can be viewed with the key-stroke:ctrl-alt-F1throughF6. F7 is reserved for the GUI screen invoked in run level 5. - Mount/procand start device controllers.
- Done with boot configuration for root drive. (initrd) Unmount root drive.
- Re-mount root file system as read/write
- Direct kernel to load kernel parameters and modules:sysctl,depmod,modprobe
- Set up clock:/etc/sysconfig/clock
- Perform disk operations based on fsck configuration
- Check/mount/check/enable quotas non-root file systems:fsck,mount,quotacheck,quotaon
- Initialize logical volume management:vgscan,/etc/lvmtab
- Activate syslog, write to log files:dmesg
- Configure sound:sndconfig
- Activate PAM
- Activate swapping:swapon
Local system boot processes can be placed in file:/etc/rc.d/rc.local51Testing软件测试网Ytol!Fn/KK
51Testing软件测试网4MP?+Uy V#d qk%e%fThe system will then boot to the runlevel set by the directiveinitdefault.51Testing软件测试网#g:t+fe"Mmz
51Testing软件测试网f F0c a.iro5xEAlso see:51Testing软件测试网3p|i+u9RD FG
51Testing软件测试网n hSh"{U5yD!y;w2`(}&F6Z5t0Linux init Run Levels: |
?W2LGoc3E0LINUX has six states of operation of which "0" is the shutdown state and "3" and above are fully operational with all essential processes running for user interaction. Upon system boot the LINUX system/sbin/initprogram starts other processes by performing the following:51Testing软件测试网L&cP8\.H&fk$o%e
- Init will bring up the machine by starting processes as defined in the/etc/inittabfile.
@m-K?,i4AJ0
'e"?jl8V5v0 - The computer will be booted to the runlevel as defined by theinitdefaultdirective in the/etc/inittabfile.
id:5:initdefault:
?:n'yrU0The inittab file will allow you to capture key sequences (ctrl-alt-del), start dial in internet connections etc.51Testing软件测试网X[9L:O'e)`m,O%z
'ey0bT&ge~X:Q051Testing软件测试网K*J i3|)`
- One of these process started by init is/sbin/rc. This scrīpt runs a series of scrīpts in the directories/etc/rc.d/rc0.d/,/etc/rc.d/rc1.d/,/etc/rc.d/rc2.d/, etc
h,])p3uz9L051Testing软件测试网!s-u }.[l+A1Mhp
- scrīpts in these directories are executed for each boot state of operation until it becomes fully operational. scrīpts beginning with S denote startup scrīpts while scrīpts beginning with K denote shutdown (kill) scrīpts. Numbers follow these letters to denote the order of execution. (lowest to highest)
cT o_a"KXF3k0Runlevel "3" will boot to text or console mode and "5" will boot to the graphical login mode ( "4" for slackware)51Testing软件测试网:v6Q&OqGt"j%\
51Testing软件测试网LCNy/\$biqr["G[5y V0Runlevel scrīpts Directory51Testing软件测试网Os!c&\]2L9{ja:T
(Red Hat/Fedora Core)State 0 /etc/rc.d/rc0.d/ shutdown/halt system 1 /etc/rc.d/rc1.d/ Single user mode 2 /etc/rc.d/rc2.d/ Multiuser with no network services exported 3 /etc/rc.d/rc3.d/ Default text/console only start. Full multiuser 4 /etc/rc.d/rc4.d/ Reserved for local use. Also X-windows (Slackware/BSD) 5 /etc/rc.d/rc5.d/ XDM X-windows GUI mode (Redhat/System V) 6 /etc/rc.d/rc6.d/ Reboot s or S Single user/Maintenance mode (Slackware) M Multiuser mode (Slackware)
`'M+L1Y^0One may switch init levels by issuing the init command with the appropriate runlevel. Use the command "init#" where # is one of s,S,0,1,3,5,6. The commandtelinitdoes the same.
9x4_'?)SQ(]?051Testing软件测试网E\^&{;?9@cThe scrīpts for a given run level are run during boot and shutdown. The scrīpts are found in the directory/etc/rc.d/rc#.d/where the symbol#represents the run level. i.e. the run level "3" will run all the scrīpts in the directory/etc/rc.d/rc3.d/which start with the letter "S" during system boot. This starts the background processes required by the system. During shutdown all scrīpts in the directory which begin with the letter "K" will be executed. This system provides an orderly way to bring the system to different states for production and maintenance modes.
+gBci8Wa1t;@ J051Testing软件测试网Qoj"\.f[O%e0nVIf you installed all demons (background processes), Linux will run them all. To avoid slowing down your machine, remove unneeded services from the start-up procedure. You can start/stop individual demons by changing to the directory:
o-bR&?G$a0- /etc/rc.d/init.d/(Red Hat/Fedora )
- /etc/init.d/(S.u.s.e.)
- /etc/init.d/(Debian)
- cd /etc/rc.d/init.d/51Testing软件测试网2I,Y"nf ^rd0bPt!X
(or/etc/init.d/for S.u.s.e. and Debian) - httpd stop
Use the command ps -aux to view all process on your machine.51Testing软件测试网-F:U/xT*HJ,fM
;xkZ.~;N{#q6_0TIP:List state and run level of all services which can be started by init:chkconfig --list51Testing软件测试网g&PeH(d%F9p g
or51Testing软件测试网$~G"|h]'D
service --status-all | grep running(Red Hat/Fedora Core based systems)
\?"E2yJN0GUI tool:/usr/X11R6/bin/tksysv
2I&f;hs;w'c0"A4U@RB_7T8DM$o051Testing软件测试网#Gt#fn%M7j
Run Level Commands: |
] l2d.P?5T6]!Z(K0
6I#Pn[D7W'^4v0- Shutdown:
- Reboot:
- Enter single user mode:
- init1
Init scrīpt Activation: |
,^U-ld5Yo:~0Adding a scrīpt to the/etc/rc.d/rc#.d/directory with either an S or K prefix, adds the scrīpt to the boot or shutdown process. The scrīpts are run in numerical order. S20abc is run before S30xyz. The extensibility to the boot and shutdown procedures of the operating system is one of the strengths of UNIX. The orderly sequential initiation of processes can be coordinated for dependent processes. The orderly shutdown of processes is often required of complex programs such as databases. This is how it is done. Individual processes may be monitored, shutdown and started at any time using these scrīpts. i.e./etc/rc.d/rc2.d/httpd start. The modifiersstart, stoporstatusmay be used.51Testing软件测试网/V'TM ^\ih.e0E_
51Testing软件测试网K%v(UM'i yThe start/stop/status scrīpts actually reside in the directory:
*B#r&L M:N0Oh*bwt}0- /etc/rc.d/init.d/(Red Hat/Fedora)
- /etc/init.d/(S.u.s.e. and Debian)
g-V8T$J"z2YE2t~0Basic services include:51Testing软件测试网 S/`yrgiV'bN
w!s EH,]:g8[$L]1j0
3@z+W;z:P @;g0System Service | Descrīption |
---|---|
anacron | Run jobs which were scheduled for execution while computer was turned off. Catch up with system duties. |
arpwatch | Keeps track of IP address to MAC address pairings |
atd | Run scheduled batch jobs. |
autofs | automounts file systems on demand. |
crond | Job sheduler for periodic tasks. |
gpm | Allows console terminal cut and paste. (Non X-window consoles) |
https | Apache web server. |
iptables | Firewall rules interface to kernel. |
keytable | Loads selected keyboard map as set in/etc/sysconfig/keyboard |
kudzu | New hardware probe/detection during system boot. |
lpd | Network printer services. |
microcode_ctl | Uploads microcode to kernel and ultimately to the Intle Pentium processor. (Hardware specific.) |
mysqld | Database services |
named | DNS name services (Bind) |
network | Active network services during system boot. |
nfs | Network file system. Unix file sharing services. |
nscd | Password and group lookup services for use with network authentication (NIS, LDAP,...). |
ntpd | Network Time Protocol time synchronization services. |
random | Random number generation tool used for encryption. |
rawdevices | Enables raw IO. Useful for Oracle and software which utilizes this for high speed disk access. |
smb | SAMBA: MS/Windows PC file sharing services |
syslog | System log file facility. |
ypbind | NIS file sharing/authentication infrastructure service. |
yppasswd | NIS file sharing/authentication infrastructure service. |
ypserv | NIS file sharing/authentication infrastructure service. |
xfs | X-Windows font server. |
Recommended basic services:anacron, ard, autofs, crond, gpm, iptables, keytable, kudzu, microcode_ctl(Intel32 hardware only),network, random. syslog51Testing软件测试网JV.G!S3sP_
Graphics Workstation - add:xfs51Testing软件测试网X7D6^\O$_X0Y
File Server for PC clients - add:smb51Testing软件测试网
~W^9y
}!_
Print Server - add:lpdorcups51Testing软件测试网R5?5r*uoU$V"P!yj
File server Linux/Unix clients - add:nfs, netfs, nfslock, portmap, ypbind, yppasswd, ypserv
6FA#c9p'y1nid0Web Server - add:httpd, tux, xinetdi, sshd
51Testing软件测试网+LX?W8FA#g
51Testing软件测试网 [9W[z8FQ
GUI configuration tools:
GUI tools can help you configure the appropriate services to start and provide a descrīption of each service available:- Red Hat 8.0/9.0:/usr/bin/redhat-config-services
- Fedora/RHEL:/usr/bin/system-config-services51Testing软件测试网 ^.UZi-hK
(Also/usr/sbin/serviceconf) - Ubuntu 6 / Debian:
- /usr/bin/services-admin
- bum(Boot Up Manager)
Red Hat/Fedora Core text console services selection tool:/usr/sbin/ntsysv
s!XvB6u1k C03D-wg&m)Fp051Testing软件测试网)m:s:_Al+]:~IP%G2WP
Init scrīpt: |
A single copy of the scrīpt is located in the directory:/etc/rc.d/init.d/scrīpt-name(Red Hat/Fedora) or/etc/init.d/scrīpt-name(Debian).51Testing软件测试网Z(Q.PV5{ev
Use the commandchkconfigto generate soft links to the appropriate directories for the various run levels.