In this article, you’ll learn how to update GRUB on Ubuntu or any other Linux distribution. You’ll also learn a thing or two about updating how this GRUB process works.

How to Update GRUB

Ubuntu and many other Linux distributions provide an easy-to-use command-line utility called update-grub.

To update GRUB, all you have to do is run this command on the terminal using sudo.

sudo update-grub
Copy the code

You should see an output like this:

[email protected]:~$ sudo update-grub
[sudo] password for abhishek:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.0.0-37-generic
Found initrd image: /boot/initrd.img-5.0.0-37-generic
Found linux image: /boot/vmlinuz-5.0.0-36-generic
Found initrd image: /boot/initrd.img-5.0.0-36-generic
Found linux image: /boot/vmlinuz-5.0.0-31-generic
Found initrd image: /boot/initrd.img-5.0.0-31-generic
Found Ubuntu 19.10 (19.10) on /dev/sda4
Found MX 19 patito feo (19) on /dev/sdb1
Adding boot menu entry for EFI firmware configuration
done
Copy the code

You might see a similar command called update-grub2. There is no need to feel scared or overwhelmed between update-grub and update-gruB2. These two commands perform the same action.

About 10 years ago, when GRUb2 was first introduced, the update-grub2 command was also introduced. Right now, update-grub2 is just a symbol linked to update-grub, and they both update the GRUB2 configuration (since GRUB2 is the default).

Can’t find update-grub? So here’s what to do in this situation

It could be that your Linux distribution may not have update-grub commands available.

What should you do in this situation? How do you update GRUB on such a Linux distribution?

There’s no need to panic here. The update-grub command is just an entry point for generating the GRUb2 configuration file by running grub-mkconfig -o /boot/grub/grub.cfg.

This means that you can update GRUB on any Linux distribution using the following commands:

sudo grub-mkconfig -o /boot/grub/grub.cfg
Copy the code

Of course, remembering the update-grub command is much easier than the above command, which is why it was created in the first place.

How does update-GRUB work?

When you install a Linux distribution, it (usually) requires you to install the GRUB boot program.

Grub is partially installed on the MBR/ESP partition. The rest of GRUB remains in the /boot/grub directory of the Linux distribution.

Depending on its MAN page, update-grub works by looking in the /boot directory. All files starting with vmlinuz- will be treated as kernels, and they will get a GRUB menu item. It will also add the initrd line for the ramdisk image that is the same as the kernel version found.

It also uses OS-prober to find all disk partitions for other operating systems. If it finds other operating systems, it adds them to the GRUB menu.

Why do you need to update GRUB?

There are many scenarios where you need to update GRUB.

Suppose you modify the GRUB configuration file (/etc/default/grub) to change the default boot order or reduce the default boot time. Unless you update GRUB, your changes won’t take effect.

On the other hand, you have multiple Linux distributions installed on the same computer system.

For example, on my Intel NUC, I have two disks. The first disk had Ubuntu 19.10, and I installed Ubuntu 18.04 on it. The second operating system (Ubuntu 18.04) installed its own GRUB, and grub’s boot screen is now controlled by Ubuntu 18.04 GRUB.

On the second disk, I installed MX Linux, but this time I didn’t install GRUB. I want the existing GRUB (controlled by Ubuntu 18.04) to handle all operating system projects.

Now, in this case, GRUB on Ubuntu 18.04 needs to be updated so that it can see MX Linux.

As shown above, when I updated GRUB, it found a number of installed Linux kernels on 18.04, as well as Ubntu 19.10 and MX Linux on different partitions.

If you want MX Linux to control GRUB, I can use the grub-install command to install GRUB on MX Linux, and grub on MX Linux will start controlling the GRUB boot screen. You already know that, don’t you?

Using a GUI tool like Grub Customizer is an easy way to make changes in Grub.

And finally…

Initially, I intended to keep it as a short essay as a quick tip. But then I wanted to explain something about it so that (relatively) new Linux users can learn more than just a simple command.

Do you like it? Do you have any questions or suggestions? Feel free to comment.


Via: itsfoss.com/update-grub…

Written by Abhishek Prakash (Lujun9972

This article is originally compiled by LCTT and released in Linux China