Question

Is there an easy way to determine the hexadecimal ID of the filesystem for a given partition? Say, I have a /dev/sda1 partition which is of "Linux" type having the filesystem ID of 83 (as shown by fdisk for example). I need to get this number from a bash script without parsing the output of fdisk/sfdisk.

Était-ce utile?

La solution

The partition IDs are stored in the MBR (or EMBR for logical ones). They are thus not stored in the device itself. i.e. /dev/sda1 doesn't contains its type.

fdisk and similar commands do display the partition types and are designed to do it properly. Trying to avoid them would be pointless.

This Linux shell script will show the partition ID for a given device:

#!/bin/sh
fdisk -l | tr -d '*' | awk -v dev=$1 '$1 == dev { print $5 } '

.

# some_command /dev/sda1
83
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top