Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to Change the UUID of a Linux Partition  (Read 1085 times)

0 Members and 1 Guest are viewing this topic.

Amal John Ronkha

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
How to Change the UUID of a Linux Partition
« on: July 14, 2018, 12:20:36 pm »
Duplicated UUID’s can be a big problem on your machine. But luckily it is easy to change the UUID of a Linux partition and can be done in roughly 1-2 minutes!

The UUID is used in a few places to identify the partition. The most notable being your /etc/fstab file, which manages the mounting of partitions at boot time.

Why would you need to change a partition UUID?

The main reason being a clash of ID’s. Technically the likelihood of creating 2 identical UUID’s is very rare (read more on the Random UUID probability of duplicates). But there may be cases where you clone a partition using DD or Clonezilla and the clone resides on the same machine – different physical hard drive or partition.

Cloning using both the tools mentioned above will create an exact copy of the partition all the way down to the UUID – and now you have 2 partitions with the same UUID. From the example of my /etc/fstab above, the UUID is no longer unique and it will mount the first partition it finds with that UUID.

How do I change the UUID?

First find the device path

You can find the device path using the following command:

Code: [Select]
sudo blkid
Your output will look something like this:

Code: [Select]
sudo blkid
/dev/sdb1: UUID="aabe7e48-2d11-421f-8609-7ea9d75e7f9b" TYPE="swap"
/dev/sdc1: UUID="9467f4de-4231-401f-bcaa-fee718d49e85" TYPE="ext4"
/dev/sdc3: UUID="93a54a4a-e0f5-4152-ae59-2245e8d16ee4" TYPE="ext4"
/dev/sde5: UUID="9467f4de-4231-401f-bcaa-fee718d49e85" TYPE="ext4"
/dev/sde6: LABEL="var" UUID="30433f28-1b79-4b4d-9985-fef5b1c886b5" TYPE="ext4"

Here you can see that /dev/sdc1 and /dev/sde5 have the same UUID. The path of the partition I want to change is /dev/sde5

Secondly, generate a UUID

This is simple, the following command will output a UUID like below:

Code: [Select]
uuidgen
f0acce91-a416-474c-8a8c-43f3ed3768f9

Finally apply the new UUID to the partition

This is also another command, tune2fs, which will apply our new UUID to our device path:

Code: [Select]
sudo tune2fs /dev/sde5 -U f0acce91-a416-474c-8a8c-43f3ed3768f9
Done, now you can update your grub to include the correct UUID’s to reduce any risk of your system confusing the partitions.

Hope this helps!  ;)  :)