1. 程式人生 > 實用技巧 >linux啟動流程grub管理及故障排錯

linux啟動流程grub管理及故障排錯

grub.conf詳解

[root@zhou grub]# cat grub.conf 
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda2
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0   #預設從哪個title啟動,一個title代表一個核心
timeout=5 #啟動選單介面停留的超時時長 splashimage=(hd0,0)/grub/splash.xpm.gz #xpm.gz是背景圖片 hiddenmenu title CentOS 6 (2.6.32-696.el6.x86_64) root (hd0,0) #hd0,0表示第一塊硬碟的第一個分割槽 kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=11efc218-6676-4741-94c2-d8aaab0abd1a rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet # /vmlinuz-2.6.32-696.el6.x86_64 前面的/表白/boot #ro root 表示作業系統的根; #rhgb表示影象,quiet表示安靜,啟動的時候不顯示核心檔案啟動的內容
initrd /initramfs-2.6.32-696.el6.x86_64.img

 centos6啟動時需第二次掛載根,在系統啟動後需執行第一個啟動指令碼/etc/rc.d/rc.sysinit,下圖可以看到一些掛著的資訊:

[root@zhou grub]# cat /etc/rc.d/rc.sysinit |grep mount
if [ ! -e /proc/mounts ]; then
	mount -n -t proc /proc /proc
	mount -n -t sysfs /sys /sys >/dev/null 2>&1
	modprobe usbcore >/dev/null 2>&1 && mount -n -t usbfs /proc/bus/usb /proc/bus/usb
	mount -n -t usbfs /proc/bus/usb /proc/bus/usb
#remount /dev/shm to set attributes from fstab #669700
mount -n -o remount /dev/shm >/dev/null 2>&1
#remount /proc to set attributes from fstab #984003
mount -n -o remount /proc >/dev/null 2>&1
if [ -n "$SELINUX_STATE" -a -x /sbin/restorecon ] && __fgrep " /dev " /proc/mounts >/dev/null 2>&1 ; then
    echo $"Unmounting file systems"
    umount -a
    mount -n -o remount,ro /
mount -n /dev/pts >/dev/null 2>&1
	mount_empty() {
			mount -n --bind "$RW_MOUNT$1" "$1"
	mount_dirs() {
			mount -n --bind "$RW_MOUNT$1" "$1"
	mount_files() {
			mount -n --bind "$RW_MOUNT$1" "$1"
	# Common mount options for scratch space regardless of
	mountopts=
	rw_mount_dev=$(blkid -t LABEL="$RW_LABEL" -l -o device)
	# First try to mount scratch storage from /etc/fstab, then any
	# to wipe the scratch storage clean.  If both fail, then mount
	if mount $mountopts "$RW_MOUNT" > /dev/null 2>&1 ; then
	elif [ x$rw_mount_dev != x ] && mount $rw_mount_dev $mountopts "$RW_MOUNT" > /dev/null 2>&1; then
		mount -n -t tmpfs $RW_OPTIONS $mountopts none "$RW_MOUNT"
					mount_empty $path
					mount_files $path
					mount_dirs $path
	# place where they can place minimal amounts of persistent
	# create the bind mounts.  However, until that's all ready this
	# First try to mount persistent data from /etc/fstab, then any
	state_mount_dev=$(blkid -t LABEL="$STATE_LABEL" -l -o device)
	if mount $mountopts $STATE_OPTIONS "$STATE_MOUNT" > /dev/null 2>&1 ; then
	elif [ x$state_mount_dev != x ] && mount $state_mount_dev $mountopts "$STATE_MOUNT" > /dev/null 2>&1;  then
		mount -t nfs $CLIENTSTATE/$HOSTNAME $STATE_MOUNT -o rw,nolock
		mount_state() {
				mount -n --bind "$STATE_MOUNT$1" "$1"
				mount -n --bind "$STATE_MOUNT/$file" "$file"
				mount_state "$path"
				mount_state "$path"
        if mount | grep -q /var/lib/nfs/rpc_pipefs ; then
                mount -t rpc_pipefs sunrpc /var/lib/nfs/rpc_pipefs && service rpcidmapd restart
		echo $"Unmounting file systems"
		umount -a
		mount -n -o remount,ro /
		echo $"Unmounting file systems"
		umount -a
		mount -n -o remount,ro /
remount_needed() {
  state=$(LC_ALL=C awk '/ \/ / && ($3 !~ /rootfs/) { print $4 }' /proc/mounts)
# Remount the root filesystem read-write.
update_boot_stage RCmountfs
if remount_needed ; then
  action $"Remounting root filesystem in read-write mode: " mount -n -o remount,rw /
# If relabeling, relabel mount points.
	# Enter mounted filesystems into /etc/mtab
	mount -f /
	mount -f /proc >/dev/null 2>&1
	mount -f /sys >/dev/null 2>&1
	mount -f /dev/pts >/dev/null 2>&1
	mount -f /dev/shm >/dev/null 2>&1
	mount -f /proc/bus/usb >/dev/null 2>&1
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
# The 'no' applies to all listed filesystem types. See mount(8).
	action $"Mounting local filesystems: " mount -a -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs,gfs2,glusterfs -O no_netdev
	action $"Mounting local filesystems: " mount -a -n -t nonfs,nfs4,smbfs,ncpfs,cifs,gfs,gfs2,glusterfs -O no_netdev
/bin/mount -t binfmt_misc none /proc/sys/fs/binfmt_misc > /dev/null 2>&1

linux啟動分為三個階段