1

I'd like to remove a (non functional) duplicate grub installation. I ended up with two different grub installations after copying a Kubuntu partition from another PC and trying to install grub manually. After hours of trying to make it work (couldn't get rid of "no such device" + "unknown filesystem" errors upon arriving on grub), I just gave up and reinstalled Kubuntu from scratch. So now I have this:

$ efibootmgr
BootCurrent: 0005
Timeout: 1 seconds
BootOrder: 0000,0002,0005,0001
Boot0000* Windows Boot Manager
Boot0001* Hard Drive
Boot0002* grub
Boot0005* ubuntu

Boot0002 grub is the faulty one. From what I've read I can remove it with efibootmgr -Bb 0002 but I believe this only removes the boot entry and not the actual grub installation. How can I ensure grub is properly uninstalled before removing the corresponding entry?

Edit: I found a solution here but it requires Windows (I have a dual boot). Keeping this question open as someone might be interested in a linux-only solution.

2 Answers 2

0

You can check to see if you have unused/old kernel packages and this effectively removes also the grub entries and frees hard drive space. To do that you need to check what kernels are installed using:

sudo dpkg -l | grep linux-image     

And then you can remove the unused/old kernel image if any exist using:

sudo apt-get remove linux-image-version_number     

version_number being the kernel version you want to remove, usually, you would want at least two versions on your hard drive in case you run into problems with the newer updated kernel version.

/etc/default/grub     

This file contains basic settings which would be considered normal for the user to configure. Options include the time the menu is displayed, the default OS to boot, etc. The entries in this file can be edited by a user with administrator (root) privileges and are incorporated into grub.cfg when it is updated. The default options included in file upon installation are only a small number of the variables which GRUB 2 can recognize.

While the most common settings are present in the default file, additional environmental settings are available for inclusion in this file. These include items such as backgrounds and themes. The pre-defined variables are contained in /usr/sbin/grub-mkconfig and can be listed using the following command:

grep "export GRUB_DEFAULT" -A50 /usr/sbin/grub-mkconfig | grep GRUB_ 

After making changes to the file you must run this command to make the changes permanent:

sudo update-grub 
6
  • 1
    I gave grub-customizer a try before posting the question and couldn't find any way to delete a grub installation using it... I couldn't even find the faulty grub install when trying to change environments. It only suggests partitions (nvme0n1p1 to p5 while I believe the faulty grub is at the "root" of the disk, nvme0n1, if that makes any sense)
    – Jukurrpa
    Commented Apr 23, 2020 at 12:11
  • have you looked in /etc/grub.d, or /etc/default/grub to see if the duplicate entry is listed in there? Commented Apr 23, 2020 at 12:16
  • What should I be looking for in either of these folders? Just in case, as I don't know if that was clear, the issue is not an extra entry in grub (the one I'm using is properly set up), but a whole separate grub installation in another location of the disk that shows up in the motherboard's boot menu.
    – Jukurrpa
    Commented Apr 23, 2020 at 12:21
  • Checkout the link I added in the above answer this should help you solve your issue Commented Apr 23, 2020 at 12:26
  • Also, the nvme0n1 is probably a disk connected through an NVM Express port instead of e.g. a traditional SATA port. So you /dev/nvme0n1 is probably equivalent to /dev/sda1 if that helps any Commented Apr 23, 2020 at 12:31
0

The neat thing about UEFI bootloaders is that they are basically just files in a specific location - not some arcane magic you need to sprinkle on disks with special commands.

First, use efibootmgr -v to view the boot file path. All the UEFI bootloaders of normally installed OSs are located in the EFI System Partition, in a sub-directory of the EFI directory. Each bootloader/manager gets its own sub-directory, which makes removal of unwanted bootloaders easy.

For the sake of an example, I'll assume that the bootloader path of your unwanted Boot0002 entry is something like .../File(\EFI\grub\grubx64.efi). Yes, it's usually in Windows-like pathname format, and it's relative to the root directory of the EFI System Partition.

In Linux, most distributions mount the EFI System Partition to /boot/efi, but some might mount it to just /boot (Arch?) or leave it unmounted (Gentoo?). Assuming that yours mounts it to /boot/efi, you prepend that to the Windows-style pathname you found out in the previous step, and now you'll know that in the Linux view of the directory structure, the unwanted Boot0002 bootloader lives in directory:

/boot/efi/EFI/grub/

Once you know that pathname, getting rid of it will be just two easy steps:

sudo efibootmgr -B -b 0002      # make UEFI forget about this bootloader
sudo rm -r /boot/efi/EFI/grub   # and actually delete it

And just like that, the unwanted UEFI bootloader will be completely gone!

Some UEFI firmware implementations will automatically remove any UEFI boot entries that are no longer accessible - in other words, sometimes just removing the bootloader directory could be enough.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .