How to Change the UUID of a Linux Partition

Change partition UUIDDuplicated 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 of a Linux partition is the Universally Unique IDentifier of that partition. I would say with a fair bit of confidence that in this and most scenarios, the Linux partition UUID has more of a local machine scope.

This ID 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. Here is a little snippet from mine…

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?

This isn’t hard at all.

First find the device path

You can find the device path using the following command:

Your output will look something like this:

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:

Finally apply the new UUID to the partition

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

Done, now you can update your grub to include the correct UUID’s to reduce any risk of your system confusing the partitions.

  • Pingback: Change a partition’s UUID « 0ddn1x: tricks with *nix()

  • Arun

    Thanks a lot ……….Save my day.

  • eacsfc

    Obrigado, foi de muita ajuda.

  • Libo

    nice job

  • jim

    Thanks, save the day. Suggestion, to revert a swap partition to a known uuid, sudo user :
    swaplabel [-U UUID] device
    fyi, be aware, every time a partition is formated it gets a new uuid

  • B Ivens

    I’m new to Linux, currently using Ubuntu 12.04; found this info very helpful since I just cloned my Ubuntu partition to a ssd; wanted to retain the original hdd so had duplicate uuids. You don’t mention fstab – does it not have to be updated?

    • In your case definitely so. Use blkid to get the new uuid (for the ssd partition) then open fstab ‘gksudo gedit fstab’ and change the uuid of the device mounted at / (root). That is usually the first uncommented line on a fresh installation.

      • B Ivens

        Thanks, much appreciated.

      • Josep Lladonosa

        I would take care about GRUB, too, if needed.

        In case of a boot partition (/ or /boot,…), after changing its UUID, a “sudo update-grub” call is required. That call will update grub configuration as it references to partitions in /etc/fstab.

  • NoOne3584

    Wouldn’t tune2fs -U random /dev/sdxx save the step of first generating a UUID with uuidgen?

    Also, what about EFI partitions which are of type “vfat”? tune2fs won’t work with those.

  • sf__

    Why would I want to change it? Because the OS sprinkled all config files all over the system with my root disk’s UUID, and then happily changed its UUID during an update, without bothering to update these files. Now I can either hunt down all the countless configs or just restore the old UUID.

  • ross minet

    In case of dual boot with two different distros (eg. unity and mint), will the uuid of an external usb drive coincide from one distro to the other?
    If not, the importation of a banshee media player db frome one distro to the other will not work and tune2fs will have to be used to make the uuids coincide.
    Thank you.

  • Jānis Elmeris

    Thanks for the instructions. However, I get an error “Couldn’t find valid filesystem superblock.”. It probably fails because the partition is NTFS?