GPT - property of a disk drive or of a partition table?

1

I always thought that GPT is the way how you write partition table to a disk and you're free to do it however you like. But when I called

fdisk -l

for my external drive (connected through USB-port), where all partitions were deleted, it showed the warning

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.

Disk /dev/sdb: 500.1 GB, 500074283008 bytes
255 heads, 63 sectors/track, 60797 cylinders, total 976707584 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1   976707583   488353791+  ee  GPT

As you can see it shows System = GPT. I thought: OK, may be when I was playing with partitions, I did not fully delete the GPT partition from /dev/sdb. So I created a new MBR partition using fdisk (fdisk said "Partition 1 of type Linux and of size 465.7 GiB is set"), called fdisk -l again and got

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.

Disk /dev/sdb: 500.1 GB, 500074283008 bytes
60 heads, 62 sectors/track, 262555 cylinders, total 976707584 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   976707583   488352768   83  Linux

And this is what I do not understand. fdisk has created an old-style non-GPT partition, but still considers the drive to be of GPT type.

What does that mean? Does that mean that GPT is also some property of the disk hardware?

linux
partitioning
gpt
fdisk
guid
asked on Super User Jun 5, 2017 by John Smith

1 Answer

1

In this context, the Master Boot Record (MBR) and GUID Partition Table (GPT) are two different types of partition tables -- data structures that hold partitioning information -- that can be stored on disks. ("MBR" can also be used in reference to BIOS-mode boot loaders or to the first sector on the disk, but these meanings aren't relevant to your question.) Much of your question relates to the layout of data used by MBR vs. GPT:

  • MBR uses the first sector of the disk and, if extended and logical partitions are present, additional sectors that can be just about anywhere on the disk.
  • GPT uses the first 34 sectors of the disk and the final 33 sectors of the disk (assuming 512-byte sectors and default partition table sizes; the number of sectors used can vary if these assumptions aren't met).

Thus, GPT uses much more of the disk than MBR (but still a trivial amount of disk space compared to a modern disk's total capacity), and GPT uses the MBR's critical first sector. For this reason, part of GPT is a protective MBR, which looks much like a regular MBR; but the protective MBR consists of a single type-0xEE partition that covers the entire disk or 2TiB of it, whichever is smaller. The idea of the protective MBR is to make GPT-unaware tools think that the entire disk is in use, in order to deter accidentally trashing the disk with an older MBR-only partitioning tool.

The version of Linux fdisk that you used isn't quite GPT-unaware -- it knows enough to look for GPT data structures and warn you when it finds them. It's not GPT-aware enough to accurately report the GPT data structures, though, just the protective MBR. Newer versions of fdisk can handle GPT disks in a more thorough manner. So can other tools, like libparted (the core of parted, GParted, and some other tools) and my own GPT fdisk (gdisk, sgdisk, and cgdisk).

You started out with a GPT disk. You then deleted the partitions from the disk; but this did not delete the GPT data structures -- it just created data structures that identified the disk as empty. Because fdisk doesn't understand GPT data structures, it can't tell the difference between a disk filled with valid GPT partitions and one with GPT data structures but no partitions defined. Using fdisk to create a new MBR then replaced the GPT's protective MBR with an MBR that defines (in your case) a single Linux partition. Note, however, that this left 66 sectors of the GPT data structures intact. (33 of those sectors are at the end of the partition you defined, though, so they might be overwritten with filesystem data structures or with file contents.) Because fdisk looks for these GPT data structures, it continues to complain about GPT being detected.

When converting from GPT to MBR, it's better to use something based on libparted; this tool knows enough to blank out the old GPT data structures. Alternatively, you could use my gdisk, which will convert the MBR data structures into GPT equivalents. The old fdisk you used obviously does not do this. (I don't know offhand what the newer fdisk versions do.) Windows' tools, like the old fdisk, leave old GPT data behind.

Currently, your disk is technically a legal MBR disk. Some tools, though, will complain about it, as fdisk does. My gdisk will ask whether you want to treat it as MBR or GPT. This is intended to aid in recovery should somebody accidentally wipe out a protective MBR; but it could cause problems if you don't know what you're doing. Some other tools might misbehave in unknown ways. To avoid problems, you might consider using my fixparts on the disk. This program is installed in the gdisk or gptfdisk package in most Linux distributions, and it can wipe the unwanted GPT data structures. There is one important caveat, though: Because your new partition overlaps the end-of-disk GPT data structures, fixparts will erase within the partition, which could cause file or filesystem damage, if you're unlucky. A better choice might be to shrink the filesystem (by as few as 33 sectors) from the end and then run fixparts on it.

Unless you have a compelling reason to use MBR, I recommend using GPT these days. Older OSes, like DOS and Windows XP, require MBR, but most or all modern OSes, including Windows 7 and later, any even remotely-current Linux, most or all current BSDs, and any OS X/macOS that runs on Intel-based Macs, support GPT. GPT has modest advantages over MBR, such as backup data structures, checksums to detect errors, and named partitions. Converting from GPT to MBR as you've done has revealed the fact that making that switch can cause problems, or at least confusion. Of course, for maximum compatibility, MBR is superior, and this may be important on some removable media; but as a general rule, GPT is the superior partition table.

answered on Super User Jun 10, 2017 by Rod Smith

User contributions licensed under CC BY-SA 3.0