Gpt Fdisk For Mac

 

MBR and GPT are two popular partitions styles on Windows-based computers. They are standards for the layout of the storage device like an HDD (Hard Disk Drive) or SSD (Solid-State Drive). The partition style tells Windows how to access the data on the current disk and is decided when during the initialization of a disk. Thus, having a partition style is necessary for each disk in use. To decide which partitioning method to apply, you should first have a basic understanding of what MBR or GPT is.

GPT fdisk can identify, but not use data in, Apple Partition Map (APM) disks, which are used on 680x0- and PowerPC-based Macintoshes. Upon exiting with the 'w' option, gdisk replaces the MBR or disklabel with a GPT. This action is potentially dangerous! Command-line GUID partition table (GPT) manipulator for Linux and Unix Synopsis. Sgdisk options device Description. GPT fdisk is a text-mode menu-driven package for creation and manipulation of partition tables. It consists of two programs: the text-mode interactive gdisk and the command-line sgdisk. Either program will automatically.

PAGE CONTENT:
What Is MBR
What Is GPT
What's the Difference Between MBR and GPT
Is GPT or MBR Better
Does Windows 10 use GPT or MBR
How to Check the Partition Style of a Disk
How to Interconvert MBR and GPT

What Is MBR

MBR, Master Boot Record, is an older disk-type first introduced with IBM PC DOS 2.0 in 1983. It's named after the boot sector located at the very beginning of a drive (the first sector) called MBR. Here is a simplified structure of an MBR disk.

MBR Sector

The first sector on both an MBR disk and a GPT disk is the MBR sector. It takes up 512bytes and contains the master boot code (446bytes), disk partition table (DPT, 64bytes), and the boot signature (2bytes) which marks the end of the MBR sector. The information in this sector describes how the partitions are organized on the current storage device. Thus, when it's corrupted, you won't be able to use the disk until you rebuild MBR.

Partitions

To use a disk for data storage, you need to divide it into chunks called partitions. Partitions can be categorized as primary partitions and extended partitions on an MBR disk. Primary partitions are those you can install the operating system on and make active in order to boot the computer from it. Excluding the space taken by primary partitions, the space left on a disk is called an extended partition. Unlike a primary partition, an extended partition is a 'concrete' storage unit with a drive letter and file system. You can only use the extended partition to create multiple logical drives to utilize the space.

Since the disk partition table is 64bytes in total and the information of each partition is 16bytes, you can create at most four primary partitions. If you prefer more than four partitions on the disk, you should make one primary partition an extended partition to create logical partitions. (Within the extended partition, you can create multiple logical drives.)

The most obvious disadvantage of an MBR disk is that it only works with a maximum size of 2TiB(≈2.2TB) on a disk. That means if you have a disk larger than 2TiB with the MBR partition style, you can only use at most 2TiB space on it.

What Is GPT

GPT, GUID Partition Table, is the newer standard compared to MBR first introduced as part of the UEFI initiative. Compared with the MBR partitioning scheme, it's more flexible and has better compatibility with modern hardware.

Protective MBR

The first sector on a GPT disk is also the MBR sector. Different from the one on an MBR disk, the protective MBR on a GPT disk serves the function of preventing tools that only supports MBR disks from misrecognizing and overwriting GPT disks.

Primary GPT Header

The second sector on a GPT disk stores the primary GUID partition table header. It defines the location and size of the partition entries that consist of the partition table and the cyclic redundancy check (CRC32) checksum that is used to verify the integrity of the GPT header. When CRC detects data corruption, it will attempt to recover the data using the backups stored at the end of the disk.

Partition Entries

From the third sector to the thirty-fourth sector (32 sectors in total) are the partitions entries. Theoretically, you can create unlimited partitions on a GPT disk. However, the number of the partition you are able to create will be limited by the operating system. For example, under Windows, each partition entry is 128bytes, thus, you can create a maximum number of 128 (32*512/128=128) partitions under Windows. This is what differs a GTP disk from an MBR disk remarkably.

Partitions

There is no extended partition or logical partitions on a GPT disk since there are no limits on how many primary partitions you can create.

Backup Partition Entries/Primary GPT Header

GPT disks back up the primary GPT header and the partition entries automatically on the last sectors on the disk. That's why GPT disks are safer and more reliable than MBR disks. When the GPT header or partition table is corrupted, these backups will be helpful to restore the data.

What's the Difference Between MBR and GPT

The difference in the structure of MBR and GPT decides they will differ in other aspects. Based on the structure and technique, an MBR disk and a GPT disk mainly vary in the supported boot mode and compatible operating systems.

Boot Mode

It's certainly true that almost all the computers running Windows boot up using one of the two ways, BIOS-MBR method or UEFI-GPT method. This indicates that an MBR disk only supports the legacy BIOS (Basic Input/Output System) mode and a GPT disk UEFI (Unified Extensible Firmware Interface) mode.

Both BIOS and UEFI are essentially low-level software that starts when you power on your PC. BIOS is the more traditional way and UEFI the newer.

The Boot Process of BIOS:

  • Powers on
  • Power-on self-test (POST)
  • Loads BIOS
  • Identifies the boot device
  • BIOS detects the code stored in the MBR sector
  • The MBR loads code from the boot sector of the active partition
  • The boot sector loads and runs the bootloader

The Boot Process of UEFI:

  • Powers on
  • The boot manager in UEFI checks the boot configuration
  • The boot manager loads into memory and executes the OS loader or OS kernel

The Advantages of UEFI-GPT over BIOS-MBR

The limits of the BIOS-MBR method promotes the appearance of the UEFI-GPT method. Due to BIOS's MBR sector boot process, you can only boot from drives at most 2TiB in size. Besides, you will get a slower boot process using BIOS. Here are the benefits of UEFI:

  • Better compatibility with big hard drives (larger than 2TiB)
  • The support of more than four primary partitions
  • Faster boot time
  • Better graphics and mouse cursor support in the interface

Supported OS

In addition to the boot method, MBR disks and GPT disks also vary in the operating system supported. As mentioned, GPT is a newer partition scheme, which means there may be an incompatibility with old operating systems. Actually, except for 32-bite Windows XP and Windows Server 2003 editions, all versions of Windows, like Windows 10/8.1/7/XP/Vista, can read and write GPT disks. However, to boot from the GPT disk, you need UEFI-based PCs. Similarly, almost all the Windows editions can read and write MBR disks. To boot from an MBR disk, ensure the motherboard in the computer is BIOS or UEFI with BIOS mode.

Is GPT or MBR Better

MBR is the traditional partition table that supports older operating systems, while GPT is a new replacement that doesn't have limits on the disk size and number of partitions you can create. To decide which partitioning scheme to choose, you should have an overall understanding of the merits and drawbacks of it in mind.

The Advantages of GPT over MBR

  • Supports hard drives larger than 2TiB
  • Allows to create theoretically unlimited partitions
  • Contains cyclic redundancy check to check the integrity of its data
  • Contains the backup of the primary GPT header and partition entries that protects data on the disk better

The Advantages of MBR over GPT

Due to its history, MBR disks work with most of the Windows editions, especially the older versions.

Given that, to determine is GPT or MBR better should base on your needs and the hardware you have. For example, if you prefer faster boot time, using a GPT disk as the system disk is advisable; if your computer is BIOS-based, choose MBR for the system disk instead; while if you use a disk under 2TB for data storage, both GPT and MBR are OK.

Does Windows 10 use GPT or MBR

Can Windows install on MBR partition? Can Windows 10 install on GPT? Of course, you can. Windows 10 uses both GPT and MBR disks. Windows 10 can be installed on both MBR and GPT, depending on the firmware of your computer. If your computer has BIOS firmware, you can only install Windows 10 on an MBR disk. If your computer firmware is UEFI-based, you can only install Windows 10 on a GPT disk. If your computer has UEFI firmware with BIOS-compatibility, you can install Windows 10 on either an MBR or GPT disk. If you attempt to install Windows on a GPT disk on a UEFI-based computer, you will receive the error 'Windows cannot be installed to this disk. The selected disk is of the GPT partition style.' Similarly, you will see the error prompt saying 'The selected disk has an MBR partition table' if you try to install Windows on an MBR disk on a BIOS-based computer.

How Can I Covert A MBR To GPT Partition M… - Apple Community

How to Check the Partition Style of a Disk

Under Windows Disk Management, you can check the partitioning scheme of a hard drive:

Step 1. Right-click 'This PC' and choose 'Manage'.

Step 2. Go to 'Disk Management'.

Step 3. Right-click the disk you want to check and choose 'Properties'.

