Fedora32启用BLS新规范管理GRUB2

编程

ydx@ydx-mf:~ $ 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="resume=/dev/mapper/VG01-swap rd.lvm.lv=VG01/root rd.lvm.lv=VG01/swap rhgb quiet"

GRUB_DISABLE_RECOVERY="true"

GRUB_ENABLE_BLSCFG=false

可以看到,我设置了GRUB_DEFAULT=saved,这说明其使用grub已经保存的配置。这指的是grub再引导目录的配置。

If you set this to ‘saved’, then the default menu entry will be that saved by ‘GRUB_SAVEDEFAULT’ or grub-set-default. This relies on the environment block, which may not be available in all situations (see Environment block).

因为我是EFI引导的,所以我需要如下检查:

ydx@ydx-mf:~ $ sudo cat /boot/grub2/grubenv                 

# GRUB Environment Block

saved_entry=47b007f224c34ad8bf0984ac74f55452-5.6.12-300.fc32.x86_64

menu_auto_hide=1

boot_success=1

kernelopts=root=/dev/mapper/fedora_localhost--live-root ro resume=/dev/mapper/fedora_localhost--live-swap rd.lvm.lv=fedora_localhost-live/root rd.lvm.lv=fedora_localhost-live/swap rhgb quiet

boot_indeterminate=2

###############################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################%

 为什么有那么多#号,我也不懂。

可以看到已保存的条目是5.6.12内核,为什么启动时用的是5.6.10?

ydx@ydx-mf:~ $ uname -a

Linux ydx-mf 5.6.10-300.fc32.x86_64 #1 SMP Mon May 4 14:29:45 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

官方文档有一句话:

The GRUB 2 configuration file, grub.cfg, is generated during installation, or by invoking the /usr/sbin/grub2-mkconfig utility, and is automatically updated by grubby each time a new kernel is installed.

它说到安装新的内核后,配置文件会由grubby自动更新。问题是,我没有安装grubby呀:

ydx@ydx-mf:~ $ grubby

zsh: grubby: command not found...

Packages providing this file are:

"grubby"

"grubby-deprecated"

这是一个被吐槽已久的软件,fedora准备抛弃,但是应该是默认安装的呀?如果没安装,为什么官方文档又有如上描述?没有安装,岂不是不能自动更新配置了?

未解之谜……

让我们回到grub.cfg配置文件的生成途径。它由grub2-mkconfig生成,手动生成时的模板文件位于/etc/grub.d/,自定义设置在/etc/default/grub文件。开篇我已提到这个自定义设置,都是一些专属变量。现在我们看看模板文件有什么特别:

ydx@ydx-mf:~ $ sudo tree /etc/grub.d 

[sudo] password for ydx:

/etc/grub.d

├── 00_header

├── 01_users

├── 08_fallback_counting

├── 10_linux

├── 10_reset_boot_success

├── 12_menu_auto_hide

├── 20_linux_xen

├── 20_ppc_terminfo

├── 30_os-prober

├── 30_uefi-firmware

├── 40_custom

├── 41_custom

└── README

0 directories, 13 files

我突然觉得GRUB_ENABLE_BLSCFG和12_menu_auto_hide有冲突(其实并没有)。我要调查一下GRUB_ENABLE_BLSCFG,终于找到了关键说明。

Something to keep in mind is that kernels installed after switching to a BLS configuration won"t be present in the old configuration backup file. On platforms using grub, users can also switch back by installing the grubby-deprecated package, setting "GRUB_ENABLE_BLSCFG=false" in /etc/default/grub , and using grub2-mkconfig to re-generate their configuration file.

可以看到,"GRUB_ENABLE_BLSCFG=false"和"sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg"是搭配使用的!!!

这里还提到了一个新名词——BLS(Boot Loader Specification)。把“引导加载器规范”缩写成“引加规”,可以理解。但是把一个通用说法直接作为一个新的规范,这起名真有艺术。

现在我要启动新的规范:

ydx@ydx-mf:~ $ 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="resume=/dev/mapper/VG01-swap rd.lvm.lv=VG01/root rd.lvm.lv=VG01/swap rhgb quiet"

GRUB_DISABLE_RECOVERY="true"

GRUB_ENABLE_BLSCFG=false

ydx@ydx-mf:~ $ grub2-switch-to-blscfg

realpath: /etc/grub2-efi.cfg: Permission denied

Couldn"t find config file

ydx@ydx-mf:~ $ sudo !!

ydx@ydx-mf:~ $ sudo grub2-switch-to-blscfg

[sudo] password for ydx:

Generating grub configuration file ...

Adding boot menu entry for EFI firmware configuration

done

ydx@ydx-mf:~ $ 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="resume=/dev/mapper/VG01-swap rd.lvm.lv=VG01/root rd.lvm.lv=VG01/swap rhgb quiet"

GRUB_DISABLE_RECOVERY="true"

GRUB_ENABLE_BLSCFG=true

可以看到,GRUB_ENABLE_BLSCFG=true。

重启可得最新内核。✌

网上有很多解决方案,但是都会过时。解决一个问题的正确思路是:

先找到问题的根因,然后找到技术起源,最后找到第一手说明,最终决定解决问题与否。

 

参考:

https://www.gnu.org/software/grub/manual/grub/html_node/Simple-configuration.html

https://docs.fedoraproject.org/en-US/fedora/rawhide/system-administrators-guide/kernel-module-driver-configuration/Working_with_the_GRUB_2_Boot_Loader/

https://fedoraproject.org/wiki/Changes/BootLoaderSpecByDefault

 

以上是 Fedora32启用BLS新规范管理GRUB2 的全部内容, 来源链接: utcz.com/z/516656.html

回到顶部