LinuxSir.Org  
| 网站首页 | 论坛帮助 |

欢迎来到LinuxSir.Org!
您还未登录,请登录后查看论坛,或者点击论坛上方的注册链接注册新账号。


发表新主题 回复
精华主题  
主题工具
旧 05-02-22, 19:00 第 1 帖
ygw_ycf
 
 
 
注册会员  
  注册日期: Oct 2003
  帖子: 270
  精华: 3
 

标题: arch 的boot scripts初探


让我们先看看官方文档里的介绍
Boot Scripts


Arch Linux uses a fairly simple bootup sequence quite similar to *BSDs. The first boot script to run is /etc/rc.sysinit. When it's done, /etc/rc.multi will be called (in a normal bootup). The last script to run will be /etc/rc.local. When started in runlevel 1, the single user mode, the script /etc/rc.single is run instead of /etc/rc.multi. You will not find an endless symlink collection in the /etc/rc?.d/ directories to define the bootup sequence for all possible runleves. In fact, due to this approach Arch only really has three runlevels, if you take starting up X in runlevel 5 into account. The boot scripts are using the variables and definitions found in the /etc/rc.conf file and also a set of general functions defined in the /etc/rc.d/functions script. If you plan to write your own daemon files, you should consider having a look at this file and existing daemon scripts.
简单翻译:
arch linux 使用一种特别简单的起动顺序,非常类似于*BSDs.首先起动的脚本是/etc/rc.sysint. 当它起动完后,/etc/rc.muti 将起动(正常起动情况),最后起动的脚本是/etc/rc.local .当起动在单用户模式,将用/etc/rc.single代替rc.multi.你不能在/etc/rc?.d这个为所有运行级别定义起动顺序的目录找到那些脚本连接。实际上,由于这一原因,arch只有三个运行级别,你可以在运行级别5起动X。起动脚本使用的变量及函数可以在/etc/rc.conf 和/etc/rc.d/functions 脚本中找到。如果你计划写自己的守护例程。你应该看看这些文件和已经存在的守护脚本。
呵呵,看看arch 是多么的简单!
大家可以在rc.sysinit 开头和结尾 加入
echo “*********rc.sysinit start********"
echo "**********rc.sysinit stop ******"
同理,rc.multi ,rc.local 加入一些!
重启来体会linux 的起动过程! ---呵呵憋脚的翻译!先写到这里!接下来我们看看rc.sysinit都干了写什么!
  ygw_ycf 当前离线   回复时引用此帖
旧 05-02-22, 19:08 第 2 帖
diony
 
diony 的头像
 
 
注册会员  
  注册日期: Jan 2005
  帖子: 2,162
  精华: 10
 

搬个凳子坐着等。

ps:第一个echo后面的引号还是改成英文符号吧。







__________________
Desktop:
| Core2Duo E6550 | ECS P35T-A | 2G DDR800 X 2 DualChannel | HD4870|
640G SATA X 1
500G SATA X 2
320G SATA X 1

Laptop:
ASUS A8SC Z99S

-------------
别把别人当成猪,但愿自己不是狗。
-------------
  diony 当前离线   回复时引用此帖
旧 05-02-22, 23:11 第 3 帖
ygw_ycf
 
 
 
注册会员  
  注册日期: Oct 2003
  帖子: 270
  精华: 3
 

同样,我们先看看官方文档
/etc/rc.sysinit
The main system boot script. It does boot-critical things like mounting filesystems, running devfsd, activating swap, loading modules, setting localization parameters, etc. You will most likely never need to edit this file!
系统主要的起动脚本,它作一些起动时重要的事情!诸如,挂载文件系统,运行devfsd,激活交换分区,加载模块,设置local,等等。你最好不要编辑这个文件!
说的非常的明白,我把文件内容贴在下面!----已经包含rc.conf,functions,目的是更好的对照理解!
#!/bin/sh
#
# /etc/rc.sysinit
#

