How To Install convert MBR Legacy booting GRUB to EFI from a non-EFI Linux Environment Ubuntu Mint Debian

 

1.) Create your EFI/ESP Partition

If you happen to have some free space on the drive already then this is easy, just create a new partition of at least 100M.

The nice thing about the EFI spec is that it must just be in the first 2.2TB of space so for most users, it means you can simply resize the last partition (downsize it by 100M) and then add an EFI partition at the end.

For example if you had this partition scheme:

/dev/sda1 = /

/dev/sda2 = swap

You could just downsize your swap partition or whatever the last partition is and then create a new partitiion as EFI/FAT32 at the end.  UEFI will still find and boot it even if it is not the first partition.

You could use gparted to achieve the above or from any other LiveCD like Ubuntu/Mint you could boot and manipulate the partition table as you need.

Format your EFI/ESP partition

Replace the xx with your info eg. if you had /dev/sda3 as your EFI partition then use mkfs.vfat /dev/sda3

mkfs.vfat /dev/sdxx

2.) chroot into your target root partition

How to properly chroot

3.) Install grub-efi first otherwise the target x86_64-efi won't exist and you won't be able to install the EFI boot loader.

apt install grub-efi

4.) Mount your ESP in /boot/efi

Remember the EFI boot loader calls for a partition type of vfat/fat32 and it can be at any location (eg. I have booted from ESP as partition#3).

mkdir -p /boot/efi

mount /dev/sda1 /boot/efi

5.) Install GRUB EFI like this:

Note that some platforms/devices/computers/laptops/servers will not boot if you don't use the --bootloader-id option and if you don't use the --no-uefi-secure-boot

Change /dev/sdx to your drive


If you are using secureboot do this:

grub-install --target=x86_64-efi /dev/sdx
Installing for x86_64-efi platform.
grub-install: warning: EFI variables are not supported on this system..
Installation finished. No error reported.

If you are not using secureboot do this:

grub-install --target=x86_64-efi /dev/sdx --no-uefi-secure-boot  --bootloader-id realtechtalk

6.) Update Partition Table

After the line in /etc/fstab add a line like this based on your UUID:

In this example we say our EFI partition is /dev/sda1 and we use the blkid tool to get the UUID

*Change /dev/sda1 to whatever your EFI partition is

blkid /dev/sda1
/dev/sda1: SEC_TYPE="msdos" UUID="A8CA-7CFC" TYPE="vfat" PARTUUID="ff050748-01"

 

UUID=A8CA-7CFC  /boot/efi       vfat    umask=0077      0       0

Then run:

update-grub

If your root partiton has changed also find the blkid of root and edit the root entry in fstab too.

 

Errors GRUB EFI won't boot or show at all or disappears from efibootmgr

The whole issue is that the grub efi binaries are hard coded to find the files in /EFI/debian for Debian for example or for Ubuntu it is /EFI/ubuntu.  If you use any bootloader-id other than those things won't work unless they exist.

To have a custom bootloader-id you need the hardcoded/default -bootloader-id in EFI/ and then you can install your customer one.  In essence --bootloader-id is broken as users have complained of for years.

This is usually caused by the issues mentioned in #4, especially installing without --bootloader-id  a lot of implementations of EFI will not boot if you don't set the --bootloader-id.

If you use a bootloader-id other than the default for the grub built for your OS eg. debian, ubuntu it will probably not work unless you use --no-uefi-secure-boot

 

 

GRUB Menu Won't Show or the EFI Computer says "No bootable disk/device"

If you have EFI/debian or EFI/ubuntu etc.. on your ESP/EFI partition and you are getting this message, it probably means your BIOS is bad/buggy.  Some EFI computers will only boot from a file called EFI/boot/bootx64.efi

You can see reports of even Asus computers and chipsets based on Z87 having this issue. 

How do you fix the problem?

Create EFI/boot on your ESP/EFI partition.

Then copy grubx64.efi from EFI/debian or EFI/ubuntu (whatever dir your EFI bootloader was installed to) to EFI/boot

Still keep your debian/ubuntu or whatever bootloader dirname you have in EFI.  Now your BIOS should pickup the file and then boot from the files it refers to in EFI/debian or EFI/ubuntu and work normally.

This is a bug as some old EFI implemenations will only boot from EFI/boot/bootx64.efi which is why a lot of OS's/distros like Ubuntu and even Microsoft Windows keep this structure.

Does your computer not boot after moving your drive to a new computer?

A symptom of this is that on the old computer grub loaded and booted fine, but now when moving to a new computer you are greeted with a black grub screen with no options.

Here is the funny thing, so if you had to create a EFI/boot directory in your old computer to make it boot.  I've seen this when moving to another computer model, that it may be not boot because it is trying to load from your boot directory and grub.cfg is not present in that directory.  The easiest solution is to wipe out the boot directory (backup your entire efi drive before to make sure).

Then for example if you have Linux Mint or Ubuntu, keep the remaining directory of "ubuntu" and then your computer should boot.

This is another weird example of quirk of how different BIOS' may handle EFI booting which is much more complicated than the old Legacy MBR days.

 

Do you need a GPT partition table / does EFI support MBR partitions?

Yes, in my experience using an MBR partition is not an issue at all.

 


Tags:

install, grub, efi, linux, ubuntu, mint, debian, _, loader, apt, chroot, partition, mount, esp, vfat, eg, booted, mkdir, dev, sda, sdx, installing, platform, variables, supported, installation, reported,

Latest Articles

  • Cisco CME How To Enable ACD hunt groups
  • How to install gns3 on Linux Ubuntu Mint
  • How to convert audio for Asterisk .wav format
  • Using Cisco CME Router with Asterisk as a dial-peer
  • Cisco CME How To Configure SIP Trunk VOIP
  • Virtualbox host Only Network Error Failed to save host network interface parameter - Cannot change gateway IP of host only network
  • Cisco CME and C7200 Router Testing and Learning Environment on Ubuntu 20+ Setup Tutorial Guide
  • Abusive IP ranges blacklist
  • How to Install Any OS on a Physical Drive from Windows Using VMware Workstation (Linux, Windows, BSD)
  • CDN Cloudflare how to set and preserve the real IP of the client without modifying application code on Apache
  • CentOS 7 fix Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was 14: curl#6 -
  • Ubuntu Debian How To Install Recommended Packages Automatically
  • How to set Linux Ubuntu Redhat Debian Command Line http https socks proxy for yum apt
  • How to resize a pdf without losing much quality in Linux Mint Ubuntu Debian Redhat Solution
  • qemu: could not load PC BIOS 'bios-256k.bin' solution
  • Proxmox How To Custom Partition During Install
  • Hyper-V Linux VM Boots to Black Screen, Storage, NIC Not Found Issues
  • Ubuntu Mint How to Fix Missing/Broken /dev and /dev/pts which causes terminal to immediately close exit and not work
  • How high can a Xeon CPU get?
  • bash fix PATH environment variable "command not found" solution