The GRUB2 boot loader is what lets you choose which operating system or kernel version to boot into when you start your machine. Whether you’re dual-booting Windows and Ubuntu or just want to change the default kernel, tweaking GRUB2 settings gives you more control over how your system boots.
In this guide, I’ll walk you through how to configure GRUB2 on Ubuntu safely and effectively.
What Is GRUB2?
GRUB2 (GRand Unified Bootloader version 2) is the default boot loader used in most modern Linux distributions, including Ubuntu. It sits between your BIOS/UEFI and the operating system, letting you select what to load when the system starts.
Why You Might Want to Configure GRUB2
- Set a different OS or kernel as default
- Change boot timeout duration
- Hide or show the GRUB menu
- Add custom boot parameters
- Improve boot speed
Step-by-Step: Configuring GRUB2 in Ubuntu
1. Backup Your Current GRUB Configuration
Before making changes, back up the config file:
sudo cp /etc/default/grub /etc/default/grub.bak
This lets you restore settings if something breaks.
2. Edit the GRUB Configuration File
Open the GRUB config file in a text editor:
sudo nano /etc/default/grub
You’ll see lines like these:
GRUB_DEFAULT=0
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
Here’s what they mean:
GRUB_DEFAULT=0
: Sets the default boot entry.0
is the first item.GRUB_TIMEOUT=10
: Time in seconds before it boots the default entry.GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
: Kernel parameters for normal boot.GRUB_CMDLINE_LINUX
: Parameters for recovery mode.
Example: To boot the second OS in the list by default, change to:
GRUB_DEFAULT=1
To reduce the boot timeout to 3 seconds:
GRUB_TIMEOUT=3
To always show the GRUB menu (useful if it’s hidden in single-OS setups):
GRUB_TIMEOUT_STYLE=menu
3. Update GRUB for Changes to Take Effect
After editing, run:
sudo update-grub
This regenerates the GRUB configuration based on the file you edited.
4. Reboot and Verify
Restart your system:
sudo reboot
You should see your changes reflected on boot.
Bonus: Set GRUB Default by Entry Name
If you want to boot a specific entry by name (e.g., “Ubuntu, with Linux 6.2.0-25-generic”), use:
GRUB_DEFAULT="Ubuntu, with Linux 6.2.0-25-generic"
To see the full list of boot entries, run:
grep menuentry /boot/grub/grub.cfg
Troubleshooting
- Stuck in GRUB prompt? Boot from a live USB and restore the GRUB config from your backup.
- Changes not saving? Make sure you’re editing
/etc/default/grub
, not/boot/grub/grub.cfg
. - Dual boot issues? Use
os-prober
to detect other OSes:sudo apt install os-prober sudo os-prober sudo update-grub
Conclusion
GRUB2 is powerful, but with great power comes the need to be careful. Now that you know how to tweak it safely, you can control your boot experience—faster startups, different defaults, or simply making it look cleaner.
Tip: Always keep a live USB handy in case something goes wrong during boot configuration.
Leave a Reply