How to create a custom menue in RHEL7

Solution Unverified - Updated

Environment

Red Hat Enterprise Linux7

Issue

When I created a new custom initramfs , how can I add the new kernel menu which includes the new initramfs?

Resolution

1. Create a new custom initramfs
How to rebuild the initial ramdisk image in Red Hat Enterprise Linux

2. Show sample entries using /etc/grub2.cfg by the following command.

# awk  '/^menuentry/,/\}/{if($1=="menuentry"){i++;print "####sample"i"####";print $0}else{print $0}}' /etc/grub2.cfg 

For example:

# awk  '/^menuentry/,/\}/{if($1=="menuentry"){i++;print "####sample"i"####";print $0}else{print $0}}' /etc/grub2.cfg 
####sample1####
menuentry 'Red Hat Enterprise Linux Server, with Linux 3.10.0-229.el7.x86_64' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-229.el7.x86_64-advanced-65d647e7-c3c8-4330-9728-61378cb98639' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='hd0,msdos1'  832273a3-e5eb-4bcb-9d4c-a049f88a6e93
        else
          search --no-floppy --fs-uuid --set=root 832273a3-e5eb-4bcb-9d4c-a049f88a6e93
        fi
        linux16 /vmlinuz-3.10.0-229.el7.x86_64 root=UUID=65d647e7-c3c8-4330-9728-61378cb98639 ro rd.lvm.lv=rhel/root crashkernel=auto  rd.lvm.lv=rhel/swap vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet debug rd.debug
        initrd16 /initramfs-3.10.0-229.el7.x86_64.img
}
####sample2####
menuentry 'Red Hat Enterprise Linux Server (3.10.0-862.9.1.el7.x86_64) 7.5 (Maipo) with debugging' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-862.9.1.el7.x86_64-advanced-08f35ea6-d950-447c-8e34-bf02b474c8b9' {
	load_video
	set gfxpayload=keep
:
:
:
:

3. create /etc/grub.d/40_custom using the abobe sample menuentry you chosed. The entry begins with the line starting with "menuentry" and ends with a line containing "}". Be careful not to change the 'exec tail -n +3 $0'

For example,

# cat /etc/grub.d/40_custom
!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry 'Red Hat Enterprise Linux Server, with Linux 3.10.0-229.el7.x86_64' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-229.el7.x86_64-advanced-65d647e7-c3c8-4330-9728-61378cb98639' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='hd0,msdos1'  832273a3-e5eb-4bcb-9d4c-a049f88a6e93
        else
          search --no-floppy --fs-uuid --set=root 832273a3-e5eb-4bcb-9d4c-a049f88a6e93
        fi
        linux16 /vmlinuz-3.10.0-229.el7.x86_64 root=UUID=65d647e7-c3c8-4330-9728-61378cb98639 ro rd.lvm.lv=rhel/root crashkernel=auto  rd.lvm.lv=rhel/swap vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet debug rd.debug
        initrd16 /initramfs-3.10.0-229.el7.x86_64.img
}

4. Change the title after menuentry:

menuentry 'Red Hat Enterprise Linux Server, with Linux 3.10.0-229.el7.x86_64'

Change to,

menuentry 'Red Hat Enterprise Linux Server, with Linux 3.10.0-229.el7.x86_64 - TEST'

5. Change the menuentry_id_option:

gnulinux-3.10.0-229.el7.x86_64-advanced-65d647e7-c3c8-4330-9728-61378cb98639

Change to,

gnulinux-3.10.0-229.el7.x86_64-TEST

6. Change the initramfs file name in the line starting with linux16.

 linux16 /vmlinuz-3.10.0-229.el7.x86_64 root=UUID=65d647e7-c3c8-4330-9728-61378cb98639 ro rd.lvm.lv=rhel/root crashkernel=auto  rd.lvm.lv=rhel/swap vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet debug rd.debug
        initrd16 /initramfs-3.10.0-229.el7.x86_64.img

Change to,

linux16 /vmlinuz-3.10.0-229.el7.x86_64 root=UUID=65d647e7-c3c8-4330-9728-61378cb98639 ro rd.lvm.lv=rhel/root crashkernel=auto  rd.lvm.lv=rhel/swap vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet debug rd.debug
        initrd16 /initramfs-3.10.0-229.el7.x86_64-TEST.img

7. Update /boot/grub2/grub.cfg to apply the changed config file:

  • On BIOS-based machines: ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
  • On UEFI-based machines: ~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.