在CentOS/RHEL 7中,如何将内核参数仅添加到特定的内核中

当我们向 /etc/sysconfig/grub 添加参数并运行 grub2-mkconfig -o /boot/grub2/grub.cfg 时,该参数将被添加到所有内核条目中。
这是 RHEL 7 系统的默认行为。
RHEL7/CentOS 7 系统中有多个内核时,如何给特定的内核版本添加内核参数。

on  it road.com

如何仅修改特定内核

  1. 将所需的菜单项从 /boot/grub2/grub.cfg 复制到 /etc/grub.d/40_custom 。
    条目以“menuentry”开头的行开始,以包含“}”的行结束。

例如,

# cat /etc/grub.d/40_custom
menuentry 'Red Hat Enterprise Linux Server 7.1 (Maipo), with Linux 3.10.0-229.el7.x86_64' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-229.el7.x86_64-advanced-99fe481b-4138-47bd-bcb2-116f3d76b622' {
	load_video
	set gfxpayload=keep
	insmod gzio
	insmod part_msdos
	insmod ext2
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  1a678f4f-85e4-43c6-b4b3-af1a732510ac
	else
	  search --no-floppy --fs-uuid --set=root 1a678f4f-85e4-43c6-b4b3-af1a732510ac
	fi
	linux16 /vmlinuz-3.10.0-229.el7.x86_64 root=/dev/mapper/vg_os-lv_root ro nomodeset crashkernel=auto rd.lvm.lv=vg_os/lv_root rd.lvm.lv=vg_os/lv_swap rhgb quiet LANG=en_US.UTF-8
	initrd16 /initramfs-3.10.0-229.el7.x86_64.img
}
  1. 更改menuentry后的标题:
menuentry 'Red Hat Enterprise Linux Server 7.1 (Maipo), with Linux 3.10.0-229.el7.x86_64'

改成,

menuentry 'RHEL 7.1 with custom parameters'
  1. 在以linux16开头的行尾添加参数。
linux16 /vmlinuz-3.10.0-229.el7.x86_64 root=/dev/mapper/vg_os-lv_root ro nomodeset crashkernel=auto rd.lvm.lv=vg_os/lv_root rd.lvm.lv=vg_os/lv_swap rhgb quiet LANG=en_US.UTF-8 [additional parameters here]
  1. 更新 /boot/grub2/grub.cfg 使更改生效的配置文件:
# grub2-mkconfig -o /boot/grub2/grub.cfg
  1. 重新启动系统以验证新的内核参数。
# shutdown -r now
日期:2020-09-17 00:12:24 来源:oir作者:oir