Step-by-Step Guide: Converting Linux Boot Disk from MBR to GPT with UEFI on Ubuntu 16.04


1 views

Before proceeding with the conversion, it's crucial to understand the difference between MBR (Master Boot Record) and GPT (GUID Partition Table). MBR has limitations like a maximum of 4 primary partitions and 2TB disk size support, while GPT supports up to 128 partitions and much larger disks. UEFI, the modern replacement for BIOS, works best with GPT.

  • A working Ubuntu 16.04 system with MBR partitioning
  • Backup of all important data (conversion carries risk)
  • Live USB/CD of Ubuntu (for emergency recovery)
  • Basic familiarity with terminal commands

Here's the step-by-step procedure to convert your disk from MBR to GPT:

# Install gdisk if not already installed
sudo apt-get install gdisk

# Verify current partition table
sudo fdisk -l /dev/sda

# Convert MBR to GPT using gdisk
sudo gdisk /dev/sda
# In gdisk interactive mode:
# Type 'x' for expert mode
# Type 'z' to zap (destroy) GPT data
# Type 'y' to proceed
# Type 'n' to create new GPT
# Type 'w' to write changes
# Type 'y' to confirm

After conversion, you'll need to create an EFI System Partition (ESP):

# Create new partition (500MB recommended)
sudo gdisk /dev/sda
# In gdisk:
# Type 'n' for new partition
# Set partition number (default is fine)
# Set first sector (default is fine)
# For last sector, type '+500M'
# Hex code: 'ef00' for EFI System
# Type 'w' to write changes

# Format the new partition
sudo mkfs.fat -F32 /dev/sda1

Now install GRUB for UEFI:

# Mount necessary partitions
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot/efi

# Chroot into your system
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
sudo chroot /mnt

# Install GRUB for UEFI
apt-get install --reinstall grub-efi-amd64
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck
update-grub

After reboot, enter your system's UEFI settings (typically by pressing F2, F12, or DEL during boot) and:

  1. Disable Legacy/CSM boot mode
  2. Enable UEFI boot mode
  3. Set Ubuntu as the default boot option
  4. Save changes and exit

To confirm successful conversion:

# Check partition table type
sudo parted -l | grep "Partition Table"

# Verify boot mode
ls /sys/firmware/efi

# Check GRUB installation
efibootmgr -v
  • If system fails to boot, use live USB to chroot and reinstall GRUB
  • Ensure ESP is mounted at /boot/efi in /etc/fstab
  • For dual-boot systems, Windows requires GPT for UEFI boot as well
  • Some older hardware might have UEFI implementation issues

Converting your Ubuntu system's boot disk from MBR (Master Boot Record) to GPT (GUID Partition Table) while enabling UEFI boot requires careful execution. This process involves both partition table conversion and bootloader reconfiguration.

  • Backup all important data (entire disk imaging recommended)
  • Ubuntu live USB/DVD (same or newer version than installed system)
  • Minimum 1MB free space at disk's start (for GPT headers)
  • Verify UEFI support in BIOS (look for "UEFI mode" option)

Insert your Ubuntu live media and boot in UEFI mode. You can verify this with:

[ -d /sys/firmware/efi ] && echo "UEFI boot" || echo "Legacy boot"

List all disks and identify your target disk (typically /dev/sda):

sudo fdisk -l
sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT

Use gdisk to convert from MBR to GPT (this preserves existing partitions):

sudo gdisk /dev/sda
# In gdisk interactive mode:
# Type 'r' for recovery/transformation
# Type 'g' to convert to GPT
# Type 'w' to write changes
# Type 'Y' to confirm

If your disk doesn't have an EFI System Partition (ESP):

sudo gdisk /dev/sda
# In gdisk:
# Type 'n' for new partition
# Choose default first sector
# Size: 512MB (recommended)
# Hex code: EF00 (EFI System)
# Type 'w' to write changes

# Format the new partition:
sudo mkfs.fat -F32 /dev/sda1

Mount your root partition and ESP, then reinstall GRUB:

sudo mount /dev/sda2 /mnt  # Replace with your root partition
sudo mount /dev/sda1 /mnt/boot/efi
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu
update-grub

After reboot, verify successful UEFI boot:

ls /sys/firmware/efi/efivars  # Should list EFI variables
sudo efibootmgr -v  # Should show Ubuntu entry
  • If GRUB installation fails, try: apt install --reinstall grub-efi-amd64
  • For dual-boot systems, ensure Windows is also in UEFI mode
  • Check BIOS boot order if system doesn't boot after conversion

For advanced users, here's a basic conversion script (use with caution):

#!/bin/bash
DISK="/dev/sda"
ESP_SIZE="512M"

# Convert to GPT
echo -e "r\ng\nw\nY\n" | sudo gdisk $DISK

# Create ESP
echo -e "n\n\n\n+$ESP_SIZE\nEF00\nw\nY\n" | sudo gdisk $DISK

# Format ESP
sudo mkfs.fat -F32 ${DISK}1

# Mount and reinstall GRUB (simplified)
sudo mount ${DISK}2 /mnt
sudo mount ${DISK}1 /mnt/boot/efi
for i in /dev /dev/pts /proc /sys; do sudo mount --bind $i /mnt$i; done
sudo chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu
sudo chroot /mnt update-grub