Product SiteDocumentation Site

21.5.4. Creating a Custom Menu

If you do not want menu entries to be updated automatically, you can create a custom menu.

Important

Before proceeding, back up the contents of the /etc/grub.d/ directory in case you need to revert the changes later.

Note

Note that modifying the /etc/default/grub file does not have any effect on creating custom menus.
  1. On BIOS-based machines, copy the contents of /boot/grub2/grub.cfg, or, on UEFI machines, copy the contents of /boot/efi/EFI/fedora/grub.cfg. Put the content of the grub.cfg into the /etc/grub.d/40_custom file below the existing header lines. The executable part of the 40_custom script has to be preserved.
  2. From the content put into the /etc/grub.d/40_custom file, only the menuentry blocks are needed to create the custom menu. The /boot/grub2/grub.cfg and /boot/efi/EFI/fedora/grub.cfg files might contain function specifications and other content above and below the menuentry blocks. If you put these unnecessary lines into the 40_custom file in the previous step, erase them.
    This is an example of a custom 40_custom script:
    #!/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 'First custom entry' --class red --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.2.0-1.fc23.x86_64-advanced-32782dd0-4b47-4d56-a740-2076ab5e5976' {
            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'  7885bba1-8aa7-4e5d-a7ad-821f4f52170a
            else
              search --no-floppy --fs-uuid --set=root 7885bba1-8aa7-4e5d-a7ad-821f4f52170a
            fi
            linux16 /vmlinuz-4.2.0-1.fc23.x86_64 root=/dev/mapper/fedora-root ro rd.lvm.lv=fedora/root vconsole.font=latarcyrheb-sun16 rd.lvm.lv=fedora/swap vconsole.keymap=us crashkernel=auto rhgb quiet LANG=en_US.UTF-8
            initrd16 /initramfs-4.2.0-1.fc23.x86_64.img
    }
    menuentry 'Second custom entry' --class red --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-0-rescue-07f43f20a54c4ce8ada8b70d33fd001c-advanced-32782dd0-4b47-4d56-a740-2076ab5e5976' {
            load_video
            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'  7885bba1-8aa7-4e5d-a7ad-821f4f52170a
            else
              search --no-floppy --fs-uuid --set=root 7885bba1-8aa7-4e5d-a7ad-821f4f52170a
            fi
            linux16 /vmlinuz-0-rescue-07f43f20a54c4ce8ada8b70d33fd001c root=/dev/mapper/fedora-root ro rd.lvm.lv=fedora/root vconsole.font=latarcyrheb-sun16 rd.lvm.lv=fedora/swap vconsole.keymap=us crashkernel=auto rhgb quiet
            initrd16 /initramfs-0-rescue-07f43f20a54c4ce8ada8b70d33fd001c.img
    }
  3. Remove all files from the /etc/grub.d directory except the following:
    • 00_header,
    • 40_custom,
    • 01_users (if it exists),
    • and README.
    Alternatively, if you want to keep the files in the /etc/grub2.d/ directory, make them unexecutable by running the chmod a-x <file_name> command.
  4. Edit, add, or remove menu entries in the 40_custom file as desired.
  5. Rebuild the grub.cfg file by running the grub2-mkconfig -o command as follows:
    • On BIOS-based machines, issue the following command as root:
      ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
    • On UEFI-based machines, issue the following command as root:
      ~]# grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg