Home Learn Linux A comprehensive guide to Linux Bootloader installation

A comprehensive guide to Linux Bootloader installation

We'll walk you through the process of installing and configuring GRUB on your Linux system, ensuring you have complete control over your boot process. Whether you're setting up a new Linux installation or repairing an existing one, this guide will be invaluable.

by Divya Kiran Kumar
install grub in linux

I‘ve always had a special place in my heart for Linux. Its customizability, robustness, and sheer power make it a wonderful operating system to work with. There’s a certain satisfaction in knowing that every piece of the system is under your control, allowing you to tweak and adjust it to your specific needs. However, there’s one aspect that has always been a bit of a pain point for me, and I imagine for many others: dealing with the bootloader. Specifically, the Grand Unified Bootloader, or Grub.

Grub is a bootloader package developed to support multiple operating systems and allow the user to select among them during boot-up. It’s incredibly flexible, but this flexibility can lead to a certain amount of complexity. In this blog post, I’m going to guide you through the process of installing Grub in Linux, based on my own experiences and those little nuggets of wisdom that I’ve gathered over the years.

What’s Grub?

grub menu

GRUB menu

Before we get too far ahead of ourselves, it’s important to understand what Grub is. Grub, or the GRand Unified Bootloader, is the default bootloader for many Linux distributions. It’s the first software that runs when your computer starts, loading your operating system or letting you choose between multiple OSes if you have more than one installed.

Why Grub?

“Why Grub?” you might ask, and that’s a valid question. There are other bootloaders out there, like LILO or Syslinux, but I’ve found Grub to be the most flexible and feature-rich. It supports a wide range of filesystems, can boot any Unix-like OS, and even some non-Unix OSes. Despite the occasional headache, Grub has never let me down, which is why it’s my go-to bootloader.

Why wouldn’t Grub be there in the first place

Well, there are a couple of reasons for this.

1. Grub is not the default bootloader in Linux

Firstly, not all systems use Grub as their default bootloader. Some Linux distributions might opt for alternatives like LILO (LInux LOader) or Syslinux. These bootloaders have their own merits and can serve specific use cases better than Grub. For instance, Syslinux shines in environments where simplicity and small footprint are paramount, such as embedded systems or rescue disks. And while LILO is considered somewhat old-school and less feature-rich than Grub, some users still prefer it for its simplicity and straightforwardness.

2. Boot sector may have been damaged

Secondly, Grub might not be there if the boot sector of your system gets damaged or overwritten. This can happen due to various reasons such as a faulty installation of an operating system, a hard drive failure, or an aggressive piece of malware. This is where having a backup of your data becomes essential. You wouldn’t want to lose your important files because of a bootloader issue.

3. Grub might have been overwritten by other OS

Thirdly, if you’re dual-booting your system with a non-Linux OS, such as Windows, the other OS’s bootloader might take precedence over Grub. Windows, for instance, tends to overwrite Grub with its own bootloader when installed alongside a Linux system. This could be a headache if you’re not expecting it, but it’s nothing that can’t be fixed by reinstalling Grub.

Lastly, Grub might not be there if you’ve manually removed or replaced it. Some power users or system administrators might choose to do this for various reasons – to try out a new bootloader, to simplify their boot process, or to resolve a conflict between multiple bootloaders.

Installing Grub on Linux systems

Installing Grub on Debian

Let’s start with Debian, one of my absolute favorite Linux distros. Debian is renowned for its stability, and its package manager, apt, makes installing software a breeze. As much as I adore Debian, its conservative nature means it sometimes lacks the latest features. But when it comes to installing Grub, it’s as straightforward as it gets.

Installing GRUB (GRand Unified Bootloader) on Debian requires a terminal session and root or superuser privileges. Here is a step-by-step guide:

Open Terminal.

Type the following command to become root:

su

If you’re using sudo for superuser access, you’ll use sudo in front of every command.

Update your system:

apt update && apt upgrade

Install the GRUB package with this command:

apt install grub-efi

Important: If your system is BIOS, use grub-pc instead of grub-efi in the above command.

