著作权属陈建业
在这□我们先了解整个linux启动的流程,首先系统核心由lilo
或loadlin程式读入记忆体,在解压缩後分别载入各周边的驱动程
式。必须注意的是,有些驱动程式采自动侦测(auto-probe)的方
式,判断硬体的设定情形,如果在核心载入的过程中,发现有侦测
错误的情况,必须把确实的硬体设定参数由lilo、loadlin在载入
时传入核心。
在核心完成载入後,linux会执行init程式,init程式会根据
/etc/inittab的设定完成系统启动的程序。由於在启动系统时,我
们可能希望进入正常的运作模式提供对外服务,或进入系统维护模
式暂时停止对外服务,所以除了特殊事件处理外,每一个项目都指
定run level,通知init这次启动本项目是否要执行。接著init监督
所有由它启动的程式及停电等系统事件,直到shutdown为止。例如
getty负责使用者签入,而一般getty的action为respawn,表示使用
者离线後,init会再重新启动getty等待下一个使用者。
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Version: @(#)inittab 2.04 17/05/93 MvS
#
# Author: Miquel van Smoorenburg,
#
# 格式: ## Default runlevel.#id:5:initdefault:## System initialization (runs when system boots).#si:S:sysinit:/etc/rc.d/rc.S## Script to run when going single user.#su:S:wait:/etc/rc.d/rc.K## Script to run when going multi user.#rc:123456:wait:/etc/rc.d/rc.M## What to do at the "Three Finger Salute".#ca::ctrlaltdel:/sbin/shutdown -t3 -rf now## What to do when power fails (shutdown to single user).#pf::powerfail:/sbin/shutdown -f +5 "THE POWER IS FAILING"## If power is back before shutdown, cancel the running shutdown.#pg:0123456:powerokwait:/sbin/shutdown -c "THE POWER IS BACK"## If power comes back in single user mode, return to multi user mode.#ps:S:powerokwait:/sbin/init 5## The getties in multi user mode on consoles an serial lines.## NOTE NOTE NOTE adjust this to your getty or you will not be# able to login !!## Note: for 'agetty' you use linespeed, line.# for 'getty_ps' you use line, linespeed and also use 'gettydefs'#c1:12345:respawn:/sbin/getty tty1 38400 consolec2:12345:respawn:/sbin/getty tty2 38400 consolec3:45:respawn:/sbin/getty tty3 38400 consolec4:45:respawn:/sbin/getty tty4 38400 vt100#c5:45:respawn:/sbin/agetty 38400 tty5#c6:456:respawn:/sbin/agetty 38400 tty6## Serial lines##s1:45:respawn:/sbin/agetty 19200 ttyS0#s2:45:respawn:/sbin/agetty 19200 ttyS1## Dialup lines##d1:45:respawn:/sbin/agetty -mt60 38400,19200,9600,2400,1200 ttyS0#d2:45:respawn:/sbin/mgetty -D -n 5 ttyS1 38400 vt100## Runlevel 6 used to be for an X-window only system, until we discovered# that it throws init into a loop that keeps your load avg at least 1 all# the time. Thus, there is now one getty opened on tty6. Hopefully no one# will notice. ;^)# It might not be bad to have one text console anyway, in case something# happens to X.#x1:6:wait:/etc/rc.d/rc.6# End of /etc/inittab*上表除中文说明外,节录自slackware 2.1.0之/etc/inittab从inittab可以看到,id:5:initdefault表示在载入核心时若没有指定runlevel,则以5作为内定值。rc.S的action属於sysinit,会在系统启动後首先被执行。接著id为rc那一项,指定在runlevel为1~6时执行,属性为wait表示init会执行rc.M且等待它执行完毕。这两个script和系统环境较密切,我们下面会作较详细的介绍。另外id为ca那一项定义了按ctrl-alt-del时,执行shutdown并立即reboot。至於id为c1~c6、s1~s2、d1~d2者,指定在那一个runlevel下,启动那些终端机,它们的action属於respawn表示这些程式在结束後,init会再次重新执行它们,直到shutdown为止。如果须要更详细的资料,可用man init得到更详细的说明。#!/bin/sh## /etc/rc.d/rc.S## These commands are executed at boot time by init(8).# User customization should go in /etc/rc.local.PATH=/sbin:/usr/sbin:/bin:/usr/bin## 启动swap系统:## 1. mount所有定义在/etc/fstab内的swap partition##/sbin/swapon -av## 2.启动swap file而不是swap partition#/sbin/swapon /.Swapfile## Start update.#/sbin/update # Test to see if the root partition is read-only, like it ought to be.## 测试档案系统的完整性#READWRITE=noif echo -n"Testing filesystem status"; thenrm -f "Testing filesystem status"READWRITE=yesfi## Check the integrity of all filesystems#if [ ! $READWRITE = yes ]; then/sbin/fsck -A -a# If there was a failure, drop into single-user mode.if [ $? -gt 1 ] ; thenechoechoecho "**************************************"echo "fsck returned error code - REBOOT NOW!"echo "**************************************"echoecho/bin/loginfi## Remount the root filesystem in read-write mode#echo "Remounting root device with read-write enabled."/sbin/mount -w -n -o remount /if [ $? -gt 0 ] ; thenechoecho "Attempt to remount root device as read-write failed! This is going to"echo "cause serious problems... "echoecho "If you're using the UMSDOS filesystem, you **MUST** mount the rootpartition"echo "read-write! You can make sure the root filesystem is getting mounted"echo "read-write with the 'rw' flag to Loadlin:"echoecho "loadlin vmlinuz root=/dev/hda1 rw (replace /dev/hda1 with your rootdevice)"echoecho "Normal bootdisks can be made to mount a system read-write with therdev command:"echoecho "rdev -R /dev/fd0 0"echoecho "You can also get into your system by using a bootkernel disk with acommand"echo "like this on the LILO prompt line: (change the root partition nameas needed)"echoecho "LILO: mount root=/dev/hda1 rw"echoecho "Please press ENTER to continue, then reboot and use one of the abovemethods to"echo -n "get into your machine and start looking for the problem. "read junk;fielseecho "Testing filesystem status: read-write filesystem"if [ -d /DOS/linux/etc -a -d /DOS/linux/dev ]; then # no warn for UMSDOScat*** ERROR: Root partition has already been mounted read-write. Cannot check!For filesystem checking to work properly, your system must initially mountthe root partition as read only. Please modify your kernel with 'rdev' so thatit does this. If you're booting with LILO, add a line:read-onlyto