著作权属陈建业 在这□我们先了解整个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 console c2:12345:respawn:/sbin/getty tty2 38400 console c3:45:respawn:/sbin/getty tty3 38400 console c4: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=no if echo -n >> "Testing filesystem status"; then rm -f "Testing filesystem status" READWRITE=yes fi # # 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 ] ; then echo echo echo "**************************************" echo "fsck returned error code - REBOOT NOW!" echo "**************************************" echo echo /bin/login fi # # 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 ] ; then echo echo "Attempt to remount root device as read-write failed! This is going to" echo "cause serious problems... " echo echo "If you're using the UMSDOS filesystem, you **MUST** mount the root partition" echo "read-write! You can make sure the root filesystem is getting mounted " echo "read-write with the 'rw' flag to Loadlin:" echo echo "loadlin vmlinuz root=/dev/hda1 rw (replace /dev/hda1 with your root device)" echo echo "Normal bootdisks can be made to mount a system read-write with the rdev command:" echo echo "rdev -R /dev/fd0 0" echo echo "You can also get into your system by using a bootkernel disk with a command" echo "like this on the LILO prompt line: (change the root partition name as needed)" echo echo "LILO: mount root=/dev/hda1 rw" echo echo "Please press ENTER to continue, then reboot and use one of the above methods to" echo -n "get into your machine and start looking for the problem. " read junk; fi else echo "Testing filesystem status: read-write filesystem" if [ -d /DOS/linux/etc -a -d /DOS/linux/dev ]; then # no warn for UMSDOS cat << EOF *** ERROR: Root partition has already been mounted read-write. Cannot check! For filesystem checking to work properly, your system must initially mount the root partition as read only. Please modify your kernel with 'rdev' so that it does this. If you're booting with LILO, add a line: read-only to the Linux section in your /etc/lilo.conf and type 'lilo' to reinstall it. If you boot from a kernel on a floppy disk, put it in the drive and type: rdev -R /dev/fd0 1 If you boot from a bootkernel disk, or with Loadlin, you can add the 'ro' flag. This will fix the problem *AND* eliminate this annoying message. :^) EOF echo -n "Press ENTER to continue. " read junk; fi fi # # remove /etc/mtab* so that mount will create it with a root entry # /bin/rm -f /etc/mtab* /etc/nologin /var/adm/utmp # # Looks like we have to create this. # cat /dev/null >> /var/adm/utmp # # mount file systems in fstab (and create an entry for /) # but not NFS because TCP/IP is not yet configured # # mount所有定义在/etc/fstab内的档案系统,但nfs除外。因为 # tcp/ip环境的设定是在後面rc.M内完成。 # /sbin/mount -avt nonfs # # Configure the system clock. # This can be changed if your system keeps GMT. # if [ -x /sbin/clock ]; then /sbin/clock -s fi # # Setup the /etc/issue and /etc/motd to reflect the current kernel level: # THESE WIPE ANY CHANGES YOU MAKE TO /ETC/ISSUE AND /ETC/MOTD WITH EACH # BOOT. COMMENT THEM OUT IF YOU WANT TO MAKE CUSTOM VERSIONS. # # 这一段程式会在每次重新开机时,将/etc/motd、/etc/issue这两 # 个档写入Slackware的内定值。 # #echo > /etc/issue #echo Welcome to Linux `/bin/uname -a /bin/cut -d -f3`. >> /etc/issue #echo >> /etc/issue #echo "`/bin/uname -a /bin/cut -d -f1,3`. (POSIX)." > /etc/motd # # Run serial port setup script: # (CAREFUL! This can make some systems hang if the rc.serial script isn't # set up correctly. If this happens, you may have to edit the file from a # boot disk) # # 执行设定serial port的程式 # /bin/sh /etc/rc.d/rc.serial # end of /etc/rc.d/rc.S * 上表除中文说明外,节录自slackware 2.1.0之/etc/inittab 在内定的情形下,我们会以runlevel 5进入系统,因此接著执行 /etc/rc.d/rc.M。 #!/bin/sh # # rc.M This file is executed by init(8) when the system is being # initialized for one of the "multi user" run levels (i.e. # levels 1 through 6). It usually does mounting of file # systems et al. # # Version: @(#)/etc/rc.d/rc.M 2.02 02/26/93 # # Author: Fred N. van Kempen, # Heavily modified by Patrick Volkerding # # # Tell the viewers what's going to happen... # echo "Going multiuser..." # # Screen blanks after 15 minutes idle time. # # 设定在15分钟内没有任何动作时,自动关闭萤幕显示 # /bin/setterm -blank 15 # # Start crond (Dillon's crond): # If you want cron to actually log activity to /var/adm/cron, then change # -l10 to -l8 to increase the logging level. # # 每个user都可用crontab -e建立一张表格,指定在特定的时间 # 执行某些程式,这是由下面的程式来监控 # /usr/sbin/crond -l10 >>/var/adm/cron 2>&1 # # If there's no /etc/HOSTNAME, fall back on this default: # # 如果没有设定主机名称,下面这段程式会填入内定值 # if [ ! -r /etc/HOSTNAME ]; then echo "darkstar.frop.org" > /etc/HOSTNAME fi # # Initialize the NET subsystem. # # 设定网路系统,後面会再作较详细的介绍 # if [ -x /etc/rc.d/rc.inet1 ]; then /bin/hostname `cat /etc/HOSTNAME cut -f1 -d .` /bin/sh /etc/rc.d/rc.inet1 /bin/sh /etc/rc.d/rc.inet2 else /sbin/hostname_notcp `cat /etc/HOSTNAME cut -f1 -d .` /usr/sbin/syslogd /usr/sbin/klogd /usr/sbin/lpd fi # # Remove stale locks (must be done after mount -a!) # /bin/rm -f /var/spool/locks/* /var/spool/uUCp/LCK..* /tmp/.X*lock 1> /dev/null 2> /dev/null # # Remove stale hunt sockets so the game can start. # if [ -r /tmp/hunt -o -r /tmp/hunt.stats ]; then echo "Removing your stale hunt sockets from /tmp..." /bin/rm -f /tmp/hunt* fi # # Update all the shared library links automatically # /sbin/ldconfig # # Start the sendmail daemon: # # 启动信件收发处理程式,每15分钟处理一次待送信件 # if [ -x /usr/sbin/sendmail ]; then echo "Starting mail daemon ( sendmail -bd -q 15m )..." /usr/sbin/sendmail -bd -q 15m fi # # Load a custom screen font if the user has an rc.font script. # # 载入自定的萤幕字型 # if [ -r /etc/rc.d/rc.font ]; then /etc/rc.d/rc.font fi # # Start the local setup procedure. # /etc/rc.d/rc.local # end of /etc/rc.d/rc.M * 上表除中文说明外,节录自slackware 2.1.0之/etc/inittab 其他系统档案 1. /etc/issue 这个档案的内容会在系统显示login:提示之前出现在使用 者的virtual console或终端机上。如果是telnet时,系统 是显示/etc/issue.net。 2. /etc/motd 即message of today,会在使用者进入shell之前显示,通 常是放系统的最新通知事项。 3. /etc/mtools slackware有一组指令包括mdir,mcopy等,可直接读取DOS 的磁片、硬碟内档案,这档内必须定义软碟机、硬碟机参 数。 # # Parameters for the /usr/bin/mtools utilities # A /dev/fd0 12 0 0 0 # Generic autodetect B /dev/fd1 12 0 0 0 # Generic autodetect # end of /etc/mtools 如有任何建议或更正,欢迎email到[email protected]
[1] [2] 下一页
(出处:http://www.sheup.com)