Hard drive partitions on Linux systems rely on a UUID (universally unique identifier) for unique labels. This is basically a unique string of characters that the operating system will use to identify your hard disk partitions and other storage components.
You can see this for yourself by examining the
/etc/fstab file on your own system.
$ grep UUID /etc/fstab
In this guide, we’ll go over several command line methods to retrieve the UUIDs of hard disk partitions. We’ll also show you how to generate UUIDs and change a partition’s UUID.
In this tutorial you will learn:
- How to retrieve, generate, and change the UUID of a partition
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
There are several different ways you can retrieve the UUID for a hard drive partition on Linux. Check out some of the commands below to get started.
- Use the
blkidcommand to see the UUID of all partitions.
or you can specify an argument to retrieve a single partition UUID:
# blkid /dev/sda2
- List the contents of the
# ls -l /dev/disk/by-uuid/
- Retrieve partition UUIDs with the
# udevadm info -q all -n /dev/sda2 | grep uuid
hwinfocommand can also be used to retrieve the information, assuming that the program has already been installed on your system.
# hwinfo --block
Now that you know how to retrieve your current UUIDs, let’s talk about how to change a partition’s UUID.
Use the following
tune2fs command to change the UUID of a partition. In this example, we will change the UUID for partition
# tune2fs /dev/sda1 -U random
Then, confirm the changes with one of the commands from the previous section.
# blkid /dev/sda1
You may also use the
uuid command (provided you have it installed) if you want to manually generate a UUID or be given more options. For example, you could use the following command to generate a UUID.
# uuid 266584be-d7b7-11eb-8c76-c3eef48c7257
And assign a particular UUID with
# tune2fs /dev/sda1 -U 266584be-d7b7-11eb-8c76-c3eef48c7257
Or use the
uuid command to generate a UUID inside the
# tune2fs /dev/sda1 -U `uuid`
Any of the three methods work fine and will allow you to set a new UUID to the desired partition.
In this guide, we saw how to retrieve and change the UUID of a partition on Linux. We also saw how to manually generate UUIDs with the
uuid command. Using the
tune2fs command, we can set a new, random UUID to a hard drive partition, or a particular one that we’ve generated via the