34

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.

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

5 Answers 5

36

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
    
1
  • No longer works! Instead, use sudo fdisk -l /dev/sda Jan 4, 2021 at 3:07
23

Using 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 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 you Disklabel type as gpt.

Disk /dev/sda: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 870 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 8B1E6FC4-F381-4A16-A27C-1AE1F0ACECFF
9

No need to install anything:

sudo ls                              # Prevent hang
sudo fdisk -l | grep -B 5 Disklabel  # Focus
1
  • 2
    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, 2019 at 3:24
5

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.

0

lshw -C disks

you'll get something like:

-disk:1
                   description: ATA Disk
                   product: CT250MX500SSD1
                   physical id: 0.19.0
                   bus info: scsi@0:0.25.0
                   logical name: /dev/sdb
                   version: 023
                   serial: 2026E2B08C85
                   size: 232GiB (250GB)
                   capacity: 232GiB (250GB)
                   capabilities: gpt-1.00 partitioned partitioned:gpt
                   configuration: ansiversion=6 guid=38547a1a-38b4-4205-bb0a-d90f6103b76a logicalsectorsize=512 sectorsize=4096

See line: capabilities: gpt-1.00 partitioned partitioned:gpt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .