A machine installed the old way boots through the firmware’s Compatibility
Support Module: an MBR partition table and a bootloader in the boot sector.
Switch CSM off and the firmware finds nothing, because UEFI boots only from
an EFI System Partition, and an MBR disk has none. The machine drops into
its setup screen.

That matters as soon as something needs UEFI. Intel Arc graphics cards carry
no legacy video BIOS and may give no picture at all with CSM enabled, and
Resizable BAR needs Above 4G Decoding, which firmware keeps locked while CSM
is on.

This converts the disk in place. The root filesystem is never resized and
never moved. The swap partition is the donor for the new EFI partition,
because swap holds nothing worth keeping.

What this page assumes

  • Arch or Manjaro, since it uses pacman, grub and a chroot helper

  • One disk with an MBR table, a root partition, and a swap partition after it

  • Swap can lose 512 MB, which is all the EFI partition needs

  • A live USB of the same distribution, and a second machine to read from

  • A current backup, because an in-place table rewrite is recoverable but not

    risk free

If swap is not the last partition, or there is no swap, the same procedure
works but the space has to come from somewhere else, typically by shrinking
the last filesystem first. That part is not covered here.

Every number on this page is an example

The sector numbers, partition sizes and UUIDs below come from one particular
machine. They are shown so each step has something concrete to compare
against, not because they will match any other disk. Read the real values
from the machine being converted and use those. The one thing that
generalises is the shape of each check, never the digits.

What an ESP is

ESP means EFI System Partition. It is a small FAT32 partition carrying the
GPT type code ef00, holding bootloaders as .efi files. It must be FAT
because UEFI firmware cannot read ext4, so the firmware needs one filesystem
on the disk that it understands. The firmware keeps boot entries in its own
NVRAM, each pointing at a file on an ESP, and grub-install writes both the
file and the entry.

Step 1 - on the installed system, before shutting down

Context: the running system, a normal terminal, as the ordinary user.

Read the partition geometry. This needs no root and the same command works
later in the live session.

grep . /sys/block/sda/sda?/start /sys/block/sda/sda?/size /sys/block/sda/size

Example output, not values to expect:

/sys/block/sda/sda1/size:940600383
/sys/block/sda/sda1/start:2048
/sys/block/sda/sda2/size:36165634
/sys/block/sda/sda2/start:940602431
/sys/block/sda/size:976773168

Write those down, or read them from the other machine later. Partition 1
must still show the same start and size after the conversion, and that
comparison is the main safety gate.

Confirm the bootloader packages are present, so the chroot later needs no
network and no package installation:

pacman -Qq grub efibootmgr
ls -d /usr/lib/grub/x86_64-efi

Both names must come back and the directory must exist. Then shut down.

Also stop anything that runs unattended against the filesystem, a backup
timer for instance. Disable it rather than stopping it, because a stopped
unit that is still enabled returns on the next boot, and the dangerous
moment is the first boot after the conversion.

Step 2 - boot the live stick in UEFI mode

Context: no shell, at the keyboard during POST.

Leave CSM enabled for now. Open the firmware’s one time boot menu, usually
F11 or F12, and look at how the stick is listed. With CSM on it appears
twice, once plainly and once with a UEFI prefix. Choose the UEFI entry.

This matters because EFI variables only exist when the system itself booted
through UEFI. Without them grub-install cannot register a boot entry in
firmware NVRAM, and the conversion produces a disk the firmware will not
boot.

Step 3 - a root shell, and two checks

Context change: the live session, the ordinary live user becomes root.

sudo -i
ls /sys/firmware/efi

A directory listing means the stick booted in UEFI mode. An error saying no
such file means it booted legacy, so reboot and repeat step 2.

Keep this root shell open to the end. It will hold a shell variable.

Now confirm the disk is in the state the recorded numbers describe, because
the abort gate in step 6 and the check in step 7 both compare against them:

grep . /sys/block/sda/sda?/start /sys/block/sda/sda?/size /sys/block/sda/size

Every line must match what step 1 recorded. Any difference means stop.

Step 4 - capture the swap UUID

Context: the live session, the same root shell.

The new swap partition should carry the old UUID. Keeping it means fstab
needs no edit for swap, and a resume parameter for hibernation keeps
pointing at something real. The old partition is about to be deleted, so
read the value out of the fstab on the root filesystem first.

mount -o ro /dev/sda1 /mnt
S=$(awk '$3=="swap"{print $1}' /mnt/etc/fstab | cut -d= -f2)
echo $S
umount /mnt

The echo must print a 36 character UUID, for example
00000000-1111-2222-3333-444444444444. If it prints nothing, the fstab swap
line is not UUID based, and the value can be taken from a resume=UUID=
parameter in the grub defaults instead. Do not continue with an empty
variable, mkswap would then invent a new UUID and hibernation would break.

Reading it into a variable also means the UUID is never retyped, which is
worth insisting on. Transcribing 36 hex characters by hand is a good way to
produce a system that boots into an emergency shell.

Step 5 - make the next step reversible

Context: the live session, the same root shell.

Dump the current table as text and copy the first two megabytes of the disk,
which is where the MBR and the start of the first partition live.

sfdisk -d /dev/sda > /root/sda-table-backup.txt
dd if=/dev/sda of=/root/sda-first-2MB.img bs=1M count=2
cat /root/sda-table-backup.txt

The cat must show the existing partitions. An empty file means stop, there
would be no way back.

Both files live in the live session’s RAM and vanish at reboot, which is
fine, they are only needed until the formatting step. Copy them elsewhere
first if they should survive longer. To undo the conversion later in the
same session, restore the table and nothing else:

sfdisk /dev/sda < /root/sda-table-backup.txt

Step 6 - repartition

Context: the live session, the same root shell.

swapoff -a
gdisk /dev/sda

On start gdisk warns that it found a valid MBR and is converting it to GPT
in memory. That is expected, and nothing reaches the disk until the final w.

Each prompt is on its own line below, and the answer to type is the indented
line under it. The numbers inside the prompts vary with the disk, the
answers do not.

Command (? for help):
   d
Partition number (1-2):
   2

Command (? for help):
   n
Partition number (2-128, default 2):
   Enter
First sector (default = ...):
   Enter
Last sector (default = ...):
   +512M
Hex code or GUID (Enter = 8300):
   ef00

Command (? for help):
   n
Partition number (3-128, default 3):
   Enter
First sector (default = ...):
   Enter
Last sector (default = ...):
   Enter
Hex code or GUID (Enter = 8300):
   8200

Command (? for help):
   p

Command (? for help):
   w
Do you want to proceed? (Y/N):
   Y

Enter means press Return and accept the offered default.

The p step is the gate. Partition 1 must still show the start sector and end
sector recorded in step 1. If it does not, type q rather than w. Quitting
writes nothing at all and the disk stays as it was.

Step 7 - verify, then format

Context: the live session, the same root shell.

These numbers come from the kernel rather than from gdisk, so they describe
the table that was actually written.

grep . /sys/block/sda/sda?/start /sys/block/sda/sda?/size

Example output from the machine this page was written on:

/sys/block/sda/sda1/size:940600383
/sys/block/sda/sda1/start:2048
/sys/block/sda/sda2/size:1048576
/sys/block/sda/sda2/start:940603392
/sys/block/sda/sda3/size:35121167
/sys/block/sda/sda3/start:941651968

Three things must hold, whatever the actual digits:

  • partition 1 start and size exactly as recorded in step 1, so root is

    untouched

  • partition 2 size 1048576 sectors, which is 512 MiB, proving partition 2

    really is the new ESP so the format below cannot land on something else

  • partition 3 exists and takes the remaining space

Start sectors depend on how gdisk aligned the partitions and may differ a
little. The sizes may not.

