47

NOTE: I don't know a lot about hard drives so you're going to have to work with me here.

My question: Can I change my hard drive from GPT to MBR without losing data on it?

NOTE: there isn't an operating system on the laptop which I'm going to do this on. I'm going to boot from a USB and try to convert it.

9
  • 5
    You have to assume that data will be lost, so take a back-up first.
    – AFH
    Commented Sep 16, 2017 at 11:51
  • 1
    @AFH how can I make a back up if I can't boot the laptop ? Commented Sep 16, 2017 at 11:53
  • Converting is not possible. You have to remove the partition and create a new one. GPT is superior to MBR though, so I would keep GPT. One of the limits of MBR is the maximum size a partition can be. I believe 2 TB is its limit.
    – LPChip
    Commented Sep 16, 2017 at 11:56
  • 2
    It's true that GPT is superior to MBR, therefore many partition layouts cannot be converted to MBR; but some layouts can. Post the result of Linux command gdisk -l /dev/sdX (substitute sdX with your HDD) so we can tell more. Commented Sep 16, 2017 at 18:24
  • 2
    Why do you want to do this conversion? It may not be necessary, and in fact may be quite inadvisable. OTOH, there are some legitimate reasons to want to do this (such as if you want to use the disk with a GPT-unaware OS).
    – Rod Smith
    Commented Sep 24, 2017 at 14:01

3 Answers 3

66

You can convert from GPT to MBR and MBR to GPT without data loss (I have tried that) with gdisk in Linux.

Use at your own risk

Run command gdisk /dev/sdx with sdx as per your HDD partition

GPT fdisk (gdisk) version 1.0.1

Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format.
THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if
you don't want to convert your MBR partitions to GPT format!
***************************************************************


Command (? for help): 

MBR to GPT

Enter w to write GPT partition on disk.

Press y to confirm your choice.

GPT to MBR

Enter r to enter in recovery and transformation options.

Enter g to convert GPT to MBR partition.

For Information

You can check table by command p.

Warning: You will lose your boot loader (Ex. GRUB)

You can check if your partition is GPT or MBR now gdisk /dev/sdx with sdx as per your HDD partition in Partition table scan(p)

8
  • 5
    For more on this subject, see the official GPT fdisk documentation on such conversions.
    – Rod Smith
    Commented Sep 24, 2017 at 13:57
  • Something's not right. In gdisk recovery and transformation options the g option will only recreate the protective MBR on top of the GPT but not actually convert the disk to GPT. The right way to convert a GPT disk to MBR is using fdisk o option but it does destroy data on the disk. Commented Oct 18, 2019 at 14:06
  • 1
    I observed this behaviour with gdisk v1.0.3 and fdisk from util-linux 2.33.1 when I was trying to convert an empty GPT disk (no partitions) to MBR Commented Oct 18, 2019 at 14:17
  • 1
    This successfully converted my disk back to MBR but did not mark the Windows partition as Active and the disk was not bootable. I ended up using DISM to clone the Windows partition after doing a fresh install to restore the structure of the disk while preserving data. Commented Aug 22, 2022 at 20:21
  • 1
    After this r -> g command, you still need to use w to write and quit. Until then, it seems nothing has happened yet (verify in another terminal with e.g. fdisk -l /dev/sdx).
    – Luc
    Commented May 6, 2023 at 23:56
12

Making your drive bootable

This is an enhancement to the information provided by Krunal and clarkttfu with more details on the steps to create a BIOS boot partition and install grub to it.

If you are changing the partition table on a a boot drive you will need to create a new "BIOS boot partition" for grub to store the bootloader in. These examples use the drive /dev/sda which will usually be the boot drive.

First, validate that there is space before the current first partition to support a boot partition, fisk -l should show that the first partition starts at sector 2048:

johnf@ubuntu:~$ sudo fdisk -l /dev/sda
[...]
Device     Boot  Start       End   Sectors  Size Id Type
/dev/sda1  *      2048    499711    497664  243M 83 Linux
/dev/sda2       501758 125829119 125327362 59.8G  5 Extended
/dev/sda5       501760 125829119 125327360 59.8G 8e Linux LVM

If it does then you have the space required to create the partition. If it doesn't you cannot follow these instructions and have a bootable system.

Use gdisk to convert the partition to gpt, you can now create a new partition for your MBR, run sudo gdisk /dev/sd, enter n to create a new partition, accept the proposed partition number, you should be able to select a first sector of 34, set the partition type of ef02:

Command (? for help): n
Partition number (2-128, default 2):
First sector (34-4294967262, default = 4294922240) or {+-}size{KMGTP}: 34
Last sector (34-2047, default = 2047) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): ef02
Changed type of partition to 'BIOS boot partition'

You can now write your partition table with w. Run partprobe again and then install grub:

johnf@ubuntu:~$ sudo partprobe
johnf@ubuntu:~$ sudo grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.

You should now be able to reboot your machine without issue.

2
  • It didn't work on ubuntu 20.04. When I use gdisk to write new boot partition, GPT is restored. Any way to create boot partition without losing MBR again?
    – Blazeag
    Commented Nov 30, 2020 at 14:06
  • works for me on 18.04 Commented Jan 1, 2021 at 14:45
2

As Krunal said, gdisk will ruin your grub, to avoid rescue mode:

If boot from BIOS, you'd better create a BIOS boot partition before you write and quit gdisk. (Otherwise a EFI partition is required if boot from UEFI).

And you grub-install /dev/sda to fix your bootloader then reboot and good luck.

i.e. I used the 2048 sectors between sda1 and sda5, exactly 1MB for BIOS boot partition:

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          999423   487.0 MiB   8300  Linux filesystem
   5         1001472        41940991   19.5 GiB    8E00  Linux LVM

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .