Score:1

How do I cleanly and completely remove Grub on Ubuntu 22.04

ng flag

I have replaced Grub with rEFInd on my system and am very happy about it. I now wish to completely uninstall Grub and make sure that Ubuntu isn't bringing it back the next time it installs updates.

I tried with sudo apt-get purge grub-pc but it is failing with:

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 shim-signed : Depends: grub-efi-amd64-signed (>= 1.187.2~) but it is not going to be installed or
                        grub-efi-arm64-signed (>= 1.187.2~) but it is not installable
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

I understand I can try to find all Grub related packages and remove them one after the other, but there must be a better way than that? Also that won't remove Grub's files from /boot/efi/ and leave Grub's entry in the EFI Boot Manager behind from what I understand.

And do I need to do anything more to stop Ubuntu from automatically forcing Grub on me again the next time it installs any updates?

oldfred avatar
cn flag
rEFInd is an UEFI boot manager (menu). Grub is both a boot manager & boot loader. You can remove the grub UEFI menu entry in UEFI & grub in ESP's boot folder. But still need grub to boot. https://askubuntu.com/questions/429610/uninstall-grub-and-use-windows-bootloader/497720#497720 I have an old USB flash drive that was too small for anything, now. But then found rEFInd fits nicely and have used it for emergency boot. But I use grub normally.
user3700562 avatar
ng flag
I'm booting the kernel directly using its efistub bootloader so I'm not using grub's bootloader functionality.
oldfred avatar
cn flag
Do not know if Ubuntu's kernel is compiled to use efi-stub. https://wiki.archlinux.org/title/EFISTUB If not you may have kernel update issues.
Score:1
in flag

Refind is not an accepted standard boot method for Ubuntu. This doesn't mean it doesn't work, it just means that Ubuntu doesn't accept it to satisfy dependencies for booting, so you can't really remove grub without breaking parts of Ubuntu.

Also, while refind can boot Ubuntu without assistance, there is a chance you are actually booting grub through refind, so it is unclear that your system will still boot if you completely remove grub.

Even if you aren't booting grub through refind, grub may be pulling in dependencies that refind is using, and if you succeed in completely removing grub, those dependencies might also be removed and you could end up with an unbootable system.

Your best bet might be to just make sure refind is your default bootloader and ignore grub. There's usually no harm in having multiple bootloaders, and sometimes it is nice to have redundant bootloaders in case something goes wrong. If grub gets updates (which are infrequent anyway), it might reset the boot order, but it shouldn't be too hard to change it back. There may be a grub option to tell it not to change boot order on update.

user3700562 avatar
ng flag
I'm booting the kernel directly using its efistub bootloader
user10489 avatar
in flag
Yup. Makes sense.
Score:0
jp flag

Removing GRUB 2 is covered in the rEFInd documentation:

https://www.rodsbooks.com/refind/bootcoup.html#disabling_grub

In brief, you use apt to remove the various GRUB packages, as you're trying; however, dependencies keep changing over time, so you may need to track them all down and remove them individually (or all in one command line). Unfortunately, an increasing web of dependencies is making this harder to do, since various packages you might want or need now depend on GRUB, even though they don't really need GRUB -- just any boot program. Thus, as @user10489 suggests, keeping GRUB around but ensuring that rEFInd is the default boot program may be easier and safer.

OTOH, if GRUB is kept installed, Ubuntu's package management will probably try to update it, sooner or later, and this may result in a boot coup, in which GRUB takes over as the default boot program. You can either deal with this manually or in a semi-automated way (by using refind-mkdefault when it happens, or putting that in a shutdown script); or you can try to prevent GRUB updates by using apt-mark hold, as in:

sudo apt-mark hold grub-efi-amd64 grub-efi-amd64-signed grub-common grub-efi-amd64-bin grub-common grub2-common

(That example is from the preceding documentation page. I haven't checked it today, so the package list might need to be changed.)

I can definitively say that it is possible to completely remove the GRUB packages and all their dependencies and the computer will continue to boot, so long as it's booting through rEFInd. I run several systems this way. (I'm rEFInd's maintainer.) It can be a nuisance, though, and it means that you might not get updates to some important packages, like shim, since they're (unnecessarily) dependent upon GRUB. (rEFInd will, when Secure Boot is active, copy over whatever Shim binary it thinks is newest to rEFInd's directory, so rEFInd will continue to boot through that Shim binary even after the shim package is removed. If Secure Boot is inactive, or if you set it up to boot with Secure Boot active without Shim, then this is irrelevant.)

As to GRUB's files on the ESP and the GRUB entry in the NVRAM, they're basically just harmless clutter, once you set up a rEFInd-only installation. If you want to remove those files and the NVRAM entry, you can do so, but you'll have to do so manually. AFAIK, there's no script to do this -- certainly not that ships with rEFInd, and AFAIK not with GRUB, either. It's not hard to do -- just one rm command to delete the files and two efibootmgr commands (one to find the relevant entry and another to delete it), but you need to know what you're doing. It's probably best to just leave it alone.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.