| name | grub |
| description | Guide for GRUB bootloader configuration and management. Use when modifying boot parameters, adding kernel entries, troubleshooting boot issues, or configuring multi-boot systems. Covers GRUB2 configuration, kernel parameters, and recovery. |
GRUB Bootloader
Configuration Files
/etc/default/grub- Main settings/etc/grub.d/- Menu entry scripts/boot/grub/grub.cfg- Generated config (do not edit directly)
Default Configuration
# /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
GRUB_DISABLE_RECOVERY="false"
Common Kernel Parameters
# Add to GRUB_CMDLINE_LINUX_DEFAULT
quiet # Suppress boot messages
splash # Show splash screen
nomodeset # Disable kernel mode setting
acpi=off # Disable ACPI
noapic # Disable APIC
init=/bin/bash # Boot to shell (recovery)
single # Single user mode
systemd.unit=rescue.target # Rescue mode
Updating GRUB
# After editing /etc/default/grub
update-grub # Debian/Ubuntu
grub2-mkconfig -o /boot/grub2/grub.cfg # RHEL/Fedora
# Install GRUB to disk
grub-install /dev/sda
grub-install --target=x86_64-efi --efi-directory=/boot/efi
Custom Menu Entries
Create /etc/grub.d/40_custom:
#!/bin/sh
exec tail -n +3 $0
menuentry "Custom Linux" {
set root=(hd0,1)
linux /vmlinuz root=/dev/sda2 ro
initrd /initrd.img
}
menuentry "Windows" {
set root=(hd0,2)
chainloader +1
}
Boot Menu Navigation
| Key | Action |
|---|---|
e |
Edit entry |
c |
Command line |
Esc |
Return to menu |
Ctrl+x or F10 |
Boot edited entry |
Recovery Mode
At GRUB prompt:
# List partitions
ls
ls (hd0,1)/
# Set root and boot
set root=(hd0,1)
linux /vmlinuz root=/dev/sda2 ro single
initrd /initrd.img
boot
Reinstalling GRUB
From live USB:
# Mount root partition
mount /dev/sda2 /mnt
mount /dev/sda1 /mnt/boot/efi # EFI systems
# Bind system directories
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
# Chroot and reinstall
chroot /mnt
grub-install /dev/sda
update-grub
exit
Password Protection
# Generate password hash
grub-mkpasswd-pbkdf2
# Add to /etc/grub.d/40_custom
set superusers="admin"
password_pbkdf2 admin grub.pbkdf2.sha512...
Troubleshooting
# Check installed version
grub-install --version
# Verify configuration
grub-script-check /boot/grub/grub.cfg
# List available kernels
ls /boot/vmlinuz*