When we add a parameter to /etc/sysconfig/grub and run grub2-mkconfig -o /boot/grub2/grub.cfg, the parameter will be added to all of the kernel entries. This is the default behaviour of a RHEL 7 system. How can we add kernel parameter to a specific kernel version when there are more than one kernel in the system in RHEL7 / CentOS 7.
How to modify a specific kernel only
1. Copy the desired menuentry from /boot/grub2/grub.cfg to /etc/grub.d/40_custom. The entry begins with the line starting with “menuentry” and ends with a line containing “}“.
For example,
# 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
}
2. Change the title after menuentry:
menuentry 'Red Hat Enterprise Linux Server 7.1 (Maipo), with Linux 3.10.0-229.el7.x86_64'
Change to,
menuentry 'RHEL 7.1 with custom parameters'
3. Add parameters to the end of the line starting with 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]
4. Update /boot/grub2/grub.cfg to apply the changed config file:
# grub2-mkconfig -o /boot/grub2/grub.cfg
5. Reboot the system to verify the new kernel parameters.
# shutdown -r now