I have a linux box (Ubuntu 16.04) whose boot disk is partitioned using MBR. How can I convert it to GPT+UEFI?
3 Answers
Before starting, make sure you have a backup, and make sure to have a linux live boot ready to rescue your system. It's easy to mess this up!
Use gdisk to convert the partition table to GPT.
gdisk /dev/sda
Create the "BIOS boot" partition that GRUB needs.
n
to create a new partition. Needs to be about 1MB. You can probably squeeze this in from sectors 34-2047. UseL
orl
to look up the code for "BIOS boot" (ef02).Write the new partition table.
w
Reload the partition table.
partprobe /dev/sda
Re-install the GRUB boot loader using the new partition scheme.
grub-install /dev/sda
Optionally reboot to verify it's working. If you just need GPT and not UEFI, you can stop here.
Use gdisk to add an "EFI System" partition (ESP). Officially should be 100-500MB, but mine only used 130kB. Can be anywhere on the disk, so consider putting it at the end if you're using non-resizable media like a physical disk.
gdisk /dev/sda
and usen
to create the partition.Give the ESP a distinctive label without whitespace like
EFI-system
, because we'll reference the partition label in fstab.c
to set the label.Write the partition table.
w
Reload the partition table.
partprobe /dev/sda
Build the filesystem for the ESP.
mkfs -t vfat -v /dev/disk/by-partlabel/EFI-system
Create the ESP mount point.
mkdir /boot/efi
Add the ESP to
/etc/fstab
. It should look like this:/dev/disk/by-partlabel/EFI-system /boot/efi vfat defaults 0 2
Mount the ESP.
mount /boot/efi
Install EFI package on Ubuntu/Debian.
apt install grub-efi-amd64
Install the GRUB EFI bootloader.
grub-install --target=x86_64-efi /dev/sda
Reboot.
Change the BIOS from BIOS boot to UEFI boot.
Use the one-time boot menu to force boot the disk. You may have to navigate to the disk (Boot from file) ->
EFI
->ubuntu
->grubx64.efi
.Re-install GRUB's EFI bootloader to update the UEFI boot selector.
grub-install
Resources:
- The author of
gdisk
has a verbose description of MBR, GPT, and UEFI. - Clonezilla restore MBR disk to 4TB disk (convert to GPT) -- LINUX (not Windows!) covers the first part of the process.
-
1The BIOS boot partition is only needed for doing legacy boot on a GPT partitioned disk. If you boot with UEFI, it is not needed and will not be used. Commented Apr 16, 2019 at 1:40
-
You may also have to change your firmware settings to support UEFI booting.– fpmurphyCommented Apr 26, 2019 at 19:40
-
9It should be noted that maybe you should install grub-efi-amd64 package before you get started with this, otherwise you can end up in all sorts of tinkering with chroot in order to be able to install grub and boot (like I ended up) Commented Jan 23, 2020 at 20:00
-
Have a look at How to initialize new disk for UEFI/GPT? for additional hints. Do not apply its hybrid guide, though, since you will delete the existing partitions as soon as you go to geparted, choose "Device" --> GPT. That is why this gdisk is needed. Still the link might generally help understand what is going on between the lines. Commented Dec 22, 2020 at 11:19
-
Tiny bit outdated. 1. if you're booted on
/dev/sda
thenpartprobe /dev/sda
won't reload partitions, thereforegrub-install
won't work. 2.grub-install
by default now installs targetx86_64-efi
so you need to give--target=i386-pc
, 3. if you need to boot a Live USB at any point, you'll have to boot your main partition to/mnt
and ESP to/mnt/boot/efi
, thenchroot
into/mnt
and callgrub-install
there.– cprnCommented May 10 at 16:51
I was converting my BIOS/MBR system HDD to UEFI/GPT without data loss
I booted in BIOS legacy mode with MBR boot disc.
As said, I shrunk last partition to create space for new EFI System partition with gParted and formatted it to FAT32.
Then with gdisk addded this new partition and converted MBR boot disc to GPT, without data loss (two root and one home partition):
Number Start (sector) End (sector) Size Code Name
1 2048 40003583 19.1 GiB 8300 Linux filesystem
2 956772352 976771071 9.5 GiB 8200 Linux swap
3 40003584 893857099 407.1 GiB 8300 Linux filesystem
4 894054400 956465151 29.8 GiB 8300 Linux filesystem
5 956465152 956772351 150.0 MiB EF00 EFI System
I mounted this Partition as (without any fstab modifications):
sudo mount /dev/sda5 /boot/efi
And then installed GRUB-EFI:
sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi /dev/sda
I Booted with Legacy BIOS and of course didn't have efivars, so got errors...
But after i rebooted my PC to change BOOT mode to UEFI Native, I was puzzled that my PC booted normally... GRUB UEFI, despite EFI variables error, was installed OK
I executed grub-install again and this time it went OK.
-
Ubuntu ships the expected boot entry configuration in
/boot/efi/EFI/ubuntu/BOOTX64.CSV
which is written to NVRAM by shim's fallback if it's missing, so this is expected behaviour.– YtvwlDCommented Mar 23, 2021 at 17:13
Sorry first of all, have not been here for some time and I can only "answer"? I want to ask a further question on the same topic. I am currently trying to convert everything to GPT/EUFI so I can use secure boot, so that I can upgrade my WIndows 10 to 11 finally (got new hardware). So, specifically, is there any order to convert first? Windows or Linux? I remember years ago when I installed this setup, I had to make sure to install Windows first. Also, what if they are on different drives? I have a setup with Ubuntu 22 and grub on sda, and Windows 10 on sdc (sdb is just an old storage drive) and everything is booting and running fine after my mobo/cpu/mem change but currently with secure boot disabled and legacy boot (csm or something it's called?) turned ON. I have this guide and one for Windows, but does it matter how or which order I do them? Thanks!