Step 4. Go to the 'Volumes' tab and you will see the partition style under the disk information.

How to Interconvert MBR and GPT

You may need to convert an MBR disk to a GPT disk or vice versa. For example, if you have a disk larger than 2TiB that is currently using the MBR partition style. To use all the storage space on it, you need to convert it to GPT. You can convert a data disk freely between MBR and GPT. If you attempt to convert the system disk, make sure your computer is equipped with the corresponding firmware, namely BIOS for MBR and UEFI for GPT, or you will encounter boot issues.
To change MBR to GPT or GPT to MBR without erasing the data on the disk, The partition tool - EaseUS Partition Master will help:

Step 1. Download and launch EaseUS Partition Master on your Windows computer.

Step 2. Right-click the MBR disk that you want to convert and choose 'Convert to GPT'.

Step 3. After that, find and click the 'Execute 1 Operation' button on the toolbar and choose 'Apply' to start the conversion. You need to restart your device to enable this change.

The Bottom Line

Now you should have a basic understanding of the MBR and GPT partitioning scheme. With the information in mind, you could make a better decision the next time you initialize a disk or choose a computer.

I decided it was time I became familiar with the nuts and bolts of how disks on Macs are partitioned by Disk Utility, and why.

After reading up on MBR, GPT, and how they compare, I assembled these tools:

  • Disk Utility: the “new” version, as shipped with each version of OS X/macOS
  • Disk Utility: the “original” (or “good”) version, patched so it’ll still run on OS X 10.11
  • diskutil: Apple’s official disk management tool
  • gpt: the FreeBSD tool for GPT disks, shipped with macOS
  • fdisk: a much older tool for MBR disks, also shipped with macOS
  • gdisk: a newer fdisk-based tool for GPT disks
    • installable via Homebrew with brew install gptfdisk

Partition tables, partition tables everywhere

For reference, my internal HFS+ drive according to diskutil:

Here we clearly see the internal drive is GPT with a 200MB EFI system partition (ESP), a Core Storage partition containing the boot volume, and a recovery partition. (Run diskutil cs list for a better view of how Core Storage volumes are structured.)

The same drive according to gpt:

The gpt tool shows everything, and counts according to 512-byte sectors. The protective MBR occupies one 512-byte sector, the GPT header occupies the next sector, and the partition table entries follow. Then at sector 34 there’s a 3KB gap so that the first partition starts on a 4KB boundary (i.e. 20KB from the start of the disk). The ESP is 409600 sectors * 512 bytes per sector / 1024 bytes per KB / 1024 KB per MB = 200MB. Then our remaining partitions, another boundary alignment gap, and the secondary GPT table and header.

Gpt Fdisk For Mac

This follows the behaviour described in Secrets of the GPT. If you’ve read that and are wondering why there are no 128MB gaps after each non-ESP partition, note the article doesn’t mention that those gaps are only added after HFS+ partitions when defined directly within the partition table, and not when encapsulated within a Core Storage logical volume group.

For example, an 8GB USB drive partitioned with original Disk Utility to use GPT for two HFS+ partitions looks like:

Note the 128MB gap after the first partition, and the 128MB + 7 sector gap after the second. This gap is slightly larger because making the end of the second HFS+ partition align to the next 4KB boundary (8 sectors later) would have made the gap one sector short of 128MB.

But if we repartition so the first is FAT:

we get:

…a just-under 1MB gap before the FAT volume, but not after. This is OS X following Windows’ practice of aligning partitions it creates on 1MB boundaries for disks over 4GB, which translates to the location of the partition’s first sector (411648) being divisible by 2048. (Note that OS X does this for all disk sizes rather than on 64KB/128 sector boundaries for smaller disks, as Windows does.)

As for that “suspicious MBR”, we can use fdisk to read its master boot record partition table:

Aha: the presence of a FAT partition made Disk Utility create a hybrid MBR. This would in theory allow the disk to mount on older systems that don’t support GPT.

  • #1 covers everything from the start of the disk to the end of the ESP and is marked as part of the protective MBR (EE)
  • #2 is the FAT (0B) partition
  • #3 is the HFS+ (AF) partition

As the linked article explains, hybrid MBRs can be a dangerous hack, and Windows XP can’t actually mount this disk as-is unless the hybrid MBR table is reordered with gdisk to list any mountable partitions before the EE partition. (Otherwise you’ll be told “this partition is not enabled” when assigning a drive letter in Disk Management, and reformatting what shows in My Computer will wipe out the primary GPT structures and the ESP in favour of a 200MB FAT volume!)

