GRUB2 CHEATSHEET
This is a quick cheatsheet on manipulating GRUB2 as Red Hat, Fedora, and CentOS have set things up.
I will set this cheatsheet up in a somewhat logical chronological order. So configurations possible, then finally at the end, how to commit the changes. GRUB2 needs a "reinstall" of sorts to apply new changes, so simply modifying the files do nothing functionally. A slight change from GRUB1's behavior.
Also, one thing that should be noted, things get wonky very quickly when you mix EFI and BIOS modes. If you want to prolong the color in your hair, stick EFI across the board, or BIOS across the board. Advice also on using the most recent mode available. So if your system supports EFI, use it over BIOS. But if you are going into a dual/triple/quadruple boot scenario that had BIOS modes on an EFI motherboard, stick with the BIOS mode and configure your EFI setup to support usage of BIOS boot modes.
QUICK OVERVIEW OF THE FILES
We have several files that are of note, whether they are physically touched by us is another story. Depending on what change is desired, certain files take care of that need.
- /etc/default/grub
- /etc/grub.d/00_header
- /etc/grub.d/01_users
- /etc/grub.d/10_linux
- /etc/grub.d/20_linux_xen
- /etc/grub.d/20_ppc_terminfo
- /etc/grub.d/30_os-prober
- /etc/grub.d/40_custom
- /etc/grub.d/41_custom
- /boot/efi/EFI/fedora/grub.cfg
- /boot/grub2/grub.cfg
File 1 is where most editing will be done. This is the main configuration. This along with what is called in 2-9 will physically build and install a working bootloader and menu
Files 2-9 are where some magic behind the scenes happens. Each file sort of denotes its function, and will perform the relevant task(s) in putting menu entries together. Custom entries are done via a "40_custom" file, linux kernels via the "10_linux" file, probing of installations is done via the "30_os-prober" file, etc.
10 and 11 are exclusive to each other. 10 is your EFI and 11 is your BIOS installation file. If you are using EFI, 10 is used, 11 for BIOS/Legacy based installations.
EDITING THE CONFIGURATION
The main place to edit the configuration of GRUB2 is at:
/etc/default/grub
And you will see something akin to this (I may have some slight modifications present):
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="gfxterm"
GRUB_CMDLINE_LINUX="rd.driver.blacklist=nouveau rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
ADDING ENTRIES TO THE MENU
To add an entry to the menu, usually speaking, a rebuild of the GRUB2 install (later on in the cheatsheet) will see it during the probe portion, and add it to the menu for you. If that fails, or you want to create something by hand, here is what you will want to do.
We will need to edit the following file:
/etc/grub.d/40_custom
Or create a new one:
/etc/grub.d/40_my-custom-entry-1
And what we will need to put there at a minimum:
#!/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 "<Title>"{
<Data>
}
The menu entry will have all the necessary info for said boot. Here is a copy of a Linux menu entry.
menuentry 'My 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
And a sample Windows menu entry:
menuentry “Microsoft Windows 10″ {
set root=(hd0,1)
chainloader +1
}
COMMITING CHANGES
To commit the changes that have been made you will need to run grub2-mkconfig:
-
EFI
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
-
BIOS/Legacy
grub2-mkconfig -o /boot/grub2/grub.cfg