Chinaunix首页 | 论坛 | 博客
  • 博客访问: 57357
  • 博文数量: 25
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 265
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-27 10:47
文章分类

全部博文(25)

文章存档

2011年(1)

2008年(24)

我的朋友
最近访客

分类: LINUX

2008-09-08 10:00:27

在分析Linux系统启动过程时,想观察rc.sysinit何时启动何时结束。于是,在rc.sysinit的开头和末尾分别加了句
echo $0 Start

echo $0 Finish
结果在启动时发现:
紧接在“INIT:version 2.85 booting”之后
“/etc/rc.d/rc.sysinit Start”连着出现了2次
而最后的“/etc/rc.d/rc.sysinit Finish”只出现一次,很奇怪。于是查看rc.sysinit,发现开头有这么几句:
if [ -z "$IN_INITLOG" -a -x /sbin/initlog ]; then
    exec /sbin/initlog -r /etc/rc.d/rc.sysinit
fi
恍然大悟,原来为了将rc.sysinit的运行信息记到syslog里(/var/log/messages),使用了进程替代:
exec /sbin/initlog -r /etc/rc.d/rc.sysinit
man了一下initlog,是这么说的:
initlog logs messages and events to the system logger.  It is mainly designed for use in init scripts.
-r, --run=[program]
              Execute the specified program, with an open file descriptor so that the program can pass back commands to initlog.
 
还有个-c参数
-c, --cmd=[program]
Execute the specified program, logging anything output to stdout or stderr.

可以用-c参数做实验:
[root@linux ~]# initlog -c 'ls /'
bin
boot
dev
etc
home
iptables
lib
mnt
opt
proc
root
sbin
sys
tmp
usr
var
[root@linux ~]# tail -20 /var/log/messages
Sep  8 09:30:01 linux crond(pam_unix)[26258]: session closed for user root
Sep  8 09:40:01 linux crond(pam_unix)[26282]: session opened for user root by (uid=0)
Sep  8 09:40:01 linux crond[26283]: (root) CMD (/usr/lib/sa/sa1 1 1)
Sep  8 09:40:02 linux crond(pam_unix)[26282]: session closed for user root
Sep  8 09:45:12 linux ls: bin
Sep  8 09:45:12 linux ls: boot
Sep  8 09:45:12 linux ls: dev
Sep  8 09:45:12 linux ls: etc
Sep  8 09:45:12 linux ls: home
Sep  8 09:45:12 linux ls: iptables
Sep  8 09:45:12 linux ls: lib
Sep  8 09:45:12 linux ls: mnt
Sep  8 09:45:12 linux ls: opt
Sep  8 09:45:12 linux ls: proc
Sep  8 09:45:12 linux ls: root
Sep  8 09:45:12 linux ls: sbin
Sep  8 09:45:12 linux ls: sys
Sep  8 09:45:12 linux ls: tmp
Sep  8 09:45:12 linux ls: usr
Sep  8 09:45:12 linux ls: var

