How can I detect whether my disk is using GPT or MBR from a terminal?
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
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 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.
No need to install anything:
sudo ls # Prevent hang
sudo fdisk -l | grep -B 5 Disklabel # Focus
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.