Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1532503
  • 博文数量: 290
  • 博客积分: 3468
  • 博客等级: 中校
  • 技术积分: 3461
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-28 22:21
文章分类

全部博文(290)

文章存档

2016年(13)

2015年(3)

2014年(42)

2013年(67)

2012年(90)

2011年(75)

分类:

2012-08-20 09:47:11

######################################################################################################################################################## 
update_boot_stage RCraid                                        # 下面部分是激活 RAID 的
if [ -f /etc/mdadm.conf ]; then                                # 如果存在 /etc/mdadm.conf 则
    /sbin/mdadm -A -s                                                # mdadm -A 表示 Assemble 模式,-s 则表示搜索 /etc/mdadm.conf 
fi
 
# 注释 :下面解决旧式的用 raid-tools 建立的 software-raid
 
if [ -f /etc/raidtab ]; then                                        # 如果存在旧式的 raidtools 的 /etc/raidtab 则
    # Add raid devices
    [ -f /proc/mdstat ] || modprobe md >/dev/null 2>&1        # 如果不存在 /proc/mdstat 文件,则用 modprobe md 先加载 md 模块
    if [ -f /proc/mdstat ]; then
         echo -n $"Starting up RAID devices: "                             # 并输出 "Starting up RAID devices:" 
         rc=0                                                                           # 先把 rc 的值设置为0,如果有某个 raid 激活失败,则 rc 为 1
                                                                                          # rc  和下面的 RESULT 不同,RESULT 是每个 raid 的激活状态,而 rc 是全局的激活状态
         for i in `awk '{if ($1=="raiddev") print $2}' /etc/raidtab`     # 用 awk 从 /etc/raidtab 中找出所有 raiddev 行打印第2个字段也就是 raid 的设备名
         do                                                                                    # 针对每个 Software-raid 执行下面的代码
                RAIDDEV=`basename $i`                                                # 把每个 raid 设备的设备名(出去前面目录部分)赋予变量 RAIDDEV
                RAIDSTAT=`LC_ALL=C grep "^$RAIDDEV : active" /proc/mdstat`            # 如果 /proc/mdstat 中表明该 RAID 已经是 active 的状态
                if [ -z "$RAIDSTAT" ]; then                                                                # 如果状态为空,表明该 RAID 并没有激活
                    # First scan the /etc/fstab for the "noauto"-flag
                    # for this device. If found, skip the initialization
                    # for it to avoid dropping to a shell on errors.
                    # If not, try raidstart...if that fails then
                    # fall back to raidadd, raidrun.  If that
                    # also fails, then we drop to a shell
                    RESULT=1                                                                                    # 先把 RESULT 设置为 1,表示 false
                    INFSTAB=`LC_ALL=C grep -c "^$i" /etc/fstab`                                 # 然后检查 /etc/fstab 中是否有以指定的 md 设备开头的行,结果赋予 INFSTAB
                    if [ $INFSTAB -eq 0 ] ; then                                                           # 如果 INFSTAB 为0,表示没有找到,也就是不希望自动我你挂载该 raid 设备
                           RESULT=0                                                                                # 则把 RESULT 设置为0
                           RAIDDEV="$RAIDDEV(skipped)"                                                    # 并在 RAIDDEV 后面加上 (skipped) ,表示该设备跳过不激活它
                    fi
                    NOAUTO=`LC_ALL=C grep "^$i" /etc/fstab | LC_ALL=C fgrep -c "noauto"`    # 如果该设备在 /etc/fstab 中但它的属性含有 noauto 
                    if [ $NOAUTO -gt 0 ]; then                                                                            # 则和上面不在 /etc/fstab 一样处理
                           RESULT=0
                           RAIDDEV="$RAIDDEV(skipped)"
                    fi
                    if [ $RESULT -gt 0 -a -x /sbin/mdadm ]; then                                            # 如果 /sbin/mdadm 文件可执行,且尝试用 mdadm 来激活它们
                            /sbin/mdadm -Ac partitions $i -m dev                                                    # mdadm 将从 /proc/partitions 文件读取并状态指定 raid($i) ,-m 表示 minor 
                                                                                                                                      # number 就等于它刚才装配的 raid 设备名的数字部分
                            RESULT=$?                                                                                           # 并把 mdadm 的结果赋予 RESULT 变量
                    fi
                    if [ $RESULT -gt 0 -a -x /sbin/raidstart ]; then                                            # 如果 RESULT 大于0,表示 madm 命令失败,则尝试用 /sbin/raidstart 来
                        /sbin/raidstart $i
                        RESULT=$?                                                                                    
                    fi
                    if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then                                             # 如果 raidstart 还是失败,则尝试用 raid0run 来
                        /sbin/raid0run $i
                        RESULT=$?
                    fi
                    if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then                  # 如果 raid0run 失败则尝试用 raidadd 然后用 raidrun 
                        /sbin/raidadd $i
                        /sbin/raidrun $i
                        RESULT=$?
                    fi
                    if [ $RESULT -gt 0 ]; then                                                                         # 如果还是失败,则 rc 的值最终为1
                        rc=1
                   fi
                    echo -n "$RAIDDEV "                                                                                # 输出当前操作的 raid 设备名
                else            # 这个 else 是对应 ”if [ -z "$RAIDSTAT" ]; “的,因为可能内核集成了 raid support ,自动激活 raid 
                       echo -n "$RAIDDEV "                                                                             # 如果 RAID 的状态本来就是 active ,则直接输出 raid 的名称
                fi
         done
 echo
 
 # A non-zero return means there were problems.                    # 如果只要有一个 raid 激活失败,则 rc 的值就为1
 if [ $rc -gt 0 ]; then                                                                # 如果 rc 的值大于0,则表示有 raid 激活失败
         if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then    # 则按照前面 fsck 失败的情况,进入紧急模式
      chvt 1
  fi
  echo
  echo
  echo $"*** An error occurred during the RAID startup"
  echo $"*** Dropping you to a shell; the system will reboot"
  echo $"*** when you leave the shell."
 
  str=$"(RAID Repair)"                                                                            # 只不过提示符有所不同而已,变成了 (RAID Repair)
  PS1="$str \# # "; export PS1
  [ "$SELINUX" = "1" ] && disable_selinux
  sulogin
 
  echo $"Unmounting file systems"
  umount -a
  mount -n -o remount,ro /
  echo $"Automatic reboot in progress."
  reboot -f
 
 fi        # 注释 ;这个 fi 是结束 "if [ -f /etc/raidtab ];" 的,如果不存在 /etc/raidtab ,则直接跳到这里
########################################################################################################################################################
 # LVM2 initialization, take 2                                                        # 由于 LVM 的 pv 可能是建立在 RAID 之上的,所以再次尝试扫描 vg 并激活它们
 if [ -c /dev/mapper/control -a -x /sbin/lvm.static ]; then             # 步骤和前面的一样
  if /sbin/lvm.static vgscan > /dev/null 2>&1 ; then 
   action $"Setting up Logical Volume Management:" /sbin/lvm.static vgscan --mknodes --ignorelockingfailure && /sbin/lvm.static vgchange -a y --ignorelockingfailure
  fi
 fi
 # LVM initialization, take 2 (it could be on top of RAID)
 if [ -e /proc/lvm -a -x /sbin/vgchange -a -f /etc/lvmtab ]; then
  action $"Setting up Logical Volume Management:" /sbin/vgscan && /sbin/vgchange -a y
 fi
    fi
fi
######################################################################################################################################################## 
# 注释 :下面对其他文件系统(/ 除外)的文件系统进行 fsck 
_RUN_QUOTACHECK=0        # 还是把 _RUN_QUOTACHECK 变量的值设置为0
# Check filesystems            # 检查其他文件系统
if [ -z "$fastboot" ]; then        # 如果不存在 /etc/fastboot ,则执行下面的脚本。可以看到 shutdown -r 不仅影响 / 的 fsck ,也影响其他文件系统的 fsck 
        STRING=$"Checking filesystems"        # 打印提示信息
        echo $STRING
         if [ "${RHGB_STARTED}" != "0" -a -w /etc/rhgb/temp/rhgb-console ]; then
                  fsck -T -R -A -a $fsckoptions > /etc/rhgb/temp/rhgb-console                # -R 表示跳过 / 文件系统,其他选项和之前的一样
         else
                  initlog -c "fsck -T -R -A -a $fsckoptions"
         fi
         rc=$?
         if [ "$rc" -eq "0" ]; then                                    #  这部分和之前处理/文件系统的 fsck 结果一样
           success "$STRING"
           echo
        elif [ "$rc" -eq "1" ]; then
           passed "$STRING"
           echo
        elif [ "$rc" -eq "2" -o "$rc" -eq "3" ]; then 
           echo $"Unmounting file systems"
           umount -a
           mount -n -o remount,ro /
           echo $"Automatic reboot in progress."
           reboot -f
        fi
 
         # A return of 4 or higher means there were serious problems.
         if [ $rc -gt 1 ]; then
             if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then
                  chvt 1
             fi
 
             failure "$STRING"
             echo
             echo
             echo $"*** An error occurred during the file system check."
             echo $"*** Dropping you to a shell; the system will reboot"
             echo $"*** when you leave the shell."
 
             str=$"(Repair filesystem)"
             PS1="$str \# # "; export PS1
             [ "$SELINUX" = "1" ] && disable_selinux
             sulogin
 
             echo $"Unmounting file systems"
             umount -a
             mount -n -o remount,ro /
             echo $"Automatic reboot in progress."
             reboot -f
         elif [ "$rc" -eq "1" -a -x /sbin/quotacheck ]; then
             _RUN_QUOTACHECK=1                                        # 如果   fsck 修复成功,则 _RUN_QUOTACHECK 的值修改为1,表示可以进行其他文件系统的 quotacheck 了
         fi        #  这个 fi 是结束  "if [ $rc -gt 1 ]; " 的
fi                # 这个 fi 是结束 ”if [ -z "$fastboot" ];“ 的
 
######################################################################################################################################################## 
# Mount all other filesystems (except for NFS and /proc, which is already            # 挂载除了 /,/proc,/proc/bus/usb,devpts 之外的文件系统
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
action $"Mounting local filesystems: " mount -a -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs -O no_netdev    # 挂载类型为 nonfs、nfs4、smbfs、ncptfs、cifs、gfs 的文件系统
                                                                                      # 但条件是这些文件系统对应在 /etc/fstab 中的属性字段没有 netdev 属性
########################################################################################################################################################  
# Start the graphical boot, if necessary and not done yet.                # 现在又再次检查是否可以启动图形启动界面
if strstr "$cmdline" rhgb && [ "$RHGB_STARTED" -eq 0 -a "$BOOTUP" = "color" -a "$GRAPHICAL" = "yes" -a -x /usr/bin/rhgb ]; then
   LC_MESSAGES= /usr/bin/rhgb
   RHGB_STARTED=1
fi
######################################################################################################################################################## 
# check remaining quotas other than root                                                            # 对 / 系统之外的文件系统进行 quota 检查
if [ X"$_RUN_QUOTACHECK" = X1 -a -x /sbin/quotacheck ]; then                            # 方法和之前对 / 进行 quotachec 一样
     if [ -x /sbin/convertquota ]; then
         # try to convert old quotas
         for mountpt in `awk '$4 ~ /quota/{print $2}' /etc/mtab` ; do
              if [ -f "$mountpt/quota.user" ]; then
                  action $"Converting old user quota files: " \
                  /sbin/convertquota -u $mountpt && \
                   rm -f $mountpt/quota.user
              fi
              if [ -f "$mountpt/quota.group" ]; then
                  action $"Converting old group quota files: " \
                  /sbin/convertquota -g $mountpt && \
                   rm -f $mountpt/quota.group
              fi
     done
 fi
 
 action $"Checking local filesystem quotas: " /sbin/quotacheck -aRnug                # quotachk -augRn 表示对 /etc/fstab 中除了 / 之外,所有启用了 usrquota、grpquota 的 
fi                                                                                                                 # 的文件系统都检查    
 
if [ -x /sbin/quotaon ]; then
    action $"Enabling local filesystem quotas: " /sbin/quotaon -aug                       # 执行 quotaon 启动 quota 功能
fi
######################################################################################################################################################## 
#
# Check to see if SELinux requires a relabel
#
[ -n "$SELINUX" ] && [ -f /.autorelabel ] && relabel_selinux
######################################################################################################################################################## 
# Initialize pseudo-random number generator                                                    # 初始化随机数生成器
if [ -f "/var/lib/random-seed" ]; then                                                                # 如果存在 /var/lib/random-seed 文件,则
 cat /var/lib/random-seed > /dev/urandom                                                            # 把它的内容送给 /dev/urandom
else                                                                                                                # 否则
 touch /var/lib/random-seed                                                                                # 创建该文件
fi
chmod 600 /var/lib/random-seed                                                                     # 修改该文件的权限为 600 (rw-------)
dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null           # 从 /dev/urandom 读入 512 kB 并送给 /var/lib/random-seed 
 
# Use the hardware RNG to seed the entropy pool, if available
[ -x /sbin/rngd -a -f /dev/hw_random ] && rngd                                                # 如果 /sbin/rngd 可执行且存在 /dev/hw_random 文件,则执行 rngd 为加密池生成种子
 
 
######################################################################################################################################################## 
# Configure machine if necessary.                                                                # 这部分允许你在启动时作一些配置(手工的)
if [ -f /.unconfigured ]; then                                                                        # 如果存在 /.unconfigured 文件
    if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then                    # 且 rhgb-client 可执行,rhgb 服务在运行,则
         chvt 1                                                                                                                    # 切换回 1# 控制台
    fi
 
    if [ -x /usr/bin/system-config-keyboard ]; then                                               # 如果 /usr/bin/sysconfig-keyboard 可执行
         /usr/bin/system-config-keyboard                                                                    # 则执行该命令
    fi
    if [ -x /usr/bin/passwd ]; then                                                                        # 如果存在 /usr/bin/passwd ,则
        /usr/bin/passwd root                                                                                        # 执行 passwd root ,修改 root 密码
    fi
    if [ -x /usr/sbin/netconfig ]; then                                                                    # 如果存在 /usr/sbin/netconfig ,则
         /usr/sbin/netconfig                                                                                            #  执行 /usr/sbin/netconfig ,重新配置网络
    fi
    if [ -x /usr/sbin/timeconfig ]; then                                                                    # 如果存在 /usr/sbin/timeconfig ,则
         /usr/sbin/timeconfig                                                                                            # 执行 /usr/sbin/timeconfig 重新配置时间和时区
    fi
    if [ -x /usr/sbin/authconfig ]; then                                                                    # 如果存在 /usr/sbin/authconfig ,则
         /usr/sbin/authconfig --nostart                                                                                # 执行 /usr/sbin/authconfig --nostart 重新配置 shadow、LDAP 、kerberos 等
    fi
    if [ -x /usr/sbin/ntsysv ]; then                                                                            # 如果存在 /usr/sbin/ntsysv ,则
         /usr/sbin/ntsysv --level 35                                                                                    # 执行 /usr/sbin/ntsysv --level 35 对运行级别3,5下的服务启动进行配置
    fi
 
    # Reread in network configuration data.                                                              # 重新读取 /etc/sysconfig/network 文件
    if [ -f /etc/sysconfig/network ]; then                                                                  #  如果存在该文件就执行它         
         . /etc/sysconfig/network
 
         # Reset the hostname.
         action $"Resetting hostname ${HOSTNAME}: " hostname ${HOSTNAME}        # 重新设置主机名,因为上面的 /etc/sysconfig/network 被重新执行了
    fi
 
    rm -f /.unconfigured                                                                          # 删除 /.unconfigured
 
    if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then        # 切换回 8# 控制台
         chvt 8
    fi
