How to Change the UUID of a Linux Partition
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 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.
Share this:
- Tweet
Pingback: Change a partition’s UUID « 0ddn1x: tricks with *nix()
Thanks a lot ……….Save my day.
Obrigado, foi de muita ajuda.
nice job
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
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.
Thanks, much appreciated.
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.
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.
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.
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.
Thanks for the instructions. However, I get an error “Couldn’t find valid filesystem superblock.”. It probably fails because the partition is NTFS?
Yep, used clonezilla kept the original drive, caused Ubuntu to go into maintenance cycle. Thanks
Wish I had read this yesterday.
Thanks again.
Please do not confuse Partition UUID with file system UUID. What you are changing is filesystem UUID. MBR partition table do not have partition UUIDs, so filesystem UUID is used interchangeably. This is not true with GPT partition table where partition UUID and filesystem UUID are two different things. Here is output from one of the devices that I have with GPT partition table:
# lsblk -o NAME,MOUNTPOINT,UUID,PARTUUID
NAME MOUNTPOINT UUID PARTUUID
sda
|-sda4 / 380a630a-eae2-4ae3-8549-bd9881b8f04e 1a678da3-8735-4a94-968e-238ac5af4c8d
|-sda2 DC89-1707 0a8d91a4-7a6f-48b8-b18b-5b0d91e45a3c
|-sda7 /var a0374f8a-d4a9-432c-951c-19de6567f185 f021ce56-c9a6-41c7-ba76-a709dfcdf062
|-sda5 380a630a-eae2-4ae3-8549-bd9881b8f04e 1b73940e-534d-4bf4-866a-a47539df1b73
|-sda3 DC89-EDE3 0be16a8a-bd55-4798-be60-8fcd69d11b15
|-sda1 DC87-EEB4 b7e79c11-f5a0-49f7-824c-e1644ecd0c63
`-sda6 [SWAP] 6968c1f4-4f3e-11e8-8ad6-000c29c9b0fb ffaa1416-6f4d-4547-ba1e-c48d370645ed
I did this in less than a second without typing anything. Gparted.
Is there any way to disable the UUID scheme in Linux? I’d rather work by position without the bother of UUIDs. That is, a drive is known as /dev/sda1, not a very long string of characters.