How to determine/find UUID of a partition?

In Linux, UUID(Universally Unique Identifier) can identify media more accurately and reliable, identify media via /dev/hdxy or /dev/sdxy is not a good method because the order may be different between boots, so it was no longer preferred any more, especially in fstab or grub config.

How to find UUIDs of my hard disk partitions?

$ ls -l /dev/disk/by-uuid

total 0
lrwxrwxrwx 1 root root 11 Feb 16 03:59 1898d5ea-dcea-4959-94a9-ff21a163ba85 -> ../../zram5
lrwxrwxrwx 1 root root 11 Feb 16 03:59 41e9022c-9a91-446c-a05c-2e3cd03f2180 -> ../../zram6
lrwxrwxrwx 1 root root 11 Feb 16 03:59 4ca3ac3b-0ada-419c-8c9b-a292c3e41e43 -> ../../zram3
lrwxrwxrwx 1 root root 11 Feb 16 03:59 6165ed95-d7f2-4997-9496-9bc8df9be3d2 -> ../../zram4
lrwxrwxrwx 1 root root 11 Feb 16 03:59 7356c5f2-3379-4953-914c-ba2e598c828e -> ../../zram0
lrwxrwxrwx 1 root root 11 Feb 16 03:59 92d32f20-bc55-4698-9096-a4966061dcf8 -> ../../zram1
lrwxrwxrwx 1 root root 10 Feb 16 03:59 a6127375-d994-4cd0-ab11-5f4bf65f9f3e -> ../../sda1
lrwxrwxrwx 1 root root 11 Feb 16 03:59 af5e0104-1213-4e49-aea2-c177c97e7118 -> ../../zram7
lrwxrwxrwx 1 root root 11 Feb 16 03:59 b4f51d6c-29bd-4655-b6c9-8acb6b8a2c9f -> ../../zram2
lrwxrwxrwx 1 root root 10 Feb 16 03:59 dca199dd-3e9f-4381-8637-22354b0b11f4 -> ../../sda5

or

$ blkid

/dev/sda5: UUID=”dca199dd-3e9f-4381-8637-22354b0b11f4″ TYPE=”swap”
/dev/sda1: UUID=”a6127375-d994-4cd0-ab11-5f4bf65f9f3e” TYPE=”ext4″
/dev/zram0: UUID=”7356c5f2-3379-4953-914c-ba2e598c828e” TYPE=”swap”
/dev/zram1: UUID=”92d32f20-bc55-4698-9096-a4966061dcf8″ TYPE=”swap”
/dev/zram2: UUID=”b4f51d6c-29bd-4655-b6c9-8acb6b8a2c9f” TYPE=”swap”
/dev/zram3: UUID=”4ca3ac3b-0ada-419c-8c9b-a292c3e41e43″ TYPE=”swap”
/dev/zram4: UUID=”6165ed95-d7f2-4997-9496-9bc8df9be3d2″ TYPE=”swap”
/dev/zram5: UUID=”1898d5ea-dcea-4959-94a9-ff21a163ba85″ TYPE=”swap”
/dev/zram6: UUID=”41e9022c-9a91-446c-a05c-2e3cd03f2180″ TYPE=”swap”
/dev/zram7: UUID=”af5e0104-1213-4e49-aea2-c177c97e7118″ TYPE=”swap”

(PS: blkid may need root privilege)

How to generate a new UUID for a partition?
# tune2fs -U random /dev/sda1

tune2fs 1.42.5 (29-Jul-2012)

Use blkid /dev/sda1to check /dev/sda1’s UUID, it’ll be a new one.

Example:
UUID

And in /etc/fstab, we should tell others we are now using UUID by UUID= like this:
fstab