Linux – How to Change Filesystem UUID (2 Same UUID)

cloningfilesystemslinuxuuid

I have a fedora guest OS in VMware. I want to expand /boot partition, so I add another virtual disk to this VM, and try to clone the disk.

After dd if=/dev/sda1 of=/dev/sdb1, blkid report that /dev/sda1 and /dev/sdb1 have same UUID/GUID.

It's weird that there're 2 same UUIDs in the universe, how to change one of them to another UUID value?


Update 2017-01-25

Subject changed, UUID here means filesystem UUID, not partition UUID.

Since it's filesystem UUID, filesystem specific utils are needed to change the UUID, or use hexeditor to modify raw data on disk (DANGEROUS, not recommended unless you know what you are doing).

Best Answer

To generate a random new UUID, one can use:

$ uuidgen

To actually change the UUID is file system dependent.

Assuming ext-family filesystem

# tune2fs -U <output of uuidgen> /dev/sdb1

Or if you're confident uuidgen is going to work:

# tune2fs -U $(uuidgen) /dev/sdb1

Assuming btrfs filesystem

# btrfstune -U $(uuidgen) /dev/sdb1

The UUID is stored in the superblock, so a byte-for-byte copy of the filesystem will have the same UUID.

Related Question