After installing, it’s time to install GRUB to your boot partition. For EFI systems, mount the EFI partition (usually /dev/sda1 or /dev/nvme0n1p1), then install GRUB:

mount /dev/sda1 /boot/efi
grub-install /dev/sda

For BIOS systems, just install GRUB:

grub-install /dev/sda

Replace /dev/sda with your actual disk device.

Update the GRUB configuration file:

update-grub

This command will generate the grub configuration file /boot/grub/grub.cfg.

Reboot your system to see if GRUB is working properly:

reboot

Please replace all instances of /dev/sda with your actual drive. You can find this by using the lsblk or fdisk -l command. Also, keep in mind that installing a bootloader can be a risky operation if not done properly. Always ensure that you have a backup of any important data before proceeding.

Note that the steps mentioned are for Debian-based systems and may differ slightly based on the specific version of your OS.

Venturing into Arch Linux Territory

Next, let’s talk about Arch Linux. Ah, Arch, the distro that’s given me both my proudest and most frustrating moments. It’s a minimalist, rolling-release distro that gives you full control over your system. But with great power comes great responsibility, and it’s easy to shoot yourself in the foot if you’re not careful.

To install Grub on Arch, start by updating your system:

sudo pacman -Syu

Next, install Grub:

sudo pacman -S grub

Unlike Debian, Arch won’t ask where to install Grub. You’ll have to do this manually:

sudo grub-install /dev/sda

Remember to replace “/dev/sda” with your drive. Finally, generate the Grub configuration file:

sudo grub-mkconfig -o /boot/grub/grub.cfg

And voila! You’ve installed Grub on Arch Linux. It’s not as automatic as Debian, but it’s not too hard, right?

The RPM Distributions: Fedora, CentOS, RHEL

Last but not least, let’s discuss the RPM-based distros: Fedora, CentOS, and Red Hat Enterprise Linux (RHEL). These distros use the RPM package manager, which, despite being a bit clunky at times, gets the job done. And it’s not all bad – Fedora, for instance, is bleeding-edge and features the latest advancements in Linux, which I really admire.

To install Grub on an RPM-based distro, you’ll need to open the terminal and update your system:

sudo dnf update

Then, install Grub:

sudo dnf install grub2

Once Grub is installed, you’ll need to install it to your hard drive:

sudo grub2-install /dev/sda

Again, remember to replace “/dev/sda” with your drive. Finally, generate the Grub configuration file:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

And that’s it! You’ve installed Grub on an RPM-based distro.

Bonus sections!

Installing Grub in a Windows and Linux Dual Boot PC

A large number of Linux users, myself included, choose to dual boot their systems with Windows. This is particularly common among gamers and professionals who require specific Windows-only software. Now, setting up a dual boot with Windows and Linux can be a bit tricky, especially when it comes to managing the bootloader. But don’t worry, I’m here to guide you through the process.

Before we proceed, it’s important to note that if you’re planning to install both Windows and Linux on the same machine, you should install Windows first. The reason for this is that Windows’ bootloader tends to overwrite any existing one, including Grub.

So, assuming you already have Windows installed, here’s how you can install Grub for a dual boot setup:

Install Linux: Start by installing your preferred Linux distribution alongside Windows. During installation, most distros will detect the existing Windows installation and set up a dual boot system automatically. The process might vary a bit depending on the distro, but generally, you’ll need to partition your hard drive, install Linux on the new partition, and then install Grub.

Install Grub: If Grub isn’t installed as part of the Linux installation (or if Windows has overwritten it), you’ll need to install it manually. You can follow the relevant instructions from the earlier sections of this article, depending on your Linux distro.

Configure Grub: After installing Grub, you should configure it to recognize both Linux and Windows. On most systems, you can do this by updating Grub:

  • sudo update-grub (for Debian-based distros)
  • sudo grub-mkconfig -o /boot/grub/grub.cfg (for Arch Linux)
  • sudo grub2-mkconfig -o /boot/grub2/grub.cfg (for RPM-based distros)

This command should generate a new Grub configuration file, and you should see output indicating that it’s found both Linux and Windows.

If everything goes according to plan, you should now have a working dual boot system. When you start your computer, Grub will display a menu where you can choose between Linux and Windows.

