How to get disk partition UUID in Linux
Universally Unique IDentifier or UUID is a random 128-bit value that can be generated and assigned to partitions or block devices. The partitions or block devices could then be identified using UUID instead of the normal device name such as /dev/sda1. You can then use the UUID to mount filesystem via /etc/fstab by specifying UUID value in block special device (the first field).
Related: How to change disk partition UUID in Linux
Related: How to mount disk partition using UUID in Linux
UUID is typically just a symlink to the actual device name in /dev directory, and you can get the UUID of a partition by browsing /dev/disk/by-uuid/ directory. There are also some command-line programs that you can use to get partition UUID in Linux.
Steps to get partition UUID in Linux:
-
Launch terminal.
-
List partition UUID from /dev.
$ ls -l /dev/disk/by-uuid/ total 0 lrwxrwxrwx 1 root root 9 Feb 27 06:29 2020-10-22-14-30-30-00 -> ../../sr0 lrwxrwxrwx 1 root root 10 Feb 27 06:23 9B8B-2022 -> ../../sda2 lrwxrwxrwx 1 root root 10 Feb 27 06:23 a7d71686-0a65-4402-b6e6-b58430ef8351 -> ../../sda3
The absolute path for ../../sda3 is /dev/sda3
-
Get UUID for all available devices using blkid.
$ blkid /dev/sda3: UUID="a7d71686-0a65-4402-b6e6-b58430ef8351" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="0ea90c96-1b56-4c51-b07a-02e09285f291" /dev/sr0: BLOCK_SIZE="2048" UUID="2020-10-22-14-30-30-00" LABEL="Ubuntu 20.10 amd64" TYPE="iso9660" PTTYPE="PMBR"
blkid is installed by default in most Linux distributions.
-
Find UUID for specific partition.
$ blkid /dev/sda3 /dev/sda3: UUID="a7d71686-0a65-4402-b6e6-b58430ef8351" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="0ea90c96-1b56-4c51-b07a-02e09285f291"
More options for blkid:
$ blkid --help Usage: blkid --label <label> | --uuid <uuid> blkid [--cache-file <file>] [-ghlLv] [--output <format>] [--match-tag <tag>] [--match-token <token>] [<dev> ...] blkid -p [--match-tag <tag>] [--offset <offset>] [--size <size>] [--output <format>] <dev> ... blkid -i [--match-tag <tag>] [--output <format>] <dev> ... Options: -c, --cache-file <file> read from <file> instead of reading from the default cache file (-c /dev/null means no cache) -d, --no-encoding don't encode non-printing characters -g, --garbage-collect garbage collect the blkid cache -o, --output <format> output format; can be one of: value, device, export or full; (default: full) -k, --list-filesystems list all known filesystems/RAIDs and exit -s, --match-tag <tag> show specified tag(s) (default show all tags) -t, --match-token <token> find device with a specific token (NAME=value pair) -l, --list-one look up only first device with token specified by -t -L, --label <label> convert LABEL to device name -U, --uuid <uuid> convert UUID to device name <dev> specify device(s) to probe (default: all devices) Low-level probing options: -p, --probe low-level superblocks probing (bypass cache) -i, --info gather information about I/O limits -S, --size <size> overwrite device size -O, --offset <offset> probe at the given offset -u, --usages <list> filter by "usage" (e.g. -u filesystem,raid) -n, --match-types <list> filter by filesystem type (e.g. -n vfat,ext3) -h, --help display this help -V, --version display version For more details see blkid(8).