再观察rc.sysinit记在messages中的信息
[root@rhel ~]# grep rc.sysinit /var/log/messages
Sep  8 16:41:19 rhel rc.sysinit: -e
Sep  8 16:41:32 rhel rc.sysinit: -e
Sep  8 16:41:46 rhel rc.sysinit: Configuring kernel parameters:  succeeded
Sep  8 08:41:47 rhel rc.sysinit: Setting clock  (localtime): Mon Sep  8 08:41:47 CST 2008 succeeded
Sep  8 08:41:47 rhel rc.sysinit: Loading default keymap succeeded
Sep  8 08:41:47 rhel rc.sysinit: Setting hostname rhel.test.org:  succeeded
Sep  8 08:41:48 rhel rc.sysinit: Checking root filesystem succeeded
Sep  8 08:41:48 rhel rc.sysinit: Remounting root filesystem in read-write mode:  succeeded
Sep  8 08:41:49 rhel rc.sysinit: Setting up Logical Volume Management: succeeded
Sep  8 08:41:49 rhel rc.sysinit: Checking filesystems succeeded
Sep  8 08:41:50 rhel rc.sysinit: Mounting local filesystems:  succeeded
Sep  8 08:41:50 rhel rc.sysinit: Enabling local filesystem quotas:  succeeded
Sep  8 08:41:51 rhel rc.sysinit: Enabling swap space:  succeeded
Sep  8 16:57:33 rhel rc.sysinit: -e
Sep  8 16:57:47 rhel rc.sysinit: -e
Sep  8 16:57:47 rhel rc.sysinit: Configuring kernel parameters:  succeeded
Sep  8 08:57:49 rhel rc.sysinit: Setting clock  (localtime): Mon Sep  8 08:57:49 CST 2008 succeeded
Sep  8 08:57:49 rhel rc.sysinit: Loading default keymap succeeded
Sep  8 08:57:49 rhel rc.sysinit: Setting hostname rhel.test.org:  succeeded
Sep  8 08:57:54 rhel rc.sysinit: Checking root filesystem succeeded
Sep  8 08:57:54 rhel rc.sysinit: Remounting root filesystem in read-write mode:  succeeded
Sep  8 08:57:55 rhel rc.sysinit: Setting up Logical Volume Management: succeeded
Sep  8 08:57:55 rhel rc.sysinit: Checking filesystems succeeded
Sep  8 08:57:56 rhel rc.sysinit: Mounting local filesystems:  succeeded
Sep  8 08:57:56 rhel rc.sysinit: Enabling local filesystem quotas:  succeeded
Sep  8 08:57:57 rhel rc.sysinit: Enabling swap space:  succeeded
Sep  8 17:00:38 rhel rc.sysinit: -e
Sep  8 17:00:52 rhel rc.sysinit: -e
Sep  8 17:00:53 rhel rc.sysinit: Configuring kernel parameters:  succeeded
Sep  8 09:00:51 rhel rc.sysinit: Setting clock  (localtime): Mon Sep  8 09:00:51 CST 2008 succeeded
Sep  8 09:00:51 rhel rc.sysinit: Loading default keymap succeeded
Sep  8 09:00:51 rhel rc.sysinit: Setting hostname rhel.test.org:  succeeded
Sep  8 09:00:51 rhel rc.sysinit: Checking root filesystem succeeded
Sep  8 09:00:51 rhel rc.sysinit: Remounting root filesystem in read-write mode:  succeeded
Sep  8 09:00:52 rhel rc.sysinit: Setting up Logical Volume Management: succeeded
Sep  8 09:00:53 rhel rc.sysinit: Checking filesystems succeeded
Sep  8 09:00:53 rhel rc.sysinit: Mounting local filesystems:  succeeded
Sep  8 09:00:53 rhel rc.sysinit: Enabling local filesystem quotas:  succeeded
Sep  8 09:00:54 rhel rc.sysinit: Enabling swap space:  succeeded
Sep  8 17:05:39 rhel rc.sysinit: -e
Sep  8 17:05:58 rhel rc.sysinit: -e
Sep  8 17:05:59 rhel rc.sysinit: Configuring kernel parameters:  succeeded
Sep  8 09:05:58 rhel rc.sysinit: Setting clock  (localtime): Mon Sep  8 09:05:58 CST 2008 succeeded
Sep  8 09:05:58 rhel rc.sysinit: Loading default keymap succeeded
Sep  8 09:05:58 rhel rc.sysinit: Setting hostname rhel.test.org:  succeeded
Sep  8 09:05:58 rhel rc.sysinit: Checking root filesystem succeeded
Sep  8 09:05:58 rhel rc.sysinit: Remounting root filesystem in read-write mode:  succeeded
Sep  8 09:05:59 rhel rc.sysinit: Setting up Logical Volume Management: succeeded
Sep  8 09:06:00 rhel rc.sysinit: Checking filesystems succeeded
Sep  8 09:06:00 rhel rc.sysinit: Mounting local filesystems:  succeeded
Sep  8 09:06:00 rhel rc.sysinit: Enabling local filesystem quotas:  succeeded
Sep  8 09:06:01 rhel rc.sysinit: Enabling swap space:  succeeded
Sep  8 17:10:58 rhel rc.sysinit: -e
Sep  8 17:11:13 rhel rc.sysinit: -e
Sep  8 17:11:14 rhel rc.sysinit: Configuring kernel parameters:  succeeded
Sep  8 09:11:11 rhel rc.sysinit: Setting clock  (localtime): Mon Sep  8 09:11:11 CST 2008 succeeded
Sep  8 09:11:11 rhel rc.sysinit: Loading default keymap succeeded
Sep  8 09:11:11 rhel rc.sysinit: Setting hostname rhel.test.org:  succeeded
Sep  8 09:11:12 rhel rc.sysinit: Checking root filesystem succeeded
Sep  8 09:11:12 rhel rc.sysinit: Remounting root filesystem in read-write mode:  succeeded
Sep  8 09:11:13 rhel rc.sysinit: Setting up Logical Volume Management: succeeded
Sep  8 09:11:13 rhel rc.sysinit: Checking filesystems succeeded
Sep  8 09:11:13 rhel rc.sysinit: Mounting local filesystems:  succeeded
Sep  8 09:11:13 rhel rc.sysinit: Enabling local filesystem quotas:  succeeded
Sep  8 09:11:14 rhel rc.sysinit: Enabling swap space:  succeeded
Sep  8 17:14:55 rhel rc.sysinit: -e
Sep  8 17:15:10 rhel rc.sysinit: -e
Sep  8 17:15:11 rhel rc.sysinit: Configuring kernel parameters:  succeeded
Sep  8 09:15:09 rhel rc.sysinit: Setting clock  (localtime): Mon Sep  8 09:15:09 CST 2008 succeeded
Sep  8 09:15:09 rhel rc.sysinit: Loading default keymap succeeded
Sep  8 09:15:09 rhel rc.sysinit: Setting hostname rhel.test.org:  succeeded
Sep  8 09:15:14 rhel rc.sysinit: Checking root filesystem succeeded
Sep  8 09:15:14 rhel rc.sysinit: Remounting root filesystem in read-write mode:  succeeded
Sep  8 09:15:15 rhel rc.sysinit: Setting up Logical Volume Management: succeeded
Sep  8 09:15:15 rhel rc.sysinit: Checking filesystems succeeded
Sep  8 09:15:16 rhel rc.sysinit: Mounting local filesystems:  succeeded
Sep  8 09:15:16 rhel rc.sysinit: Enabling local filesystem quotas:  succeeded
Sep  8 09:15:17 rhel rc.sysinit: Enabling swap space:  succeeded
阅读(1004) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~