Installing Grub in a macOS and Linux Dual Boot PC

For those of you who are fans of Apple’s hardware but also want to enjoy the flexibility and freedom that Linux provides, a dual boot setup with macOS and Linux might be just what you need. However, due to the differences between the EFI boot process used by macOS and the traditional BIOS boot process used by most Linux distributions, setting up a dual boot system can be a bit challenging. But fear not, it’s certainly doable, and I’m here to guide you through the process.

Before proceeding, it’s crucial to back up your data. There’s always a risk when partitioning drives and installing multiple operating systems, and I wouldn’t want you to lose any valuable data.

So, assuming you already have macOS installed, here’s how you can install Grub for a dual boot setup:

Partition the Hard Drive: Before you install Linux, you’ll need to create a partition for it on your hard drive. You can do this using Disk Utility on macOS. Make sure to format the new partition as “MS-DOS (FAT)”.

Install Linux: Boot into your Linux distribution’s live environment using a USB stick or DVD. During installation, you should be able to select the partition you created for Linux. It will need to be reformatted, usually as ext4. Follow the installation process, and when prompted, install Grub as the bootloader.

Repair the Boot Process: After installation, you’ll likely find that your computer boots directly into Linux, with no option to choose macOS. This is because Grub may not recognize the macOS EFI boot process. But don’t panic, your macOS is still there, and we can make it accessible by installing an additional piece of software called rEFInd.

First, boot into your Linux system. Then download and install rEFInd:

sudo apt-add-repository ppa:rodsmith/refind
sudo apt-get update
sudo apt-get install refind

This will add rEFInd to your EFI partition, which will be run before Grub when you boot your computer. rEFInd is able to recognize both macOS and Linux and will provide a boot menu for you to choose between them.

And there you have it, a dual boot system with macOS and Linux! It’s a bit more complicated than setting up a dual boot with Windows and Linux, but with some patience, it’s certainly achievable.

Troubleshooting

Now, here’s where my love-hate relationship with Grub really comes into play. When it works, it’s great. But when it doesn’t, boy oh boy, it can be a nightmare. However, over the years, I’ve picked up a few troubleshooting tips that might help.

If you ever find yourself in a situation where Grub refuses to boot your Linux system, try booting into a live Linux environment and reinstalling Grub. Remember, you can chroot into your installed system from the live environment, and run the same commands as before to install Grub.

Another common issue is the dreaded “unknown filesystem” error. This usually happens when Grub’s configuration file points to the wrong partition. To fix this, you’ll need to manually edit the grub.cfg file, which can be a bit scary. But as long as you’re careful and make sure to backup your data, you should be fine.

Conclusion

We’ve embarked on a thorough exploration into the world of Grub, traversing the myriad landscapes of Debian, Arch Linux, RPM-based distributions, and dual-boot systems. We’ve seen how this bootloader, as powerful and flexible as it is, can sometimes be a source of frustration. But isn’t that the charm of Linux? The challenges, the problem-solving, the feeling of triumph when things finally work – that’s what makes it so gratifying.

We’ve discussed why Grub might not be present in the first place, and we’ve detailed how to install Grub in a variety of scenarios. We’ve even touched upon the situations where you might find yourself troubleshooting Grub, and I’ve shared some of my hard-earned wisdom on that front.

We’ve seen that whether you’re running a pure Linux system or setting up a dual-boot with Windows or macOS, Grub is an integral part of the process. It might be a bit tricky, it might test your patience, but at the end of the day, its versatility is worth the effort.

As always, if you have any questions, feel free to drop them in the comments section below, and I’ll do my best to answer them. Also, I’d love to hear your own Grub stories – the good, the bad, and the “why is this happening to me?” Trust me, we’ve all been there.

You may also like

1 comment

Sanju July 4, 2023 - 2:31 AM

I wish to triple boot. sda with Arch, sdb with Mint (where grub actually is) and sdc with Windows (grub chainloads it). I have both Mint and Windows currently installed on their separate hard disks (sdb and sdc) but wish to install Arch onto sda via chainloading. How am I going to do this with installing grub anywhere else.? Thank you

Reply

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.