Skip to main content
update answer
Source Link
mivk
  • 3.9k
  • 1
  • 37
  • 34

You can use blkid


NB: in 2021. But you may need to run it as root or as you may need to run blkid as root for accurate information to be returnedsudo blkid.


 

Examples with output:

# blkid /dev/sdc /dev/sdc: PTUUID="92f03b9b-7402-4ad2-8316-08a991c237b3" PTTYPE="gpt" # blkid -o export /dev/sdc DEVNAME=/dev/sdc PTUUID=92f03b9b-7402-4ad2-8316-08a991c237b3 PTTYPE=gpt 

Or in a script, with the -o value option :

disk=$1 part_type=$(blkid -o value -s PTTYPE $disk) case $part_type in gpt) echo "GPT";; dos) echo "MBR";; *) echo "partition is $part_type";; esac 

Alternatively as a $USER you could check for the existence of an EFI Partition (which would indicate a gpt partition scheme):

$ lsblk | grep -i efi ├─nvme0n1p1 259:2 0 100M 0 part /boot/efi 

You can use blkid


NB: in 2021 you may need to run blkid as root for accurate information to be returned.


 

Examples with output:

# blkid /dev/sdc /dev/sdc: PTUUID="92f03b9b-7402-4ad2-8316-08a991c237b3" PTTYPE="gpt" # blkid -o export /dev/sdc DEVNAME=/dev/sdc PTUUID=92f03b9b-7402-4ad2-8316-08a991c237b3 PTTYPE=gpt 

Or in a script, with the -o value option :

disk=$1 part_type=$(blkid -o value -s PTTYPE $disk) case $part_type in gpt) echo "GPT";; dos) echo "MBR";; *) echo "partition is $part_type";; esac 

Alternatively as a $USER you could check for the existence of an EFI Partition (which would indicate a gpt partition scheme):

$ lsblk | grep -i efi ├─nvme0n1p1 259:2 0 100M 0 part /boot/efi 

You can use blkid. But you may need to run it as root or as sudo blkid.

Examples with output:

# blkid /dev/sdc /dev/sdc: PTUUID="92f03b9b-7402-4ad2-8316-08a991c237b3" PTTYPE="gpt" # blkid -o export /dev/sdc DEVNAME=/dev/sdc PTUUID=92f03b9b-7402-4ad2-8316-08a991c237b3 PTTYPE=gpt 

Or in a script, with the -o value option :

disk=$1 part_type=$(blkid -o value -s PTTYPE $disk) case $part_type in gpt) echo "GPT";; dos) echo "MBR";; *) echo "partition is $part_type";; esac 

Alternatively as a $USER you could check for the existence of an EFI Partition (which would indicate a gpt partition scheme):

$ lsblk | grep -i efi ├─nvme0n1p1 259:2 0 100M 0 part /boot/efi 

You can use blkid


NB: in 2021 you may need to run blkid as root for accurate information to be returned.

 

Examples with output:

# blkid /dev/sdc /dev/sdc: PTUUID="92f03b9b-7402-4ad2-8316-08a991c237b3" PTTYPE="gpt" # blkid -o export /dev/sdc DEVNAME=/dev/sdc PTUUID=92f03b9b-7402-4ad2-8316-08a991c237b3 PTTYPE=gpt 

Or in a script, with the -o value option :

disk=$1 part_type=$(blkid -o value -s PTTYPE $disk) case $part_type in gpt) echo "GPT";; dos) echo "MBR";; *) echo "partition is $part_type";; esac 

Alternatively as a $USER you could check for the existence of an EFI Partition (which would indicate a gpt partition scheme):

$ lsblk | grep -i efi ├─nvme0n1p1 259:2 0 100M 0 part /boot/efi 

You can use blkid.

Examples with output:

# blkid /dev/sdc /dev/sdc: PTUUID="92f03b9b-7402-4ad2-8316-08a991c237b3" PTTYPE="gpt" # blkid -o export /dev/sdc DEVNAME=/dev/sdc PTUUID=92f03b9b-7402-4ad2-8316-08a991c237b3 PTTYPE=gpt 

Or in a script, with the -o value option :

disk=$1 part_type=$(blkid -o value -s PTTYPE $disk) case $part_type in gpt) echo "GPT";; dos) echo "MBR";; *) echo "partition is $part_type";; esac 

You can use blkid


NB: in 2021 you may need to run blkid as root for accurate information to be returned.

 

Examples with output:

# blkid /dev/sdc /dev/sdc: PTUUID="92f03b9b-7402-4ad2-8316-08a991c237b3" PTTYPE="gpt" # blkid -o export /dev/sdc DEVNAME=/dev/sdc PTUUID=92f03b9b-7402-4ad2-8316-08a991c237b3 PTTYPE=gpt 

Or in a script, with the -o value option :

disk=$1 part_type=$(blkid -o value -s PTTYPE $disk) case $part_type in gpt) echo "GPT";; dos) echo "MBR";; *) echo "partition is $part_type";; esac 

Alternatively as a $USER you could check for the existence of an EFI Partition (which would indicate a gpt partition scheme):

$ lsblk | grep -i efi ├─nvme0n1p1 259:2 0 100M 0 part /boot/efi 
Source Link
mivk
  • 3.9k
  • 1
  • 37
  • 34

You can use blkid.

Examples with output:

# blkid /dev/sdc /dev/sdc: PTUUID="92f03b9b-7402-4ad2-8316-08a991c237b3" PTTYPE="gpt" # blkid -o export /dev/sdc DEVNAME=/dev/sdc PTUUID=92f03b9b-7402-4ad2-8316-08a991c237b3 PTTYPE=gpt 

Or in a script, with the -o value option :

disk=$1 part_type=$(blkid -o value -s PTTYPE $disk) case $part_type in gpt) echo "GPT";; dos) echo "MBR";; *) echo "partition is $part_type";; esac