In this short tutorial, you are going to learn how to change the UUID of a Linux partition. This can help you in a less likely to happen scenario when the UUID of two partitions are the same.
In reality, this is really hard to happen, but it is still possible, if for example you copy a partition using dd command.
What is UUID?
UUID stands for Universally Unique IDentifier of a partition. This ID is used in few different places to identify the partition. Most commonly this would be /etc/fstab.
How to Find UUID of Your Filesystems
To find the UUID of your partitions, you can use blkid command as shown.
# blkid|grep UUID

How to Change UUID of Your Filesystems
Changing UUID of a filesystem is fairly easy. To do this, we are going to use tune2fs. For the purpose of this tutorial, I will change the UUID on my second partition /dev/sdb1
, yours may vary, thus make sure you are changing the UUID of the desired filesystem.
The partition has to be unmounted prior apply the new UUID:
# umount /dev/sdb1
# tune2fs -U random /dev/sdb1
# blkid | grep sdb1

The UUID has been successfully changed. Now you can mount the filesystem back again.
# mount /dev/sdb1
You can also update your /etc/fstab if needed, with the new UUID.
Conclusion
This was a short tutorial how to change a Linux partition UUID. The scenarios to use this are very rare and chances are that you will most probably use this on a local machine.
Typical of Linux advice, many times more wrong instructions and correct ones and NEVER corrected..
@michael,
I always correct articles based on the user suggestions, may I know what errors you have found in this article?
You have a typo.
I don’t believe you intended the second
/dev/sdb1
nor the# blkid
to appear on the same line.I’ve used this to reduce confusion after copying an image of a partition from an SSD to NVMe during an upgrade. Copying a partition with “dd” leaves two filesystems with the same UUID and this will reduce confusion.
How does having two partitions with the same UUID reduce confusion? How do you know which is the original and which is the copy? The idea is to have all unique UUIDs.
> tune2fs /dev/sdb1 -U random /dev/sdb1
That’s not the correct syntax.
> tune2fs -U random /dev/sdb1
First, even if you think all your readers will only be using ext2/3/4, you should at least mention that this only works for those filesystems.
Second, you’ve not said anything about *why* someone might want to *change* a UUID! I have never encountered a reason to do this, in real life (and the few instances that this may be needed are NOT for ext2/3/4 systems anyway!)
oops; ignore the second point in my comment
Mainly it happens after you clone a disk or partition with dd. You now have multiple filesystems with the same UUID.
For example, yesterday I copied the system partition to an SSD from an old spin disk. I wanted to preserve the spin disk for a couple of days in order to see SSD is working and all settings were preserved. I want to preserve data partition on the spin disk.
After the copy, the partition with GParted, both partitions, had dame UUID, so this tutorial was very helpful since grub was booting the incorrect partition.
You could also do this to make it easy to remember:
# tune2fs /dev/sda2 -U 12345678-abcd-1234-abcd-12ab34cd56ef
so, how to change uuid of root
(/)
partition?I got a message “The UUID may only be changed when the filesystem is unmounted” when I typed the tune2fs command with parameters.
@Andy,
Follow the instructions given in the article to change the UUID of the root partition.
Sorry, Ravi, but the article does not mention ‘root‘ at all, unless you are referring to “You can also update your /etc/fstab if needed, with the new UUID.”. But to update the /fstab file one needs root privileges.
@Dragonmouth,
If you see clearly, you notice that I have used the root user in the article.