The update-grub command is an essential tool for Linux system administrators and users who need to manage their GRUB (Grand Unified Bootloader) configuration. This comprehensive guide covers everything you need to know about using update-grub effectively, from basic usage to advanced troubleshooting scenarios.
What is update-grub?
update-grub is a convenience script that automatically generates or updates the GRUB configuration file (/boot/grub/grub.cfg) based on the settings in /etc/default/grub and the scripts in /etc/grub.d/. This command is primarily available on Debian-based distributions like Ubuntu, while other distributions may use grub-mkconfig directly.
Key Functions of update-grub
- Scans for installed operating systems and kernels
- Updates boot menu entries automatically
- Applies configuration changes from
/etc/default/grub - Generates a new
grub.cfgfile - Maintains proper boot order and options
Basic Syntax and Usage
The basic syntax for update-grub is straightforward:
sudo update-grub
This command must be run with root privileges (using sudo) because it modifies system boot configuration files.
Example Output
When you run update-grub, you’ll see output similar to this:
$ sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub config file ...
Found linux image: /boot/vmlinuz-5.15.0-75-generic
Found initrd image: /boot/initrd.img-5.15.0-75-generic
Found linux image: /boot/vmlinuz-5.15.0-72-generic
Found initrd image: /boot/initrd.img-5.15.0-72-generic
Found Windows Boot Manager on /dev/sda1: Windows 10
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
When to Use update-grub
You should run update-grub in the following scenarios:
1. After Kernel Updates
When new kernel versions are installed, update-grub ensures they appear in the boot menu:
# After installing a new kernel
sudo apt install linux-image-generic
sudo update-grub
2. After Modifying GRUB Configuration
Any changes to /etc/default/grub require running update-grub:
# Edit GRUB configuration
sudo nano /etc/default/grub
# Apply changes
sudo update-grub
3. After Installing New Operating Systems
When dual-booting or multi-booting systems, update-grub detects new OS installations:
sudo update-grub
4. After Hardware Changes
Significant hardware changes may require GRUB configuration updates.
Common Configuration Changes
Changing Default Boot Option
To change which OS or kernel boots by default, modify the GRUB_DEFAULT parameter:
# Edit /etc/default/grub
GRUB_DEFAULT=0 # First menu entry
GRUB_DEFAULT=2 # Third menu entry
GRUB_DEFAULT="saved" # Remember last selection
GRUB_DEFAULT="1>2" # Submenu selection
After making changes:
sudo update-grub
Modifying Boot Timeout
Control how long the GRUB menu displays:
# In /etc/default/grub
GRUB_TIMEOUT=10 # 10 seconds
GRUB_TIMEOUT=0 # Boot immediately
GRUB_TIMEOUT=-1 # Wait indefinitely
Adding Kernel Parameters
Add persistent kernel boot parameters:
# In /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi=off"
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
Advanced update-grub Options
Verbose Output
For detailed information during the update process:
sudo update-grub --verbose
Output to Specific File
Generate configuration to a custom location:
sudo grub-mkconfig -o /boot/grub/grub.cfg.backup
Troubleshooting update-grub Issues
Common Error: Permission Denied
If you encounter permission errors:
# Error example
update-grub: command not found
# Or
/usr/sbin/grub-mkconfig: 284: cannot create /boot/grub/grub.cfg: Permission denied
Solution: Always use sudo:
sudo update-grub
Missing Kernels in Boot Menu
If kernels don’t appear after installation:
# Check if kernel files exist
ls -la /boot/vmlinuz*
ls -la /boot/initrd*
# Regenerate configuration
sudo update-grub
GRUB Configuration Backup
Always backup your working configuration before making changes:
# Backup current configuration
sudo cp /boot/grub/grub.cfg /boot/grub/grub.cfg.backup
# If something goes wrong, restore backup
sudo cp /boot/grub/grub.cfg.backup /boot/grub/grub.cfg
Distribution-Specific Considerations
Ubuntu and Debian
These distributions include update-grub as a wrapper script:
sudo update-grub
Red Hat, CentOS, and Fedora
Use grub2-mkconfig instead:
# BIOS systems
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
# UEFI systems
sudo grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
Arch Linux
Use grub-mkconfig directly:
sudo grub-mkconfig -o /boot/grub/grub.cfg
Interactive Example: Customizing GRUB Timeout
Let’s walk through a complete example of changing the GRUB timeout:
Step 1: Check Current Configuration
$ grep GRUB_TIMEOUT /etc/default/grub
GRUB_TIMEOUT=5
Step 2: Edit Configuration
sudo nano /etc/default/grub
Change the line to:
GRUB_TIMEOUT=3
Step 3: Apply Changes
$ sudo update-grub
Sourcing file `/etc/default/grub'
Generating grub config file ...
Found linux image: /boot/vmlinuz-5.15.0-75-generic
Found initrd image: /boot/initrd.img-5.15.0-75-generic
done
Step 4: Verify Changes
$ grep "timeout" /boot/grub/grub.cfg
set timeout_style=menu
set timeout=3
Best Practices and Security Tips
Regular Backups
Create automated backups of your GRUB configuration:
# Create backup script
#!/bin/bash
cp /boot/grub/grub.cfg /boot/grub/grub.cfg.$(date +%Y%m%d)
find /boot/grub/ -name "grub.cfg.*" -mtime +30 -delete
Test Changes Safely
Always test GRUB changes in a safe environment or with recovery options available:
- Keep a live USB/CD handy for recovery
- Document your changes
- Test boot process after modifications
Monitor Boot Process
After running update-grub, verify the boot process works correctly:
# Check boot logs
sudo journalctl -b -u systemd-boot
Automating update-grub
For systems that frequently receive kernel updates, consider automating the process:
#!/bin/bash
# Auto-update GRUB after kernel updates
if [ -f /var/run/reboot-required ]; then
sudo update-grub
echo "GRUB configuration updated after kernel update"
fi
Conclusion
The update-grub command is a powerful tool for maintaining your Linux system’s boot configuration. By understanding when and how to use it properly, you can ensure smooth system boots, manage multiple operating systems effectively, and troubleshoot boot-related issues. Remember to always backup your configuration before making changes and test thoroughly after modifications.
Regular use of update-grub after system changes helps maintain a reliable and up-to-date boot environment, making it an essential command in every Linux administrator’s toolkit.
- What is update-grub?
- Basic Syntax and Usage
- When to Use update-grub
- Common Configuration Changes
- Advanced update-grub Options
- Troubleshooting update-grub Issues
- Distribution-Specific Considerations
- Interactive Example: Customizing GRUB Timeout
- Best Practices and Security Tips
- Automating update-grub
- Conclusion