The protective MBR that Disk Utility usually creates on disks (meant to actively deter non-GPT-aware disk utilities from thinking the disk is unformatted) looks like this:

where the sole EE partition covers the entire disk.

And if we reformat our 8GB USB drive as GPT with HFS+ and then FAT:

The gap between #2 and #3 is 262144 sectors trailing the HFS+ partition (the 128MB gap mentioned above) plus 2008 sectors leading the FAT partition so it starts on a megabyte boundary. Also note the 2015 sector trailing gap, which wasn’t present when FAT came first. This gives the FAT partition a size that also ends on a megabyte boundary.

And if we use HFS+ followed instead by ExFAT, do we get the same gap and hybrid MBR?

Here, the gap between #2 and #3 is 262144 sectors (128MB) trailing the HFS+ partition plus 440 sectors leading the ExFAT partition (a 1MB boundary gap, as before), and 2015 sectors trailing it. And “Suspicious MBR” indicates the presence of a hybrid MBR.

Further down the MBR rabbit hole

Having gone this far, we may as well keep digging. Using the original Disk Utility, I’ll format the same 8GB drive as MBR with a variety of partitions.

Note that:

  • diskutil refers to MBR as FDisk_partition_scheme
  • both standard and case-sensitive HFS+ are Apple_HFS
  • FAT is marked as DOS_FAT_32 (so presumably it’s not FAT12 or FAT16)
  • ExFAT is marked as Windows_NTFS (what???)
  • all four partitions were supposed to be 2GB, but the last got shorted by a few hundred MB because of the 128MB trailing gap for each HFS+ partition, which diskutil includes in their total sizes

Where is diskutil getting the partition type info? Presumably from the MBR partition type IDs. Can we see those directly?

Neat, gpt can read MBR tables. And it does show partition IDs, but in decimal for some reason.

  • first sector is the MBR
  • second sector is the (unlabelled) EBR which points to the final partition (see below)
  • then our HFS+ and case-sensitive HFS+ partitions with just a 1-sector boundary after each, because 128MB gaps are only added on GPT disks (175 0xAF)
  • then our FAT/ExFAT partitions (11 0x0B)

To see both the MBR and EBR contents, use fdisk:

This lets us see the actual hex value partition type IDs in the MBR that Disk Utility chose to assign.

  • AF is HFS or HFS+
  • 0B is FAT32 with CHS addressing (instead of the newer 0C for LBA addressing; I’m guessing this is for max backwards compatibility)
  • 05 is the EBR, covering everything past the third partition

And then in the extended partition table:

  • 07 is ambiguous — it could be IFS, HPFS, NTFS, ExFAT, or old QNX. And now we know why diskutil just shows the last partition as Windows_NTFS, because it can’t tell which it actually is without reading the partition’s data itself.

What does gdisk say?

What a weird message. Is it detecting an old secondary GPT table at the end of the disk, making it think it should still be GPT? This would cause it to think there’s partition overlap even though the disk isn’t GPT at all. And the last two partitions are labelled the same because gdisk is translating the MBR type IDs to their GPT equivalents, which are the same for FAT and ExFAT.

Once more time, with GPT

And now we’ll repartition with the same volume types, but with GPT instead.

Note:

  • addition of the standard 200MB ESP
  • both the standard and case-sensitive HFS+ partitions have the same label
  • FAT and ExFAT partitions are both labelled “Microsoft Basic Data”

Note:

  • we still have a hybrid MBR
  • only the HFS+ partitions have a trailing 128MB gap
  • the second HFS+ partition’s trailing gap is 1696 sectors larger than it needs to be so that the FAT partition that follows starts on a 1MB (2048-sector) boundary
  • the full GPT GUIDs are:
    • C12A7328-F81F-11D2-BA4B-00A0C93EC93B - ESP
    • 48465300-0000-11AA-AA11-00306543ECAC - HFS+
    • EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 - Microsoft Basic Data, which could equal MBR type IDs 06, 07, 0B, 01, 04, 0C, 0E

This hybrid MBR only lists the first four partitions, leaving out the ExFAT one entirely.

Nothing special here, except to note that this Disk Utility has set each partition’s GPT label, which is distinct from its name that shows in Finder and is not set by the new Disk Utility (except for “EFI System Partition”).

By the way, I also ran through the above exercises with a 250GB spinning disk without seeing any changes in behaviour.

So, with original Disk Utility:

  • 128MB gaps are only created after HFS+ partitions, and not for EF (ESP), AF05 (Apple Core Storage), or AB00 (Recovery HD) partitions
  • the presence of a FAT or ExFAT partition on a GPT disk has it create a hybrid MBR for the first four partitions, including the ESP
  • FAT and ExFAT partitions get leading gaps so they start on a 1MB boundary, plus a trailing gap if it’s the last partition on the disk

Trying out the new Disk Utility because we have to

The rewritten Disk Utility that shipped with OS X 10.11 is buggy and underpowered, i.e. changing the partition map only lets you create one volume, and because “free space” is not an option, creating custom-sized and -formatted disk partitions is only possible if you format it as HFS+ first, then click [Partition] to add and change partitions. Even then it won’t let you reduce the first to less than 5.4GB, and disks smaller than that can’t be repartitioned at all.

macOS 10.12

Maybe some of its bugs were fixed with the release of macOS 10.12 Sierra, but I still found it not respecting requested partition sizes, not seeing newly inserted disks without a relaunch, not being able to erase a disk on the first attempt, and so on.

Anyway, let’s see how it behaves with formatting a USB drive as GPT with HFS+, FAT, and ExFAT.

Note the uneven partition sizes. I had to reformat as GPT+HFS, then split the last third of the disk twice because of the arbitrary limitation on shrinking the first partition.

If you check Disk Utility’s output as it does its repartitioning, you’ll see it shrinks the initial HFS+ partition, creates a new 2GB HFS+ partition in the empty space, then shrinks that partition to 1GB and creates a third HFS+ partition; only then does it reformat the latter two volumes as FAT and ExFAT. This behaviour may be a factor in why I was seeing inconsistent results. On this drive only the HFS+ partition has its 128MB trailing gap, but on other drives that same gap would still be there after the FAT or ExFAT partitions. Also note that it didn’t align those two partitions on 1MB boundaries, as the original Disk Utility would.

But, it’s still creating a hybrid MBR.

macOS 10.13

Can macOS High Sierra do any better? I found that Disk Utility’s worst interface quirks had been resolved at this point.

For example, in 10.12 while erasing a drive as GPT+FAT, the dialog failed to convert the default disk name “Untitled” to uppercase, resulting in the volume just being named “U”. The 10.13 version now auto-uppercases text in the Erase dialog, although it still doesn’t in the Partition dialog, which can lead to failure if anything other than uppercase letters are in your FAT volume’s name. (This can happen even if you set a name with lowercase, tab out of the field, and then uppercase the name, because Disk Utility will inexplicably use the first name you typed when it does the partitioning, and then update the volume name at the end of the process.)

Gpt Fdisk For Mac Os X

It also now allows repartitioning 4GB and smaller drives. Just remember to select View > Show All Devices to see more than just formatted volumes.

You can see that Disk Utility isn’t bothering to reclaim the 128MB gap left over from when each partition was formatted as HFS+. It is at least adjusting the start and end sectors for FAT and ExFAT partitions to align on 1MB boundaries again. Also note that it’s no longer creating a hybrid MBR.

A similar quirk comes up if you erase a disk as GPT+(Ex)FAT, it’ll add a leading 1MB boundary gap (and won’t format as HFS+ first!):

If you then use Partition to change it to HFS+, or select just the volume and use Erase (and so not rewrite the partition table):

it’ll add a trailing 128MB gap, but won’t reclaim that leading gap.

And of course, as of 10.13 we can create APFS volumes, which always require GPT and are actually containers for sub-partitions that all draw from the same storage pool. This is how a 4GB USB drive with a single APFS container shows up. (Another bug: after formatting, Disk Utility displayed the drive as two separate devices, but after an unplug/replug it displayed properly as SanDisk > Container disk3 > apfs.)

Note how an APFS disk takes up two /dev entries.

No trailing gap for APFS containers, just enough to align on 4KB blocks. And still no hybrid MBR, obviously.

My testing on macOS 10.14 didn’t find any changes in how its Disk Utility formats disks. I did dig up some more bugs in its interface though, which I’ve filed with Apple. If any bugfixes or other significant changes surface in Disk Utility with macOS 10.15 I’ll update this post.