whatis rc rc(8) - command scripts for auto-reboot and daemon startup 这些脚本实际位于/etc/rc;通常,位于/etc下的这个配置文件对应于手册的第五部分,所以你可以根据手册对配置文件作正确地修改。但是,如果你打:
man 5 rc 你却会得到以下信息:
No entry for rc in section 5 of the manual 这对于上面提到的它位于手册第八部分来说看起来有点古怪,因为这部分手册包含的是系统维护和操作命令,通常它们都是后台进程。让我们进一步来看一下这个文件:
more /etc/rc # System startup script run by init on autoboot # or after single-user. # Output and error are redirected to console by init, # and the console is the controlling terminal. # Note that almost all of the user-configurable behavior # is no longer in # this file, but rather in /etc/defaults/rc.conf. # Please check that file first before contemplating any changes # here. If you do need to change this file for some reason, we # would like to know about it. 好,相当清晰;看来对于该文件我们自己是不能乱来的。这里有些相当重要的东西对于正确引导我们的系统所必须的。让我们往后跳,看一些重要的部分来找出启动时实际上都发生了些什么。注意当在引导过程中处理rc脚本时,init会把所有的输出和错误信息记录到终端上。
# If there is a global system configuration file, suck it in. if [ -f /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf elif [ -f /etc/rc.conf ]; then . /etc/rc.conf fi 接着它会作一个文件系统连贯性检查。如果你曾经非正常关闭FreeBSD系统,你会在引导过程中看到它在这一步上发出抱怨的。
echo Automatic boot in progress... fsck -p 假定fsck没有遇到任何问题,它就马上装载你的文件系统:
# Mount everything except nfs filesystems. mount -a -t nonfs 在其它任何进程启动之前,你的CMOS时钟必须调整为内核时钟可以理解的形式:
adjkerntz -i 然后整理var目录,将引导信息写入dmesg.boot:
clean_var() { if [ ! -f /var/run/clean_var ]; then rm -rf /var/run/* find /var/spool/lock ! -type d -delete rm -rf /var/spool/uucp/.Temp/* # Keep a copy of the boot messages around dmesg >/var/run/dmesg.boot 接着rc会读取以下文件:
# Whack the pty perms back into shape. chflags 0 /dev/tty[pqrsPQRS]* chmod 666 /dev/tty[pqrsPQRS]* chown root:wheel /dev/tty[pqrsPQRS]* 并清理自己产生的“垃圾”以及/tmp目录:
# Clean up left-over files # Clearing /tmp at boot-time seems to have a long tradition. It doesn't # help in any way for long-living systems, and it might accidentally # clobber files you would rather like to have preserved after a crash # (if not using mfs /tmp anyway). # See also the example of another cleanup policy in /etc/periodic/daily. # Remove X lock files, since they will prevent you from restarting X11 # after a system crash. 现在rc准备启动一些后台进程,首先是syslogd和named:
# Start system logging and name service. Named needs to start before syslogd # if you don't have a /etc/resolv.conf. 然后是inetd、cron、lpd、sendmail、sshd和usbd:
# Now start up miscellaneous daemons that don't belong anywhere else 接着rc将更新motd(每日信息)并执行“uname -m”,这条命令会在屏幕上显示构架类型。
type 对于虚拟终端,对应的类型为cons25。其它通常的值包括伪终端network,调制解调器入口dialup,以及unknown,用于用户试图以无法预定的类型进行连接的终端。
status 它必须是on或off。如果是on,init将运行getty栏指定的程序。如果出现单词“secure”,说明该tty允许root登录;为避免这种情况,可以用单词“insecure”。
让我们从虚拟终端部分开始解释该文件;可以看到它是以设置控制台开始的:
# If console is marked "insecure", then init will ask # for the root password when going to single-user mode. console none unknown off secure 如果在引导过程中fsck命令运行出了问题,init将使你的FreeBSD系统进入单用户模式以使root用户可以修复问题。如果你用insecure代替secure来设置控制台,init将在你可以继续干之前索取口令。
ttyv0 "/usr/libexec/getty Pc" cons25 on secure # Virtual terminals ttyv1 "/usr/libexec/getty Pc" cons25 on secure ttyv2 "/usr/libexec/getty Pc" cons25 on secure ttyv3 "/usr/libexec/getty Pc" cons25 on secure ttyv4 "/usr/libexec/getty Pc" cons25 on secure ttyv5 "/usr/libexec/getty Pc" cons25 on secure ttyv6 "/usr/libexec/getty Pc" cons25 on secure ttyv7 "/usr/libexec/getty Pc" cons25 on secure ttyv8 "/usr/X11R6/bin/xdm -nodaemon" xterm off secure 你可以看到在我的FreeBSD系统上除了控制台以外还有八个虚拟终端;我可以通过按ALT键加一个控制键来访问每个终端。例如ALT F1可访问控制台,ALT F2访问ttyv1, ALT F3访问ttyv2,等等。如果我启动了X会话,那么它可以用ALT F8来访问。如果我把ttyv8上的单词off改为on,那么我可以在引导时得到一个X终端而不是控制台。然后可以继续用我ALT加功能键来访问其它终端。我的所有这些虚拟终端都标为“secure”,说明它们都可接受root登录。你可以有多少个虚拟终端是由你的FreeBSD版本所决定的;如果你希望建立更多虚拟终端,可以读一下这个faq。
现在让我们移到拨号终端:
# Serial terminals # The 'dialup' keyword identifies dialin lines to login, fingerd etc. ttyd0 "/usr/libexec/getty std.9600" dialup off secure ttyd1 "/usr/libexec/getty std.9600" dialup off secure ttyd2 "/usr/libexec/getty std.9600" dialup off secure ttyd3 "/usr/libexec/getty std.9600" dialup off secure 你可以看到我有四个可获得的拨号终端,但它们都被关闭了