Let's Learn Linux!: The GRUB Boot Menu - Issue #9 - GaiaYoga Gardens, Lower Puna, Far East Big Island, Hawai'i - Saturday, April 15, 2023

Polish_20220714_121452303.jpg

Polish_20220714_121631044.jpg

Polish_20230217_163432316.png

Polish_20220714_121631044.jpg

Warm greetings fellow Linux-and-FOSS lovers! 😁🙏💚✨🤙

Welcome to the 9th installment of Let's Learn Linux! In this issue I want to introduce you to the GRUB and the boot menu that it can create. GRUB is a very versatile and adaptable application. It has a huge number of options to tailor itself to all manner of setups and hardware. While there are many other bootloader and boot managers for Linux, such as syslinux, systemd-boot, rEFInd, to name a few, GRUB is the default bootloader for most Linux distributions. Some bootloaders/boot managers work for the legacy BIOS/MBR boot, while others are exclusively for the newer UEFI/GPT boot. GRUB is versatile enough to work with either.

Polish_20220714_121754649.jpg

What we call GRUB today is actually GRUB2. It is a rewrite of the original GRUB code. While the original version of GRUB was simpler to use, it was far less flexible, which is in part what prompted the rewrite. The present version of GRUB is so flexible that it can be used to create a boot manu for not only multiple distributions of Linux, but also for other operating systems as well, such as Windows or MacOS. Or in my case one distribution, Arch Linux, but with boot entries for many different kernels.

Polish_20220714_121754649.jpg

The default GRUB boot menu is quite simple, and rather boring, being black-and-white text.

Polish_20220714_121631044.jpg

The GRUB boot menu for the Ubuntu live/installation media.
IMG_20230415_214554294_HDR.jpg

Polish_20220714_121631044.jpg

Very thankfully the GRUB boot menu can me modified in all manner of ways to make it more attractive and interesting. Themes and background images can be used, the font and font size and color can be changed, among other options.

Polish_20220714_121631044.jpg

This is the GRUB boot menu for all three of my Arch installations.
IMG_20230415_204016660_HDR.jpg

Polish_20220714_121631044.jpg

Once you understand the basics of GRUB, it's actually quite easy to use. If you don't understand it, things can be frustrating. I used GRUB on my old Dell for quite a while before I finally dove into actually learning it. I used to use an application called grub-customizer. In the end, however, I found that it would utterly screw up the code in the GRUB configuration files. That's when I decided to just learn to do it myself. Once I did, I found how easily I could customize it.

Polish_20220714_121754649.jpg

To do what I do with GRUB, there are only two terminal commands and two configuration files. I originally used this setup on the old BIOS/MBR Dell, then when I got the new Dell that died after one month and twenty days, I had to adapt to its quirky and rather frustrating UEFI firmware. That process took me twenty days. Once I figured it out, then I could replicate it across all three of my Arch installations. When I got my marvelous new ASUS, getting everything working again was incredibly simple and quick, exactly as it should be. Now that I understand how to work with UEFU/GPT systems, things are a lot less confusing and frustrating. Since all newer computers have EUFI firmware and UEFI/GPT boot, I'll use the command for those systems. The first command to run is the one to register GRUB with the UEFI firmware, and create a EUFI boot entry.

Polish_20220714_121631044.jpg

grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub --recheck

Polish_20220714_121631044.jpg

Once that command runs without errors, then running the next command (if os-prober is installed and enabled) will add boot-menu entries for all kernels and operating systems.

Polish_20220714_121631044.jpg

grub-mkconfig -o /boot/grub/grub.cfg

Polish_20220714_121631044.jpg

That's the quick and easy way that will give you a basic black-and-white GRUB boot menu. For many people that is fine. I am not one of those people, however. I need to make my systems beautiful and elegant, and that requires customization. The first step of that process is to add various customization information to the default GRUB configuration file found in the /etc directory.

Polish_20220714_121631044.jpg

/etc/default/grub

 ## GRUB boot loader configuration

GRUB_DEFAULT=saved
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR="Arch"
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="splash loglevel=3 udev.log-priority=3 rd.udev.log_priority=3 vt.global_cursor_default=0 sysrq_always_enabled=1 ibt=off nvidia_drm.modeset=1 rhgb rd.driver.blacklist=nouveau nouveau.modeset=0 video=vesafb:off efifb:off"
# efifb:on
GRUB_FONT="/boot/grub/fonts/DejaVuSansMono-Bold.pf2"

