19

I am running Ubuntu 13.10. Some links shows that:

  • If you use an MS-DOS partition table (or MBR), you can only have up to four primary/extended partitions.

  • If you use a GUID partition table (GPT) with default settings, you can have up to 128 partitions.

How do I find out whether my disk uses MBR or GPT from the terminal in Ubuntu?.

So that it would be easy for me while creating partitions.

  • The easiest way is to use blkid. See this answer. – mivk Jun 18 at 12:35
22

To find whether your disk is GPT or MBR in ubuntu,you have to install gdisk utility.

sudo apt-get install gdisk

Then run the below command,

sudo gdisk -l /dev/sda
  • If the output of the above command shows like this,then you have MBR disk,

    Partition table scan:
    MBR: MBR only
    BSD: not present
    APM: not present
    GPT: not present
    
  • If the output shows like this then you have GPT disk,

    Partition table scan:
    MBR: protective
    BSD: not present
    APM: not present
    GPT: present
    
14

Using parted Install parted

You can use this command, replace /dev/sda with your device:

parted /dev/sda print | grep -i '^Partition Table'

You may need to install it first:

sudo apt-get install parted

Example output for an MBR disk:

Partition Table: msdos

Using gdisk Install gdisk

Install it first:

sudo apt-get install gdisk

Then, you can use this command, replace /dev/sda with your device:

gdisk -l /dev/sda | grep -A4 '^Partition table scan:'

Example output for an Mbr disk:

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

Using fdisk

Run this command, replacing /dev/sda with your device:

fdisk -l /dev/sda

It will show a warning if the device uses GPT:

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

No need to install anything:

sudo ls                              # Prevent hang
sudo fdisk -l | grep -B 5 Disklabel  # Focus
  • 1
    On ubuntu 18 this was the only answer that worked for me - trying to do fdisk -l /dev/sda would lead to errors about such a directory not existing, even though I can see it in /dev/ – Caleb Jay Jun 4 at 3:24
2

The accepted answer should be updated:

fdisk -l /dev/sdb
Disk /dev/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 6C5ED23-xxxxxxx

As you can see, fdisk now shows Disklabel type: gpt without needing to parse error messages.

time fdisk: real 0m0.004s

time parted: real 0m0.413s

100x slower for parted.

I was researching this for another application that needed this data, so I'm just updating the slightly out of date fdisk information. Also because when one program is 100x faster than another, it's usually worth taking a closer look at it in general.

I don't know which version of fdisk brought in this change.

The above is: 2.30.2

I found one in an older systems that shows gpt error, versions 2.20.1, but I don't know which specific fdisk version corrected this issue.

Note that the gpt error is going to stderr, so if you were sending errors to 2>/dev/null you'd miss that message.

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.