Grub2概述
Grub2
支持更多的特性和功能,包括自动搜索可用的内核和硬盘中的可用系统、支持更多分区格式、模块化设计等。
CentOS
从7
系列版本开始使用grub2
,ubuntu
从9.10
开始使用grub2
Grub2配置的修改
grub2
包含一个完全修改过的配置文件及目录,menu.list(grub.conf)
不再使用 。
grub2
采用模块化的设计,主要配置文件是/boot/grub2/grub.cfg
,默认情况下允许修改此文件,而是修改其他配置,最后通过grub-mkconfig
名重新生成。
grub2
可以修改的配置文件主要是/etc/default/grub
和 /etc/grub.d
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| $ cat /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rootvg01/lv01 rhgb quiet net.ifnames=0 biosdevname=0" GRUB_DISABLE_RECOVERY="true" $ ll /etc/grub.d/ total 72 -rwxr-xr-x. 1 root root 8702 Nov 24 2015 00_header -rwxr-xr-x. 1 root root 992 May 4 2015 00_tuned -rwxr-xr-x. 1 root root 230 Nov 24 2015 01_users -rwxr-xr-x. 1 root root 10232 Nov 24 2015 10_linux -rwxr-xr-x. 1 root root 10275 Nov 24 2015 20_linux_xen -rwxr-xr-x. 1 root root 2559 Nov 24 2015 20_ppc_terminfo -rwxr-xr-x. 1 root root 11169 Nov 24 2015 30_os-prober -rwxr-xr-x. 1 root root 214 Nov 24 2015 40_custom -rwxr-xr-x. 1 root root 216 Nov 24 2015 41_custom -rw-r--r--. 1 root root 483 Nov 24 2015 README
|
修改完配置后,都需要通过grub2-mkconfig
命令下发
1 2 3 4 5 6 7 8 9
| $ grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-3.10.0-514.2.2.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-514.2.2.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-98af9a09ce4e42a397fc1a169eff4005 Found initrd image: /boot/initramfs-0-rescue-98af9a09ce4e42a397fc1a169eff4005.img done
|
Grub2修改内核启动顺序
在CentOS7
中,提供了一个软件grubby
,可以用来查看grub
策略,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| $ grubby --info=ALL index=0 kernel=/boot/vmlinuz-3.10.0-514.2.2.el7.x86_64 args="ro crashkernel=auto rd.lvm.lv=rootvg01/lv01 rhgb quiet net.ifnames=0 biosdevname=0 " root=/dev/mapper/rootvg01-lv01 initrd=/boot/initramfs-3.10.0-514.2.2.el7.x86_64.img title=CentOS Linux (3.10.0-514.2.2.el7.x86_64) 7 (Core) index=1 kernel=/boot/vmlinuz-3.10.0-327.el7.x86_64 args="ro crashkernel=auto rd.lvm.lv=rootvg01/lv01 rhgb quiet net.ifnames=0 biosdevname=0 " root=/dev/mapper/rootvg01-lv01 initrd=/boot/initramfs-3.10.0-327.el7.x86_64.img title=CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core) index=2 kernel=/boot/vmlinuz-0-rescue-98af9a09ce4e42a397fc1a169eff4005 args="ro crashkernel=auto rd.lvm.lv=rootvg01/lv01 rhgb quiet net.ifnames=0 biosdevname=0 " root=/dev/mapper/rootvg01-lv01 initrd=/boot/initramfs-0-rescue-98af9a09ce4e42a397fc1a169eff4005.img title=CentOS Linux (0-rescue-98af9a09ce4e42a397fc1a169eff4005) 7 (Core) index=3 non linux entry
|
1 2 3 4
| $ grubby --default-kernel /boot/vmlinuz-3.10.0-327.el7.x86_64 $ grubby --default-index 1
|
1
| $ grubby --set-default /boot/initramfs-3.10.0-514.2.2.el7.x86_64.img
|
1
| $ grub2-mkconfig -o /boot/grub2/grub.cfg
|
注意:尝试了grubby
修改grub
,发现不生效,还是用grub2-set-default
吧
grub2设置密码
grub2
中密码设置,在/etc/grub.d/01_users
里有相关定义
1 2 3 4 5 6 7 8 9 10 11 12
| $ cat /etc/grub.d/01_users #!/bin/sh -e cat << EOF if [ -f \${prefix}/user.cfg ]; then source \${prefix}/user.cfg if [ -n \${GRUB2_PASSWORD} ]; then set superusers="root" export superusers password_pbkdf2 root \${GRUB2_PASSWORD} fi fi EOF
|
可以看出默认用户名是root
,密码则需要通过grub2-setpassword
命令来设定
1 2 3
| $ grub2-setpassword Enter password: Confirm password:
|
1 2
| $ cat /boot/grub2/user.cfg GRUB2_PASSWORD=grub.pbkdf2.sha512.10000.FAFA0A09BD3F228BA786EB2C1BD41255E2F79972E406E8C2EB2FBB79227ABEC2696F466916FD35625C56BA1BE51B3BE46F41539501CC8305DFA8434EA5FD74D4.54E2C5C81CF5C65569EFD4F8BDD6AA16103FA12F22C4BC075ED47B46C0C77F7426AFB476A7DD97A840FCE2AB546E1B5CBD353A0F7B5D9A27D8F4D41332533AF1
|
此处不需要使用grub2-mkconfig
了,密码存在user.cfg
里的
重置root密码
在新版的systemd
管理机制中,默认的rescue
模式是无法直接取得root
权限的。
需要在 linux16
的那行最后加上rd.break
参数来处理。
之后会进入到RAMFS
,root
分区会挂载到/sysroot
。
重新mount
和chroot
后可以重置密码了
1 2 3
| $ mount -o remount,rw /sysroot $ chroot /sysroot $ echo "your_root_new_pw" | passwd --stdin root
|
上一篇:nginx开启状态统计
下一篇:Bokeh python交互式可视化库