fi
 
# Clean out /.                                                                                        # 下面把 / 下的一些文件删除,包括 /fastboot、/fsckoptions、/forcefsck、/.autofsck 
rm -f /fastboot /fsckoptions /forcefsck /.autofsck /halt /poweroff &> /dev/null        # /halt、/poweroff ,这样下次重启就会再次检测是否需要 fsck 了
 
# Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might...        # 正常情况下是需要 /var/run/utmpx 和 /var/log/wtmpx 文件
_NEED_XFILES=                                                                                                        #  _NEED_XFILES 的值为空
[ -f /var/run/utmpx -o -f /var/log/wtmpx ] && _NEED_XFILES=1                                  # 如果存在其中之1个文件,就把 _NEED_XFILES 的值设置为1
######################################################################################################################################################## 
# Clean up /var.  I'd use find, but /usr may not be mounted.            # 现在清理 /var 目录。
for afile in /var/lock/* /var/run/* ; do                                          # 对于在 /var/lock/ 和 /var/run 下的每个文件,执行下面的操作
 if [ -d "$afile" ]; then                                                                        # 如果 $afile 是一个目录,则
    case "$afile" in                                                                                    # 根据 $afile 的值进行选择
  */news|*/mon) ;;                                                                                    # 如果该目录的路径名是以 '/news' 或者 '/mon' 结尾则跳过它们不处理
  */sudo)  rm -f $afile/*/* ;;                                                                        # 如果是以 '/sudo' 结尾,则用 rm -rf 把该目录下面的”所有子目录“下的全部东西删除
  */vmware) rm -rf $afile/*/* ;;                                                                   # 如果是以 '/vmware' 结尾,则用 rm -fr 把它下面的”所有子目录“下的内容全部删除
  */samba) rm -rf $afile/*/* ;;                                                                      # 如果是以 '/samba' 结尾,也是同样操作
  *)  rm -f $afile/* ;;                                                                                   # 如果不是上面4种类型,则把该目录下的所有内容都删除,不仅包括子目录,也包括文件
    esac
 else                                                                                                 # 如果 $afile 是一个文件,不是目录,则
    rm -f $afile                                                                                            # 删除该文件
 fi
done
rm -f /var/lib/rpm/__db* &> /dev/null                                            # 删除 /var/lib/rpm/_db* 
 
# 补充 :可以看到不要在 /var/run 和 /var/lock 下面放置有用的文件,否则启动时会被删除。
 
# 正常情况下 /var/run 有如下内容 :
 
[root@mail run]# ls
acpid.socket=           dbus/           iptraf/         mysqld/     ptal-mlcd/    rpc.statd.pid  syslogd.pid
atd.pid                 dovecot/        klogd.pid       named/      ptal-printd/  saslauthd/     usb/
console/                dovecot-login/  mailman/        netreport/  pvm3/         sendmail.pid   utmp
crond.pid               gpm.pid         mdadm/          news/       quagga/       sm-client.pid  winbindd/
cups-config-daemon.pid  haldaemon.pid   mdmpd/          nscd/       radiusd/      sshd.pid       xfs.pid
cupsd.pid               iiim/           messagebus.pid  ppp/        radvd/        sudo/          xinetd.pid
[root@mail run]# 
 
######################################################################################################################################################## 
# Reset pam_console permissions                                                                    # 这里重置 pam_console 的权限
[ -x /sbin/pam_console_apply ] && /sbin/pam_console_apply -r                        # 如果 /sbin/pam_console_apply 存在且可以执行,则执行 /sbin/pam_console_apply -r
                                                                                                                  # -r 是表示 reset 的意思,具体见 man pam_console_apply
########################################################################################################################################################
# 注意下面这段话,一直到后面的 "kill -TERM `/sbin/pidof getkey` >/dev/null 2>&1" 才算结束,这一段放在 {} 中的代码在 bash 中被成为 command block
 
# 它可以把放在 {} 中的多个命令当成1个命令来执行,这样可以对多个命令一次使用 IO 重定向。
 
# 实际上,这部分是被放在后台运行的 ,因为它是以  {xxxxx}& 的形式出现的
 
# 我们可以也可以用函数的形式来把下面的代码做成一个函数,不过 command blocks 是一种简便的方式
 
{                                                                                                        # command block 开始
# Clean up utmp/wtmp                                                                        # 首先清空 utmp 和 wtmp 文件的内容
> /var/run/utmp                                                                                  # 首先清空 /var/run/utmp 文件
touch /var/log/wtmp                                                                           # 再用 touch 创建 /var/log/wtmp 文件
chgrp utmp /var/run/utmp /var/log/wtmp                                             # 把这两个文件的组都改为 utmp 组
chmod 0664 /var/run/utmp /var/log/wtmp                                            # 把这两个文件的权限改为 0664 (rw-rw-r--)
if [ -n "$_NEED_XFILES" ]; then                                                               #  如果 _NEED_XFILES 的值不为空
  > /var/run/utmpx                                                                                    # 则清空  /var/log/umptx
  touch /var/log/wtmpx                                                                             # 创建 /var/log/wtmpx 
  chgrp utmp /var/run/utmpx /var/log/wtmpx                                              # 同样是修改 group 和 permission
  chmod 0664 /var/run/utmpx /var/log/wtmpx
fi
 
 
 
# Clean up various /tmp bits                                                                        # 解析来是清理 /tmp 目录了
rm -f /tmp/.X*-lock /tmp/.lock.* /tmp/.gdm_socket /tmp/.s.PGSQL.*            # 删除 /tmp 下的一些隐藏文件
rm -rf /tmp/.X*-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/hsperfdata_* \
       /tmp/kde-* /tmp/ksocket-* /tmp/mc-* /tmp/mcop-* /tmp/orbit-*  \
       /tmp/scrollkeeper-*  /tmp/ssh-*
 
# Make ICE directory                                                                                     # 下面创建 ICE 目录
mkdir -m 1777 -p /tmp/.ICE-unix >/dev/null 2>&1                                            # 创建 /tmp/.ICE-unix/ 目录,权限为 1777(sticky)
chown root:root /tmp/.ICE-unix                                                                     # 改为属于 root用户、root 组
[ -n "$SELINUX" ] && restorecon /tmp/.ICE-unix >/dev/null 2>&1        
               
 
# Start up swapping.                                               # 下面是启动 swap 空间
update_boot_stage RCswap                                     # 执行 rhgb-client --update RCswap
action $"Enabling swap space: " swapon -a -e            # 启用所有 swap 分区,并跳过那些不存在的 swap 设备
# Set up binfmt_misc                                                                                    # 设置 binfmt_misc
/bin/mount -t binfmt_misc none /proc/sys/fs/binfmt_misc > /dev/null 2>&1     # 挂载 binfmt_misc 文件系统
 
# Initialize the serial ports.                                    # 初始化串口
if [ -f /etc/rc.serial ]; then                                    # 如果存在 /etc/rc.serial 则执行该文件
 . /etc/rc.serial
fi
 
# If they asked for ide-scsi, load it
if strstr "$cmdline" ide-scsi ; then
 modprobe ide-cd >/dev/null 2>&1
 modprobe ide-scsi >/dev/null 2>&1
fi
 
# Turn on harddisk optimization                                                                                        # 下面部分是用 hdparm 命令对硬盘进行优化
# There is only one file /etc/sysconfig/harddisks for all disks                                                # 默认是使用统一的优化参数文件 /etc/sysconfig/harddisks,
# after installing the hdparm-RPM. If you need different hdparm parameters                          # 如果你想对针对不同的硬盘进行优化,把该文件拷贝并重新命名为
# for each of your disks, copy /etc/sysconfig/harddisks to                                                    # /etc/sysconfig/harddisk ,并修改该文件
# /etc/sysconfig/harddiskhda (hdb, hdc...) and modify it.
# Each disk which has no special parameters will use the defaults.                                        # 如果某个选项没有指定,则默认使用默认值
# Each non-disk which has no special parameters will be ignored.                                         

                                                                                                                                         # 下面定义一个数组,名为 disk ,共有21个元素
disk[0]=s;
disk[1]=hda;  disk[2]=hdb;  disk[3]=hdc;  disk[4]=hdd;
disk[5]=hde;  disk[6]=hdf;  disk[7]=hdg;  disk[8]=hdh;
disk[9]=hdi;  disk[10]=hdj; disk[11]=hdk; disk[12]=hdl;
disk[13]=hdm; disk[14]=hdn; disk[15]=hdo; disk[16]=hdp;
disk[17]=hdq; disk[18]=hdr; disk[19]=hds; disk[20]=hdt;
 
 
if [ -x /sbin/hdparm ]; then                                                                                     # 如果存在 /sbin/hdparm 且可执行,则
   for device in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do                            # 从0-20 循环,每次把一个数字赋予 device 变量
        unset MULTIPLE_IO USE_DMA EIDE_32BIT LOOKAHEAD EXTRA_PARAMS                         # 首先把 MULTIPLE_IO、USE_DMA、EIDE_32BIT、LOOKAHEAD、
                                                                                                                                   # EXTRA_PARAMS 的值清空
        if [ -f /etc/sysconfig/harddisk${disk[$device]} ]; then                                              # 如果存在 /etc/sysconfig/harddisk 文件,则      
                . /etc/sysconfig/harddisk${disk[$device]}                                                                # 执行该文件
                HDFLAGS[$device]=                                                                                                # 把 HDFLAGS 数组对应 $device 的元素的值清空
                if [ -n "$MULTIPLE_IO" ]; then                                                                                  # 如果 MULTIPLE_IO 的值不为空,则
                    HDFLAGS[$device]="-q -m$MULTIPLE_IO"                                                                    # HDFLAGS 数组对应该 deivce 值的元素的值为 -q -m$MULTIPE_IO 
                fi
                if [ -n "$USE_DMA" ]; then                                                                                        # 如果 USE_DMA 的值不为空,则
                    HDFLAGS[$device]="${HDFLAGS[$device]} -q -d$USE_DMA"                                        # HDFLAGS 对应该 deivce 值的元素的值再加上  -q -d$USE_DMA
                fi
                if [ -n "$EIDE_32BIT" ]; then                                                                                      # 如果 EIDE_32BIT 变量的值不为空,则
                    HDFLAGS[$device]="${HDFLAGS[$device]} -q -c$EIDE_32BIT"                                        # HDFLAGS 对应 device 值的元素的值再加上 -q -c$EIDE_32BIT
                fi    
                if [ -n "$LOOKAHEAD" ]; then                                                                                    # 如果 LOOKAHEAD 变量的值不为空,则
                    HDFLAGS[$device]="${HDFLAGS[$device]} -q -A$LOOKAHEAD"                                        # HDFLGAS 对应 device 值的元素的值加上 -q -A$LOOKAHEAD
                fi
                if [ -n "$EXTRA_PARAMS" ]; then                                                                                # 如果 EXTRA_PARAMS 变量的值不为空,则
                    HDFLAGS[$device]="${HDFLAGS[$device]} $EXTRA_PARAMS"                                           # HDFLAGS 对应 device 值的元素的值加上 -q $EXTRA_PARAMS
                fi
        else                                                                                                                        # 如果不存在 /etc/sysconfig/harddisk 文件,则
                HDFLAGS[$device]="${HDFLAGS[0]}"                                                                            # 统一使用 HDFLAGS[0] 的值作为每个硬盘的优化参数值
        fi
        if [ -e "/proc/ide/${disk[$device]}/media" ]; then                                                      # 如果存在 /proc/ide//media 文件,则
             hdmedia=`cat /proc/ide/${disk[$device]}/media`                                                    # 则找出它的 media 类型并赋予变俩功能 hdmedia
             if [ "$hdmedia" = "disk" -o -f "/etc/sysconfig/harddisk${disk[$device]}" ]; then        # 如果 hdmedia 的值是 "disk" 或者存在 /etc/sysconfig/harddisk 文件 
                  if [ -n "${HDFLAGS[$device]}" ]; then                                                                    # 且对应硬盘的参数值不为空,则
                      action $"Setting hard drive parameters for ${disk[$device]}: "  /sbin/hdparm ${HDFLAGS[$device]} /dev/${disk[$device]}    # 调用 action 函数,
                  fi                                                                                                                                                                                    # 执行 /sbin/hdparm 命令,
             fi                                                                                                                                                                                         # 根据给定优化参数值进行优化
        fi
   done
fi            # 注释 :这个 fi 是结束 "if [ -x /sbin/hdparm ];" 的
 
# Boot time profiles. Yes, this should be somewhere else.                        
if [ -x /usr/sbin/system-config-network-cmd ]; then
  if strstr "$cmdline" netprofile= ; then
    for arg in $cmdline ; do
        if [ "${arg##netprofile=}" != "${arg}" ]; then
     /usr/sbin/system-config-network-cmd --profile ${arg##netprofile=}
        fi
    done
  fi
fi
 
# Now that we have all of our basic modules loaded and the kernel going,        # 现在所有基础的模块都已经被加载,内核已经开始运行了。可以把这些信息导出了
# let's dump the syslog ring somewhere so we can find it later                        # 这样在启动后可以重新查阅.
 
# 补充 :在第 125 行,我们执行了 dmesg -n  $LOGLEVEL 命令,把信息都写入 syslog 了。
 
# 现在把它们从 syslog 中导出来到文件中                                                                               
 
dmesg -s 131072 > /var/log/dmesg       # 执行 dmesg -s 131072 > /var/log/dmesg 文件,导出的内容是 131072 字节。
                                                        # 默认是 16392 字节                                                                  
        
# create the crash indicator flag to warn on crashes, offer fsck with timeout        # 在这里创建 /.autofsck ,如果系统在这里崩溃了,下次重启就会出现 fsck 提示
touch /.autofsck &> /dev/null                    # 用 touch 命令创建 /.autofsck 。不过可以看到前面的第 785 -786行 把 /.autofsck 连同其他 /fastboot 等都删除了
 
kill -TERM `/sbin/pidof getkey` >/dev/null 2>&1        # 在这里才把 getkey 命令杀死
} &                                                                        # command block 结束
 
############################################################################################################################################################
 
if strstr "$cmdline" confirm ; then                                                # 如果内核启动参数含有 "comfirm" ,则
 touch /var/run/confirm                                                                 # 创建 /var/run/confirm 文件
fi    
if [ "$PROMPT" != "no" ]; then                                                      # 如果 PROMPT 变量的值不为 no ,则
 /sbin/getkey i && touch /var/run/confirm                                    # 调用 getkey 等待用户输入 i ,如果按下 i 则创建 /var/run/confirm 
fi
wait                                                                                            # 一旦用户按下任意键,则跳过该行,继续执行下面的代码
 
if [ -x /sbin/redhat-support-check -a -f /var/lib/supportinfo ]; then        #  如果存在 /sbin/redhat-support-check 且可执行,且存在 /var/lib/supportinfo  文件,则
 /sbin/redhat-support-check || {                                                                # 执行该命令,如果不成功则输出”Normal startup will continue in 10 seconds“ ,
   echo $"Normal startup will continue in 10 seconds."                                    # 然后睡眠10秒钟
   sleep 10
}
fi
 
######################################################################################################################################################## 
# Let rhgb know that we're leaving rc.sysinit                                            # 到这里 rc.sysinit 就结束了。
if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then             # 执行 rhgb-client --sysinit ,告诉 rhgb 服务器已经完成 rc.sysinit 了
    /usr/bin/rhgb-client --sysinit
fi
 
 
######################################################################################################################################################## 
 
阅读(1123) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~