If anything is wrong, stop, and put the table back with the dump from step
5. Only once the check passes:

mkfs.fat -F32 /dev/sda2
mkswap -U $S /dev/sda3

The variable comes from step 4. If the shell was closed in between it is
gone, so redo step 4 rather than guessing the UUID.

This is the point of no return. Before it, the table dump restores
everything. After the format, the dump no longer matches the disk.

Step 8 - mount and enter the installed system

Context: the live session, the same root shell.

mount /dev/sda1 /mnt
mkdir -p /mnt/boot/efi
mount /dev/sda2 /mnt/boot/efi

Context change: the next command enters the chroot, the installed system.

manjaro-chroot /mnt /bin/bash

On Arch the equivalent is arch-chroot. The prompt changes, and everything
until the exit in step 12 runs inside the installed system rather than the
live one.

Step 9 - install the EFI bootloader

Context: inside the chroot.

Nothing is installed here, since step 1 confirmed the packages are present.
That also means this works with no network inside the chroot.

grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=Manjaro

Rather than matching the success message, whose wording varies by version,
confirm it independently:

echo $?
ls /boot/efi/EFI/Manjaro/grubx64.efi

The echo must print 0 and the file must exist. A missing file means no
bootloader was written and there is nothing for the firmware to find.

Step 10 - add the ESP to fstab

Context: inside the chroot.

The swap line needs no change, its UUID was preserved. Only the ESP is new,
and the shell can fill in its UUID so nothing is transcribed.

E=$(blkid -s UUID -o value /dev/sda2)
echo "UUID=$E /boot/efi vfat umask=0077 0 2" >> /etc/fstab
tail -2 /etc/fstab

The tail must show a real UUID after UUID=, not an empty one.

Step 11 - regenerate

Context: inside the chroot.

grub-mkconfig -o /boot/grub/grub.cfg
mkinitcpio -P

If the system hibernates, check that a resume=UUID= parameter still exists
in the grub defaults and still names the swap UUID. Preserving that UUID in
step 7 is what keeps it valid.

Step 12 - leave and reboot

Context: starts inside the chroot.

Context change: exit returns to the live root shell.

exit
umount -R /mnt
reboot

The two commands after exit run in the live session, not in the chroot.
Remove the stick while the machine reboots.

Step 13 - firmware settings

Context: no shell, at the keyboard during POST.

Enter the firmware setup, disable CSM, and put the new entry first in the
boot order. Above 4G Decoding stops being greyed out once CSM is off, which
is what Resizable BAR needs, but leave that until the machine has booted
once successfully.

Step 14 - after the first boot

Context: the converted system, as the ordinary user.

ls /sys/firmware/efi >/dev/null && echo UEFI
findmnt /boot/efi
swapon --show

Expect the word UEFI, a mounted EFI partition, and swap slightly smaller
than before. Re-enable any backup job that was disabled in step 1, but only
once the filesystem looks right, since a mirroring job with a delete option
will happily propagate damage.

If it goes wrong

The firmware finds no bootloader and offers only its setup screen. Boot the
live stick in UEFI mode again and repeat steps 8 to 12. They are repeatable
and destroy nothing.

A black screen after disabling CSM means the graphics card has no UEFI GOP
in its video BIOS, which is common on older cards. Re-enter the setup and
turn CSM back on. Clearing CMOS is not a reliable remedy, because the
defaults on many boards have CSM off, which is the state being escaped.

Once the disk is GPT the legacy boot path is gone, so keep the live stick
available until the machine boots unaided.

Why in place rather than reinstalling

A reinstall is simpler to describe and takes longer to live with: every
package, every configuration file and every dotfile has to be restored
afterwards. The conversion touches two partitions worth of metadata, leaves
the root filesystem alone, and is reversible up to the formatting step. The
risk is concentrated in one gdisk session with an explicit abort, which is
easier to control than a day of reconstruction.