# Preload both GPT and MBR modules so that they are not missed
GRUB_PRELOAD_MODULES="part_gpt fat"

# Uncomment to enable booting from LUKS encrypted devices
#GRUB_ENABLE_CRYPTODISK=y

# Set to 'countdown' or 'hidden' to change timeout behavior,
# press ESC key to display menu.
GRUB_TIMEOUT_STYLE=menu

# Uncomment to use basic console
GRUB_TERMINAL_INPUT=console

# Uncomment to disable graphical terminal
GRUB_TERMINAL_OUTPUT=gfxterm

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
GRUB_GFXMODE=1280x800x32,auto

# Uncomment to allow the kernel use the same resolution used by grub
GRUB_GFXPAYLOAD_LINUX=keep

# Uncomment if you want GRUB to pass to the Linux kernel the old parameter
# format "root=/dev/xxx" instead of "root=/dev/disk/by-uuid/xxx"
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
GRUB_DISABLE_RECOVERY=true

# Uncomment and set to the desired menu colors.  Used by normal and wallpaper
# modes only.  Entries specified as foreground/background.
GRUB_COLOR_NORMAL="light-gray/black"
GRUB_COLOR_HIGHLIGHT="light-cyan/black"

# Uncomment one of them for the gfx desired, a image background or a gfxtheme
GRUB_BACKGROUND="/boot/grub/themes/Sacred-Interconnection.jpg"
#GRUB_THEME="/path/to/gfxtheme"

# Uncomment to get a beep at GRUB start
#GRUB_INIT_TUNE="480 440 1"

# Uncomment to make GRUB remember the last selection. This requires to
# set 'GRUB_DEFAULT=saved' above.
GRUB_SAVEDEFAULT=true

# Uncomment to disable submenus in boot menu
#GRUB_DISABLE_SUBMENU=y

#Disable OS Prober
GRUB_DISABLE_OS_PROBER=true

Polish_20220714_121631044.jpg

This is where themes, fonts, colors, background images, menu timeout, os-prober behavior, Linux-command-line commands, screen resolution and color depth, and lots of other useful things can be set. Anything beginning with the # symbol are commented out, which means they will not be read by GRUB.

Polish_20220714_121754649.jpg

The next step to customizing the boot menu is to create a drop-in GRUB configuration file. Lower-numbered files are read first, so I used the name 06_custom, which is placed in another location in the /etc directory.

/etc/grub.d/06_custom

The basic structure of this file can be taken from the generated grub configuration file in the /boot directory. Just a note, I would not suggest using my examples as your templates, as I have the UUIDs of my specific hard drive partitions, which would not work on hour system.

/boot/grub/grub.cfg

Once the basic structure is added to the 06_custom file, then the individual entries can be modified as desired. I don't like how the default GRUB menu structure is organized, so I redo it completely. Below is an example of the top of the 06_custom file with the very first entry. The initial #!/bin/sh in that file is not a comment, but marks the file as executable, and is necessary. Just after menuentry, where the single quotes are visible, is the first field that should be edited, as that is the name that will appear in the boot menu. Anything after echo inside single quotes can be changed as desired, as that's what appears on the screen after the boot entry is selected.

Polish_20220714_121631044.jpg

#!/bin/sh
echo 1>&2 "Adding Arch Linux"
exec tail -n +4 $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.
#/dev/sda1

menuentry 'Arch Linux (Arch Official Kernel)' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-linux-advanced-ec4e85d6-ccb5-4d18-9fd1-f31fd30b304c' {
savedefault
    load_video
    set gfxpayload=keep
    insmod gzio
    insmod part_gpt
    insmod fat
    set root='hd1,gpt2'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt2 --hint-efi=hd1,gpt2 --hint-baremetal=ahci1,gpt2  4F61-707D
    else
      search --no-floppy --fs-uuid --set=root 4F61-707D
    fi
    echo    'Loading Arch Linux Official Kernel'
    linux   /vmlinuz-linux root=UUID=ec4e85d6-ccb5-4d18-9fd1-f31fd30b304c rw
    echo    'Loading Initial Ramdisk...'
    initrd  /intel-ucode.img /initramfs-linux.img
}

Polish_20220714_121631044.jpg

If like me you have multiple kernels, then the next bits of information to change as needed are the actual names of the Linux kernels and initial ramdisks, which can be seen below after linux and initrd. The names have to match how they are in the /boot directory, or GRUB won't be able to find them, and they won't boot.

Polish_20220714_121631044.jpg

menuentry 'Arch Linux (CachyOS Kernel)' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-linux-cachyos-advanced-ec4e85d6-ccb5-4d18-9fd1-f31fd30b304c' {
savedefault
    load_video
    set gfxpayload=keep
    insmod gzio
    insmod part_gpt
    insmod fat
    set root='hd1,gpt2'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt2 --hint-efi=hd1,gpt2 --hint-baremetal=ahci1,gpt2  4F61-707D
    else
      search --no-floppy --fs-uuid --set=root 4F61-707D
    fi
    echo    'Loading Arch Linux CachyOS Kernel'
    linux   /vmlinuz-linux-cachyos root=UUID=ec4e85d6-ccb5-4d18-9fd1-f31fd30b304c rw
    echo    'Loading Initial Ramdisk...'
    initrd  /intel-ucode.img /initramfs-linux-cachyos.img
}

Polish_20220714_121631044.jpg

Those are just two examples from that file. I have thirteen different kernels, each with their own entry in the file. There are also entries for fallback initial ramdisks for each of those thirteen kernels too, which are used in case something driver-related goes awry. I keep those in the 06_custom file, but I hide them in a submenu, to keep things cleaner and neater. Again, I give the first entry at the top of the submenu.

Polish_20220714_121631044.jpg

submenu 'Advanced options for Arch Linux' $menuentry_id_option 'gnulinux-advanced-ec4e85d6-ccb5-4d18-9fd1-f31fd30b304c' {
    menuentry 'Arch Linux (Official Kernel - Fallback)' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-linux-fallback-ec4e85d6-ccb5-4d18-9fd1-f31fd30b304c' {
    savedefault
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod fat
        set root='hd1,gpt2'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt2 --hint-efi=hd1,gpt2 --hint-baremetal=ahci1,gpt2  4F61-707D
        else
          search --no-floppy --fs-uuid --set=root 4F61-707D
        fi
        echo    'Loading Arch Linux Official Kernel (Fallback)'
        linux   /vmlinuz-linux root=UUID=ec4e85d6-ccb5-4d18-9fd1-f31fd30b304c rw
        echo    'Loading Initial Ramdisk...'
        initrd  /intel-ucode.img /initramfs-linux-fallback.img
    }

Polish_20220714_121631044.jpg

Once all the menu entries are added, and the file is saved, it must be made executable, which can be done via the command line of via graphical means. The last step whenever you modify either or both of these two configuration files, is to run the following command one more time.

grub-mkconfig -o /boot/grub/grub.cfg

Once that runs without errors (and there may be, so it's necessary to be careful adding everything), you can reboot and you should see your spify new GRUB boot menu! GRUB has so many options, and this is just working with the ones I use myself.

Polish_20220714_121754649.jpg

That brings me to the end of this 9th installment of Let's Learn Linux! I truly hope that this information is useful, and that this post was engaging, interesting, and perhaps even inspiring! Until next week! 😁 🙏 💚 ✨ 🤙

All images were taken with my Motorola G Power Android Phone or are screen shots from my laptop.

Polish_20220714_121551463.jpg

Thank you all so much who have helped me get to where I am today, and allowing me to share more of the beauty and magic from my life and my world with you, and for your continuous appreciation and support! I am truly deeply grateful! 😁🙏💚✨🤙

Polish_20220714_121551463.jpg

If you'd like to find me on other alternative platforms where I have accounts (I spend most of my time here on Hive), click on this signature image below to go to my LinkTree page.

Polish_20220714_123613996.png

If you'd like to send me a BTC Lighting Tip (made possible by the fantastic work of brianoflondon on @v4vapp), just scan the QR image below. 👇

tydynrain.png

Sources
Signature image created by @doze, and the dividers made by @thepeakstudio, with all tweaked to their present form by me.

Banner image created by me using Polish, with the Arch Linux logo converted into ASCII art, and Tux the Linux Peguin created by Larry Ewing.

Polish_20220714_121452303.jpg

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center