Ubuntu – Uninstalling GRUB from UEFI laptop


I installed Ubuntu alongside Windows 8, however have decided to unisntall Ubuntu.

First I booted into Parted Magic and, using GParted deleted all the ext4 and swap partitions.

This leaves me with the same partitions I had before I installed Ubuntu:

/dev/sda1 ntfs WINRE_DRV
/dev/sda2 fat32 SYSTEM_DRV (my UEFI partition)
/dev/sda3 fat32 LRS_ESP
/dev/sda4 unknown Microsoft Reserved Partition
/dev/sda5 ntfs Windows8_OS
/dev/sda6 ntfs LENOVO
/dev/sda7 ntfs PBR_DRV

I expected deleting the partitions would be enough to remove Ubuntu and allow me to boot back into Windows 8, however whenever I boot I get the following error:

error: no such partition.

which is followed by GRUB rescue:

grub rescue>

In my UEFI partition, there are two directories BOOT and EFI. In BOOT is a single file – boot.sdi. In the EFI directory are another two directories, BOOT and Microsoft. Inside BOOT are two files, bkpbootx64.efi and bootx64.efi. The Microsoft directory has a directory in it named Boot. Inside it are the normal Microsoft EFI files (as far as I can tell).

Thinking there were still GRUB files left, I ran find . -iname "*grb*" and find . -iname "*grub*" in the UEFI partition, however only found one empty file, bootx64.efi.grb (which I deleted).

How is GRUB still installed, and how can I uninstall it?

I'm pretty new to UEFI and so things may need explained in detail. The computer is a Lenovo IdeaPad Z580.

edit: I forgot to mention, I deleted the ubuntu folder in the UEFI partition.

edit 2: I managed to get back into Windows through a "System Recovery" option in the laptop's BIOS settings. This may or may not have solved the issue.

edit 3: okay, I can boot almost normally now. When I boot, I see No partition active for a couple of seconds then Windows boots. How can I remove that?

Best Answer

  • I realize you've fixed the problem, but I want to point out what went wrong and how it should be fixed (both by end users and by Ubuntu's developers).

    First, Ubuntu's developers have decided -- most unwisely -- to create a GRUB configuration that relies on files in the Ubuntu root (/) partition, as well as on the EFI System Partition (ESP). This makes GRUB vulnerable to removal of or damage to the Linux partition, and therefore makes it difficult to boot the computer after removing Ubuntu or if the Ubuntu installation is damaged in some way. This vulnerability is unnecessary; it is possible to configure GRUB to look for all its support and configuration files on the ESP. If GRUB were configured in this way (as Fedora does), then deleting Ubuntu would not affect GRUB's ability to redirect to Windows. The system would still boot through GRUB, but it would at least still boot. So, shame on Ubuntu for setting GRUB up the wrong way.

    Second, based on the filenames you mentioned, you seem to have run Ubuntu's Boot Repair tool at some point. This tool automatically renames the Windows boot loader, EFI/Microsoft/Boot/bootmgfw.efi, and places a copy of GRUB in its place. It does the same thing with the EFI fallback boot loader, EFI/BOOT/bootx64.efi, and drops another copy of GRUB in as EFI/Microsoft/Boot/bootx64.efi, for reasons that I don't claim to fathom. This is a done as a workaround for a bug in a handful of EFIs. The trouble is that Boot Repair does this by default. On most computers, it is not necessary. When it's subsequently desirable to make changes to the boot configuration, this renaming and replication of GRUB becomes a complication, since users are left guessing about what's going on. So, shame on Boot Repair's developers for being unsubtle about their repairs. (In their defense, though, it would be very difficult for Boot Repair to reliably detect which computers have the bugs that require moving boot files in the way that it does by default.)

    One more point is important: In a properly-functioning EFI system, a list of boot programs is held in NVRAM. The EFI tries each of the programs in this list in sequence; if one fails or is absent, the next one is tried. When Ubuntu installs, it adds its version of GRUB to the top of the list. Most EFIs also enable users to specify which boot program to use from a built-in boot manager, but this built-in boot manager is crude on most EFIs.

    Sum all these factors up, and the simplest solution to the original problem becomes:

    1. Undo the Boot Repair tool's changes. This can be done using the Boot Repair tool itself; it has an Advanced Options menu with a check-box called "Restore EFI Backups". Use that and the multiple copies of GRUB will be removed and Windows' boot loader will be restored. Alternatively, this can be done manually. Most importantly, the backup of bootmgfw.efi (probably called bkpbootmgfw.efi, although some versions of Boot Repair have used other names) should be copied to EFI/Microsoft/Boot/bootmgfw.efi on the ESP.
    2. Delete GRUB in its official/proper location -- EFI/ubuntu/grubx64.efi for Ubuntu. If Secure Boot was active, deleting EFI/ubuntu/shimx64.efi would be necessary instead. In fact, deleting the whole EFI/ubuntu directory, or at least renaming it, would do the job in any case.

    That's it. With those two things accomplished, the EFI will skip the Ubuntu boot option because it's not longer valid and go on to boot Windows. Some EFIs will also automatically remove the Ubuntu boot option from their boot managers' menus, too, although this practice is not universal.

    Note that in your case, Matthew, I don't recommend doing these things; you've got a working configuration, and as they say, "if it ain't broke, don't fix it." You may have a few stray files left on your ESP, but they aren't doing any harm, so it's best to just leave it alone. I've presented my answer in the hope that somebody else will find it useful.

    EDIT: The above was correct when I first wrote it, and the principles remain the same; however, Boot Repair no longer automatically renames the Windows boot loader and replaces it with another copy of GRUB. (Boot Repair can do this optionally, but the option is buried on an advanced options menu, so it's no longer done by default.) This fact makes recovery from this problem easier today than it was in 2013. In most cases, you need only delete the EFI/ubuntu directory on the ESP to make the system boot directly to Windows. If GRUB still appears after you do this, you may have used the Boot Repair option to back up and rename boot files, in which case using it to undo those actions is in order, as noted earlier.

    Another option is to use the computer's built-in boot manager (usually accessed by hitting a function key, Esc, or Enter soon after you turn on the computer) to bypass GRUB and boot to Windows. You can then use EasyUEFI to adjust the boot order and/or delete the ubuntu entry from the boot list. This action won't delete GRUB from the ESP, but it will bypass GRUB.

  • Related Question