[root@localhost grub]# vim 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/mapper/VolGroup-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS rd_NO_MD rd_LVM_LV=VolGroup/lv_swap crashkernel=auto LANG=zh_CN.UTF-8 rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-431.el6.x86_64.img 其中常用的配置
default=#: 设定默认启动的菜单项;落单项(title)编号从0开始;
timeout=#:指定菜单项等待选项选择的时长;
splashimage=(hd#,#)/PATH/TO/XPM_PIC_FILE:指明菜单背景图片文件路径;
hiddenmenu:隐藏菜单;
password [--md5] STRING: 菜单编辑认证;
title TITLE:定义菜单项“标题”, 可出现多次;
root (hd#,#):grub查找stage2及kernel文件所在设备分区;为grub的“根”;
kernel /PATH/TO/VMLINUZ_FILE [PARAMETERS]:启动的内核
initrd /PATH/TO/INITRAMFS_FILE: 内核匹配的ramfs文件;
password --md5 STRING: 启动选定的内核或操作系统时进行认证; 2、GRUB2
CentOS 7上安装的是gurb2
1. help
查看命令用法,显示所有可用命令
help search
search 命令用法
2. ls
列出当前的所有设备。如 (hd0) (hd0,1) (hd0,5) (hd1) (hd1,1) (hd1,2) .......
ls -l
详细列出当前的所有设备。对于分区,会显示其label及uuid。
ls /
列出当前设为root的分区下的文件
ls (hd1,1)/
列出(hd1,1)分区下文件
3. search
search -f /ntldr
列出根目录里包含ntldr文件的分区,返回为分区号
search -l LINUX
搜索label是LINUX的分区。
search --set -f /ntldr
搜索根目录包含ntldr文件的分区并设为root,注意如果多外分区含有ntldr文件,set 失去作用
4. loopback
loopback命令可用于建立回放设备,如
loopback lo0 (hd1,1)/abc.iso
可以使用lo0设备来访问abc.iso里的内容,比如说,可以从abc.iso里的软盘映像中启动
loopback lo0 (hd1,1)/aa.iso
linux (lo0)/memdisk
initrd (lo0)/abc.img
要删除某一回放设备,可以使用-d参数:
loopback -d lo0
5. set
使用set可以设置变量的值
set root=
set timeout=
需要调用变量的值时,使用${AA},如set root=(hd1,1)
则${root}=(hd1,1)
6. pager
分页显示。
set pager=1
满页时暂停,按space继续
set pager=0
取消分页
7. linux
linux取代grub中的kernel CentOS 7的/boot/grub2/grub.conf官方建议是不要随便修改的,一般都是在grub.d文件下生成新的启动目录,再重新生成
默认启动的修改可通过/boot/grub2/grubenv文件修改
[root@localhost grub2]# vim grubenv
# GRUB Environment Block
saved_entry=CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)
######################################################### 可以进入/etc/grub.d下查看
[root@localhost grub.d]# ls
00_header 01_users 20_linux_xen 30_os-prober 41_custom
00_tuned 10_linux 20_ppc_terminfo 40_custom README 进入README可以查看grub.d中文件的说明
[root@localhost grub.d]# cat README
All executable files in this directory are processed in shell expansion order.
00_*: Reserved for 00_header.
10_*: Native boot entries.
20_*: Third party apps (e.g. memtest86+).
The number namespace in-between is configurable by system installer and/or
administrator. For example, you can add an entry to boot another OS as
01_otheros, 11_otheros, etc, depending on the position you want it to occupy in
the menu; and then adjust the default setting via /etc/default/grub.#00 _ *:为00 _header保留
#10 _ *:本机引导条目
#20 _ *:第三方应用程序(例如memtest86)五、进入kernel
在GRUB中选择对应的kernel进入,然后kernel会对自身进行初始化
探测可识别到的所有硬件设备。
加载硬件驱动程序。
以只读方式挂载根文件系统。
运行用户空间的第一个应用程序,在CentOS 6上是init,在CentOS 7上是Systemd
内核组成部分:
kernel: 内核核心,一般为bzImage,通常在/boot目录下,名称为vmlinuz-VERSION-RELEASE;
kernel object: 内核对象,一般放置于/lib/modules/VERSION-RELEASE/ 六、运行init
CentOS 6上init所在的位置是在/sbin/init,init共分为7个级别
[root@localhost sbin]# runlevel
N 5
[root@localhost sbin]# who -r
运行级别 5 2016-04-10 18:25 init的配置文件在/etc/inittab
[root@localhost sbin]# vim /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
#这里定义的默认运行级别为5 配置文件中的格式是:id:runlevel:action:process
此配置文件每行定义一个级别
id:指入口标识符,它是一个字符串,对于getty或mingetty等其他login程序项,要求id与tty的编号相同,否则getty程序将不能正常工作。
runlevel:init的系统运行级别
action:是用来定义后面process的运行方式,常用的有下面几种
wait: 切换至此级别运行一次;
respawn:此process终止,就重新启动之;
initdefault:设定默认运行级别;process省略;
sysinit:设定系统初始化方式,此处一般为指定/etc/rc.d/rc.sysinit
process:为具体的执行程序, 例如设置为l0:5:wait:/etc/rc.d/rc 5
/etc/rc.d/rc是一个Shell脚本,它接受5作为参数,去执行/etc /rc.d/rc5.d/目录下的所有的rc启动脚本,/etc/rc.d/rc5.d/目录中的这些启动脚本实际上都是一些链接文件,而不是真正的rc 启动脚本,真正的rc启动脚本实际上都是放在/etc/rc.d/init.d/目录下。而这些rc启动脚本有着类似的用法,它们一般能接受start、stop、restart、status等参数。
/etc/rc.d/rc5.d/中的rc启动脚本通常是K或S开头的链接文件。
#K开头的文件:运行次序是数字越小,越先运行;数字越小的服务,通常为依赖到别的服务;关闭服务。
#S开头的文件:运行次序是数字越小,越先运行;数字越小的服务,通常为被依赖到的服务;启动服务。[root@localhost rc5.d]# pwd
/etc/rc.d/rc5.d
[root@localhost rc5.d]# ls
K01numad K69rpcsvcgssd S05cgconfig S23NetworkManager S80postfix
K01smartd K73winbind S07iscsid S24nfslock S82abrt-ccpp
K02oddjobd K75ntpdate S08ip6tables S24rpcgssd S82abrtd
K05wdaemon K75quota_nld S08iptables S25blk-availability S84ksm
K10psacct K76ypbind S10network S25cups S85ksmtuned
K10saslauthd K84wpa_supplicant S11auditd S25netfs S90crond
K15htcacheclean K85ebtables S11portreserve S26acpid S95atd
K15httpd K86cgred S12rsyslog S26haldaemon S97libvirtd
K15svnserve K87restorecond S13cpuspeed S26hypervkvpd S99certmonger
K46radvd K88sssd S13irqbalance S26udev-post S99libvirt-guests
K50dnsmasq K89rdisc S13iscsi S28autofs S99local
K50netconsole K95firstboot S13rpcbind S50bluetooth
K50snmpd K99rngd S15mdmonitor S55sshd
K50snmptrapd S01sysstat S20kdump S58ntpd
K60nfs S02lvm2-monitor S22messagebus S70spice-vdagentd七、运行系统初始化脚本