What GRUB is and when you need to install it yourself

GRUB (Grand Unified Bootloader) is the program that runs when your computer starts up, before any operating system loads. It displays a menu letting you choose which system to boot — Linux, Windows, or another OS — and passes control to whichever one you select. Most Linux distributions install GRUB automatically during setup, but you may need to reinstall or reconfigure it if you replace a hard drive, add a new operating system, repair a broken boot, or want to change how the menu looks and behaves.

Installing GRUB yourself means running commands from a Linux terminal or from a live USB drive. The process differs slightly depending on whether your system uses BIOS or UEFI firmware, and whether you're working on an existing Linux installation or recovering a broken one. This guide covers the most common scenario: reinstalling GRUB on a system where Linux is already installed but the bootloader is missing or damaged.

Key Takeaways

  • GRUB installation requires root access and knowledge of your disk layout — specifically which drive holds your Linux installation and which partition is your boot partition.
  • BIOS and UEFI systems use different installation commands, and using the wrong one will leave your system unbootable.
  • The two main steps are installing the GRUB package to your disk and then generating the configuration file that tells GRUB which operating systems to show in the menu.
  • If your Linux system won't boot, you can boot from a live USB, mount your existing Linux partition, and reinstall GRUB without losing your files.
  • After installation, test the bootloader by restarting your computer and checking that the GRUB menu appears with all expected operating systems listed.

Determine your system's firmware type and disk layout

Before you install GRUB, you need to know two things: whether your computer uses BIOS or UEFI firmware, and which disk and partition hold your Linux installation. Open a terminal on your working Linux system and run ls /sys/firmware/efi. If the directory exists, you have UEFI; if it does not exist, you have BIOS.

Next, identify your disks and partitions. Run lsblk to see a tree view of all drives and their partitions. Look for the partition where your Linux root filesystem lives — this is usually labeled as / in the output. Also note which partition is mounted at /boot or /boot/efi, as GRUB needs to know about this. For example, you might see /dev/sda1 as your boot partition and /dev/sda3 as your root partition. Write these down — you will need them in the next steps.

Install GRUB on a working Linux system

If your Linux system boots normally but you want to reinstall or reconfigure GRUB, open a terminal and install the GRUB package. On Debian-based systems (Ubuntu, Linux Mint, Debian), run sudo apt update followed by sudo apt install grub-pc for BIOS systems or sudo apt install grub-efi-amd64 for UEFI systems. On Red Hat-based systems (Fedora, CentOS, RHEL), run sudo dnf install grub2 instead.

After the package installs, you need to write GRUB to your disk. For BIOS systems, run sudo grub-install /dev/sda, replacing sda with your actual disk name (not a partition number). For UEFI systems, run sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi /dev/sda. The command should report "Installation finished. No error reported." If you see an error, double-check that you used the correct disk name and that the partition paths exist.

Finally, generate the GRUB configuration file by running sudo grub-mkconfig -o /boot/grub/grub.cfg on BIOS systems or sudo grub-mkconfig -o /boot/efi/EFI/grub/grub.cfg on UEFI systems. This command scans your disks for operating systems and creates a menu. Restart your computer and watch for the GRUB menu to appear.

Reinstall GRUB from a live USB if your system won't boot

If your Linux system no longer boots and you see only a black screen or a BIOS/UEFI menu, you can recover it by booting from a live USB drive containing the same Linux distribution you installed. Insert the USB, restart your computer, and press the key to enter the boot menu — usually F12, Esc, or Del depending on your manufacturer. Select the USB drive and boot into the live environment.

Once the live system loads, open a terminal. You need to mount your existing Linux partition so you can access its files. Run sudo mkdir -p /mnt/linux to create a mount point, then sudo mount /dev/sda3 /mnt/linux, replacing sda3 with your actual root partition. If you have a separate boot partition, also run sudo mount /dev/sda1 /mnt/linux/boot. For UEFI systems, add sudo mount /dev/sda2 /mnt/linux/boot/efi (adjust partition numbers as needed).

Next, chroot into your mounted system so that commands run as if you were booted into it normally. Run sudo chroot /mnt/linux. Now you can install GRUB exactly as described in the previous section — run the apt install or dnf install command, then grub-install, then grub-mkconfig. When finished, type exit to leave the chroot, then restart your computer and remove the USB drive.

Customize the GRUB menu appearance and behavior

The GRUB configuration file at /boot/grub/grub.cfg is generated automatically and should not be edited directly. Instead, edit /etc/default/grub, which is the source file that grub-mkconfig reads. Open it with sudo nano /etc/default/grub or your preferred text editor.

Common settings include GRUB_TIMEOUT, which controls how many seconds GRUB waits before booting the default entry (set to 0 to boot immediately, or a higher number to give you time to choose). GRUB_DEFAULT sets which menu entry boots by default — use 0 for the first entry, 1 for the second, and so on. GRUB_CMDLINE_LINUX lets you add kernel parameters that apply to all Linux entries. After making changes, save the file and run sudo grub-mkconfig -o /boot/grub/grub.cfg to regenerate the menu.

Troubleshoot common GRUB installation problems

If grub-install reports "cannot find a GRUB drive for /boot/grub", you may have specified the wrong disk or partition. Double-check your disk layout with lsblk and make sure you are installing to the disk itself (like /dev/sda) rather than a partition (like /dev/sda1). For UEFI systems, ensure that /boot/efi exists and is mounted before running grub-install.

If GRUB installs but the menu does not appear at startup, you may have a BIOS/UEFI setting that bypasses the bootloader. Restart your computer, enter the BIOS or UEFI setup (usually by pressing F2, Del, or F10 during startup), and check the boot order. Make sure the disk containing GRUB is listed first. Some systems also have a "Secure Boot" setting that can interfere with GRUB — try disabling it if the menu still does not appear.

If the GRUB menu appears but does not list all your operating systems, run sudo grub-mkconfig -o /boot/grub/grub.cfg again. GRUB scans for Windows, other Linux distributions, and other bootable systems automatically, but it may miss them if they are on a different disk or if the scan runs before all partitions are mounted. If an operating system still does not appear, you can add it manually by editing /etc/grub.d/40_custom and adding a menu entry, then regenerating the configuration.

Test your GRUB installation

After installing or reconfiguring GRUB, restart your computer and watch carefully as it boots. You should see the GRUB menu appear with a list of operating systems, usually with a Linux entry highlighted in yellow. If you have multiple Linux distributions or Windows installed, they should all appear in the list. Use the arrow keys to select an entry and press Enter to boot it.

If the menu does not appear, your system may be booting directly to the default entry without showing the menu. This is normal if GRUB_TIMEOUT is set to 0. To see the menu, hold Shift or Esc while the computer starts up — this forces GRUB to display the menu even if the timeout is disabled. If you want the menu to always appear, edit /etc/default/grub, set GRUB_TIMEOUT to a number like 5, and regenerate the configuration.

Frequently Asked Questions

What is the difference between BIOS and UEFI, and why does it matter for GRUB?

BIOS is older firmware that boots from the first sector of a disk, while UEFI is newer and boots from a special EFI partition. GRUB must be installed differently for each: BIOS uses grub-install /dev/sda, while UEFI uses grub-install --target=x86_64-efi and requires an EFI partition. Using the wrong command will leave your system unbootable.

Can I install GRUB without losing my files?

Yes. GRUB is the bootloader, not the filesystem. Reinstalling it does not touch your files or operating system. You can safely reinstall GRUB as many times as needed without data loss, as long as you specify the correct disk and partition.

What should I do if I accidentally installed GRUB to the wrong disk?

Boot from a live USB, mount your Linux partition, chroot into it, and run grub-install again with the correct disk name. Then regenerate the configuration. Your files are unaffected — you are simply correcting where the bootloader is installed.

How do I add Windows to the GRUB menu if it does not appear automatically?

Run sudo grub-mkconfig -o /boot/grub/grub.cfg again — GRUB usually detects Windows automatically if it is on a different disk. If it still does not appear, edit /etc/grub.d/40_custom with a text editor, add a custom menu entry pointing to your Windows partition, save the file, and regenerate the configuration.

Can I change the GRUB menu background or font?

Yes. You can add a background image by placing a PNG or JPG file in /boot/grub/ and editing /etc/default/grub to set GRUB_BACKGROUND=/boot/grub/image.png. Font changes are more complex and depend on your distribution, but most allow you to set GRUB_FONT to a path like /boot/grub/fonts/unicode.pf2. Regenerate the configuration after making changes.