12

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

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

Note that 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.

  • 1
    You have to assume that data will be lost, so take a back-up first. – AFH Sep 16 '17 at 11:51
  • @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. – Biswapriyo Sep 16 '17 at 12:36
13

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)

  • 1
    For more on this subject, see the official GPT fdisk documentation on such conversions. – 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 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 at 14:17
0

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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.