Master the art of configuring Linux bootloaders
A bootloader is a crucial component in the Linux boot process. It's responsible for loading the operating system kernel into memory and transferring control to it. The two most common bootloaders in Linux systems are:
This guide will primarily focus on GRUB2 configuration, as it's the most widely used bootloader in modern Linux systems.
GRUB2 uses several configuration files:
/boot/grub/grub.cfg: The main configuration file (don't edit this directly)/etc/default/grub: The primary configuration file for users/etc/grub.d/: Directory containing scripts that generate the grub.cfg fileThis file contains the main user-configurable settings for GRUB2. Here are some key parameters:
GRUB_DEFAULT=0 GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX=""
GRUB_DEFAULT: Sets the default menu entry to bootGRUB_TIMEOUT: Sets the time (in seconds) to display the menuGRUB_CMDLINE_LINUX_DEFAULT: Kernel parameters for normal modeGRUB_CMDLINE_LINUX: Kernel parameters for all modesTo change the default boot entry, edit the GRUB_DEFAULT line in /etc/default/grub. You can use a number (starting from 0) or the menu entry title.
GRUB_DEFAULT="Advanced options for Ubuntu"
Modify the GRUB_TIMEOUT value to change how long the menu is displayed:
GRUB_TIMEOUT=10
To add kernel parameters, edit the GRUB_CMDLINE_LINUX_DEFAULT line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"
Add the following line to set a specific resolution:
GRUB_GFXMODE=1024x768
sudo update-grub to apply the changes.
To add custom menu entries, create a new file in /etc/grub.d/ (e.g., 40_custom) and add your entries:
#!/bin/sh
exec tail -n +3 $0
menuentry "My Custom Linux" {
set root=(hd0,1)
linux /vmlinuz root=/dev/sda1
initrd /initrd.img
}
You can customize GRUB2's appearance by setting a theme. Add this line to /etc/default/grub:
GRUB_THEME="/path/to/your/theme.txt"
GRUB2 usually detects other operating systems automatically. If it doesn't, you can manually add entries for other OSes in /etc/grub.d/40_custom.