Say you have an drive on a Linux computer that was created in the days before UEFI was widespread. And say, you want to move it to a more modern hardware. In this case, you may want to convert that drive from Legacy BIOS to UEFI.
This is not an easy process, but quite doable, though it is a multi-step one. There are several guides online, like this one, which details the process.
Overview
The cruical part is that the new disk must:
- Be partitioned with GPT.
- Have room for a new EFI partition.
Creating an EFI partition is the harder part. It has to be about 50MB (if you intend to run Linux only), or more if you want to dual boot certain other operating systems. The filesystem type must be vfat. You may need to resize the existing Linux partition to make room for the EFI partition.
After those two crucial requirements are met, you will need to:
- Install GRUB in UEFI mode.
- Update the
/etc/fstabfile. - Switch your BIOS to UEFI only mode.
I will not cover all the above steps in detail, since the above linked guide covers all of it.
However, it is missing a crucial piece when it comes to Ubuntu (and perhaps Debian): a new GRUB package needs to be installed!
Boot From A Rescue USB Drive
You need to boot from any rescue USB drive. I prefer Finnix, but you can use anyone that you are familiar with.
Make sure that you connect an Ethernet cable. Even though you may have WiFi on your laptop/desktop, it is easier to use Ethernet since you don't need to provide an SSID and password. That way, you can install the GRUB package over the internet.
Once you boot the rescue drive, you need to figure out which partition has your root filesystem for Linux, so you can mount it.
lsblkCreate a mount point for the root partiton:
mkdir /mnt/rMount Your Root Partition
Depending on your drive, replace FOOx with your real parition, e.g. nvme0n1p5, sda2, ...etc.
mount /dev/FOOx /mnt/rBind the mount points:
mount --bind /proc /mnt/r/proc
mount --bind /sys /mnt/r/sys
mount --bind /run /mnt/r/run
mount --bind /dev /mnt/r/dev
mount --bind /dev/pts /mnt/r/dev/ptsCreate a mount point for the EFI partition:
mkdir -p /boot/efiMount the EFI partition (again replace FOOy by nvme0n1p1, sda1, ...etc.):
mount /dev/FOOy /boot/efiNow change root, so you are in the root partition:
chroot /mnt/rInstall GRUB for EFI
Here is where things change for Ubuntu ...
On Ubuntu, if your root file system was configured with a Legacy BIOS, the operating system will install the package: grub-pc, while if you install with a UEFI BIOS, the operating system will install grub-efi.
As a result, when you try to switch from Legacy BIOS to UEFI, you will NOT have the necessary software!
Therefore, you have to install the grub-efi package before reconfiguring the system for UEFI.
And to do that, you need a network connection, so the easiest way is to connect an Ethernet cable before you boot the rescue Linux media.
apt install grub-efiCheck the /etc/default/grub to make sure it exists, and that there are no odd stuff in it.
Install the EFI GRUB:
install-grubThen run the following command:
update-grubDisable initramfs resume, in case you had it:
vi /etc/initramfs-tools/conf.d/resumeAdd a single line to it, as follows:
RESUME=noneSave it, then run:
update-initramfs -uExit the chroot environment
exitUnmount everything ...
umount /mnt/r/proc
umount /mnt/r/sys
umount /mnt/r/run
umount /mnt/r/dev/pts
umount /mnt/r/devumount /mnt/rShutdown Linux:
shutdown -h nowNow, change the BIOS from Legacy to UEFI.
Hopefully, if you have done everything correctly, you will be in EFI mode.
If you see a GRUB prompt after you reboot, please refer to our article: What to do when Linux boots into a GRUB prompt.
Most Comments
Most commented on articles ...