. /etc/rc.conf #引用rc.conf 里的变量及函数 .把rc。conf装入内存
下面是rc。conf的内容
HARDWARECLOCK="localtime"
TIMEZONE=Asia/Shanghai
KEYMAP=us
CONSOLEFONT=
USECOLOR="yes"
# Scan for LVM volume groups at startup, required if you use LVM
USELVM="no"

# Networking
HOSTNAME="myhost"
# Module to load at boot-up
MODULES=(usbserial ide-scsi forcedeth snd-intel8x0 snd-pcm-oss)
# Note: to use DHCP, set your interface to be "dhcp" (eth0="dhcp")
#
lo="lo 127.0.0.1"
eth0="dhcp"
INTERFACES=(lo eth0)

#
# Routes to start at boot-up (in this order#
gateway="default gw 192.168.1.1"
ROUTES=(gateway)
# Daemons to start at boot-up (in this order)
# (prefix a daemon with a ! to disable it)

DAEMONS=(syslog-ng hotplug !pcmcia network !netfs !crond alsamixer !xinetd)
以上是rc.conf的内容

. /etc/rc.d/functions #把functions装入,引用functions里的函数
下面是fuctions的内容
STAT_COL=$[`stty size | awk 'BEGIN { RS=" " }; END { print $1 }'` - 13]

# colors:

if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then

C_MAIN="\033[1;37m" # main text
C_OTHER="\033[1;34m" # prefix & brackets
C_SEPARATOR="\033[1;30m" # separator

C_BUSY="\033[0;36m" # busy
C_FAIL="\033[1;31m" # failed
C_DONE="\033[1;37m" # completed

C_H1="\033[1;37m" # highlight text 1
C_H2="\033[1;36m" # highlight text 2

C_CLEAR="\033[1;0m"
fi

# prefixes:

PREFIX_REG="::"
PREFIX_HL=" >"

# functions:

deltext() {
echo -ne "\033[$(($STAT_COL+4))G"
}

printhl() {
echo -e "$C_OTHER$PREFIX_HL $C_H1$1$C_CLEAR "
}

printsep() {
echo -e "\n$C_SEPARATOR ------------------------------\n"
}

stat_busy() {
echo -ne "$C_OTHER$PREFIX_REG $C_MAIN$1$C_CLEAR "
deltext
echo -ne " $C_OTHER[${C_BUSY}BUSY$C_OTHER]$C_CLEAR "
}

stat_done() {
deltext
echo -e " $C_OTHER[${C_DONE}DONE$C_OTHER]$C_CLEAR "
}

stat_fail() {
deltext
echo -e " $C_OTHER[${C_FAIL}FAIL$C_OTHER]$C_CLEAR "
}

stat_die() {
retval=1
[ "$1" = "" ] || retval=$1
stat_fail
exit $retval
}

status() {
stat_busy "$1"
shift
$* >/dev/null 2>&1
if [ $? -eq 0 ]; then
stat_done
return 0
else
stat_fail
return 1
fi
}

# daemons:

add_daemon() {
[ -d /var/run/daemons ] || mkdir -p /var/run/daemons
touch /var/run/daemons/$1
}

rm_daemon() {
rm -f /var/run/daemons/$1
}

ck_daemon() {
[ -f /var/run/daemons/$1 ] && return 1
return 0
}

# End of file以上是fuctions的函数


echo " "
printhl "Arch Linux v0.7 $C_OTHER(${C_H2}Wombat$C_OTHER)\n"
printhl "${C_H2}http://www.archlinux.org"
printhl "Copyright 2002-2004 Judd Vinet"
printhl "Distributed under the GNU General Public License (GPL)"
printsep

# start up our mini logger until syslog takes over
/sbin/minilogd

# anything more serious than KERN_WARNING goes to the console
/bin/dmesg -n 3

# mount /proc and /sys
mount -n -t proc none /proc
[ "`grep sysfs /proc/filesystems`" ] && mount -n -t sysfs none /sys

if [ -e /dev/.devfsd -a -x /sbin/devfsd ]; then
# Looks like devfs is running, use it
status "Starting DevFS Daemon" /sbin/devfsd /dev
elif [ -x /etc/start_udev -a -d /sys/block ]; then
# We have a start_udev script and /sys appears to be mounted, use UDev
status "Starting UDev Daemon" /etc/start_udev
else
# Static /dev, our last resort
status "Using static /dev filesystem" /bin/true
fi

if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
if [ -f /etc/lvmtab -a -x /sbin/vgchange ]; then
# Kernel 2.4.x, LVM1 groups
stat_busy "Activating LVM1 groups"
/sbin/vgchange -a y
stat_done
elif [ -x /sbin/lvm -a -d /sys/block ]; then
# Kernel 2.6.x, LVM2 groups
stat_busy "Activating LVM2 groups"
/sbin/lvm vgchange --ignorelockingfailure -a y
stat_done
fi
fi

status "Activating Swap" /sbin/swapon -a #激活swap分区

status "Mounting Root Read-only" /bin/mount -n -o remount,ro / #挂载分区

if [ -x /sbin/fsck ]; then #检查文件系统
stat_busy "Checking Filesystems"
/sbin/fsck -A -T -C -a
if [ $? -gt 1 ]; then
stat_fail
echo
echo "***************** FILESYSTEM CHECK FAILED ****************"
echo "* *"
echo "* Please repair manually and reboot. Note that the root *"
echo "* file system is currently mounted read-only. To remount *"
echo "* it read-write type: mount -n -o remount,rw / *"
echo "* When you exit the maintenance shell the system will *"
echo "* reboot automatically. *"
echo "* *"
echo "************************************************************"
echo
/sbin/sulogin -p
echo "Automatic reboot in progress..."
/bin/umount -a
/bin/mount -n -o remount,ro /
/sbin/reboot -f
exit 0
fi
stat_done
fi

stat_busy "Mounting Local Filesystems"
/bin/mount -n -o remount,rw /
/bin/rm -f /etc/mtab*
# make sure / gets written to /etc/mtab
/bin/mount -o remount,rw /
# re-mount /proc and /sys so they can be written to /etc/mtab
umount /proc && mount -t proc none /proc
[ "`grep sysfs /proc/filesystems`" ] && umount /sys && mount -t sysfs none /sys
# now mount all the local filesystems
/bin/mount -a -t nonfs,nosmbfs,noncpfs,nosysfs,nousbfs
stat_done

stat_busy "Configuring System Clock" #设置时间
if [ "$HARDWARECLOCK" = "UTC" ]; then
/sbin/hwclock --utc --hctosys
else
/sbin/hwclock --localtime --hctosys
fi
if [ ! -f /var/lib/hwclock/adjtime ]; then
echo "0.0 0 0.0" > /var/lib/hwclock/adjtime
fi
if [ "$TIMEZONE" != "" ]; then
/bin/ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
fi
stat_done

stat_busy "Removing Leftover Files" #不太清楚,清除临时文件,可能主要目的是为了检测,如daemons起动成功,会向/var/run写入一些空的文件,如果有这些文件,表明起动成功,所以起动时先清空。
/bin/rm -f /etc/nologin &> /dev/null
/bin/rm -f /etc/shutdownpid &> /dev/null
/bin/rm -f /var/locks/* &> /dev/null
/bin/rm -f /var/run/*.pid &> /dev/null
/bin/rm -f /var/run/daemons/* &>/dev/null
/bin/rm -rf /tmp/* /tmp/.* &> /dev/null
: > /var/run/utmp
# Keep {x,k,g}dm happy with xorg
mkdir /tmp/.ICE-unix && chmod 1777 /tmp/.ICE-unix
mkdir /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix
stat_done

status "Updating Shared Library Links" /sbin/ldconfig
#检查依赖关系,这一步有人把它注释,以加快起动速度,意义不大!

if [ "$HOSTNAME" != "" ]; then
status "Setting Hostname: $HOSTNAME" /bin/hostname $HOSTNAME
fi

status "Updating Module Dependencies" /sbin/depmod -A

if [ -f /var/run/random-seed ]; then
stat_busy "Initializing Random Seed"
/bin/cat /var/run/random-seed >/dev/urandom
stat_done
fi

if [ "$KEYMAP" != "" ]; then
status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q $KEYMAP
fi

if [ "$CONSOLEFONT" != "" ]; then
stat_busy "Loading Console Font: $CONSOLEFONT"
for i in `seq 1 12`; do
/usr/bin/setfont $CONSOLEFONT -C /dev/vc/${i};
done
stat_done
fi

# Load modules from the MODULES array defined in rc.conf#加载rc。conf中定义的模块
stat_busy "Loading Modules"
for mod in "${MODULES[@]}"; do
if [[ `echo $mod | grep '^[^\!]' | wc -l` -eq 1 ]]; then
/sbin/modprobe $mod
fi
done
stat_done

# Now that modules are loaded, try to mount /proc/bus/usb
[ "`grep usbfs /proc/filesystems`" ] && mount -t usbfs none /proc/bus/usb

# Screen blanks after 15 minutes idle time
/usr/bin/setterm -blank 15

# End of file
相对其它系统的rc.sysinit,arch的还是比较简单,易懂的。正如其文档所说!
有些地方我也不太懂,以后补充
下面看看rc.multi的内容

此帖于 05-02-22 23:20 被 ygw_ycf 编辑.
  ygw_ycf 当前离线   回复时引用此帖
旧 05-02-22, 23:33 第 4 帖
ygw_ycf
 
 
 
注册会员  
  注册日期: Oct 2003
  帖子: 270
  精华: 3
 

同样看看官方文档简介
/etc/rc.multi
Multi-user startup script. It starts all daemons you configured in the DAEMONS array (set in /etc/rc.conf) after which it calls /etc/rc.local. You shouldn't feel a pressing need to edit this file.
多用户环境起动脚本,它起动所有你在rc.conf里设置的守护进程,之后,起动rc.local
看看rc.multi内容:
!/bin/sh
#
# /etc/rc.multi
#
echo "*****************************ok rc.multi start***********************"
. /etc/rc.conf #同样装入 rc.conf ,functions
. /etc/rc.d/functions

# Start daemons 起动daemons
for daemon in "${DAEMONS[@]}"; do
if [[ `echo $daemon | grep '^[^\!]' | wc -l` -eq 1 ]]; then
/etc/rc.d/$daemon start #可见rc.d 下全是些daemons的起动脚本,如果想编写自己的守护进程,可放到这里,然后加入到rc.conf 里的DAEMONS
fi
done
echo " let sleep 6 seconds" 我加的
sleep 6s
echo "let 's go on"
if [ -x /etc/rc.local ]; then 执行rc.local
/etc/rc.local
fi
echo "***************************ok rc.multi stop*************************"
# End of file
rc.loca的内容,我的是空的
#!/bin/sh
#
# /etc/rc.local: Local multi-user startup script.
#
echo "ok"
# End of file
  ygw_ycf 当前离线   回复时引用此帖
旧 08-12-18, 18:34 第 5 帖
kevinlei
 
kevinlei 的头像
 
 
注册会员  
  注册日期: Sep 2003
  帖子: 454
  精华: 0
 

ARCHLINUX的minilogd有BUG, 在SYSLOG不启动的情况下, 会占用大量内存直至死机...
  kevinlei 当前离线   回复时引用此帖
旧 08-12-19, 07:54 第 6 帖
activeion
 
activeion 的头像
 
 
注册会员  
  注册日期: Oct 2002
  帖子: 182
  精华: 1
 

多谢, 学习了。
  activeion 当前离线   回复时引用此帖
发表新主题 回复


主题工具

发帖规则
您 [不可以] 发表新主题
您 [不可以] 回复主题
您 [不可以] 上传附件
您 [不可以] 编辑您的帖子

已 [启用] BB 代码
已 [启用] 表情符号
已 [启用] IMG 代码
已 [禁用] HTML 代码
[论坛跳转…]


所有时间均为[北京时间]。现在的时间是 11:04


Powered by vBulletin 版本 3.6.8
版权所有 ©2000 - 2012, Jelsoft Enterprises Ltd.
官方中文技术支持: vBulletin 中文
版权所有 ©2002 - 2011, LinuxSir.Org