41

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.

slm
  • 9,959
  • 10
  • 49
  • 57
Mahmood Darwish
  • 533
  • 1
  • 4
  • 9
  • 4
    You have to assume that data will be lost, so take a back-up first. – AFH Sep 16 '17 at 11:51
  • 1
    @AFH how can I make a back up if I can't boot the laptop ? – Mahmood Darwish Sep 16 '17 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 Sep 16 '17 at 11:56
  • If you boot a diagnostic disc or a Linux Live system, then you can back up from there. – AFH Sep 16 '17 at 11:56
  • Yes that's possible. But you have to delete the OS partition to proceed. Use any bootable partition manager e.g. [link](http://getintopc.com/softwares/utilities/minitool-partition-wizard-technician-9-1-bootable-iso-download/). – Biswapriyo Sep 16 '17 at 12:36
  • 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. – Kamil Maciorowski Sep 16 '17 at 18:24
  • Also: are you going to boot OS from this HDD? – Kamil Maciorowski Sep 17 '17 at 06:44
  • 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 Sep 24 '17 at 14:01
  • https://serverfault.com/questions/963178/how-do-i-convert-my-linux-disk-from-mbr-to-gpt-with-uefi – sancho.s ReinstateMonicaCellio Feb 12 '21 at 04:43

3 Answers3

59

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)

Krunal Mevada
  • 706
  • 6
  • 5
  • 5
    For more on this subject, see the [official GPT fdisk documentation on such conversions.](http://www.rodsbooks.com/gdisk/mbr2gpt.html) – Rod Smith Sep 24 '17 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. – ManSamVampire Oct 18 '19 at 14:06
  • 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 – ManSamVampire Oct 18 '19 at 14:17
  • "Converting" MBR to GPT this way (from a terminal in GParted or some other live distro) is good enough to get Windows 10 to install in UEFI mode, so even if it's not 100% right it's just what I need. (I care about keeping data because I dumped the disk structure from an old machine using Clonezilla and then am putting the new Win 10 in unallocated space.) – Will Matheson Jan 22 '20 at 20:41
  • Should I use `gdisk` when it is saying `THIS OPERATION IS POTENTIALLY DESTRUCTIVE!`? – amrezzd Jul 31 '20 at 18:00
  • It worked for me too without data loss. Although it warned me multiple times about probability of data loss. thanks – aghArdeshir Mar 15 '21 at 00:18
  • 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. – duct_tape_coder Aug 22 '22 at 20:21
  • 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 May 06 '23 at 23:56
9

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.

johnf
  • 211
  • 2
  • 2
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
phuclv
  • 26,555
  • 15
  • 113
  • 235
clarkttfu
  • 141
  • 3