How do I change UUID of a disk to whatever I want?

If you used ext for it:

tune2fs /dev/{device} -U {uuid}

From man tune2fs

-U UUID

Set the universally unique identifier (UUID) of the filesystem to UUID. The format of the UUID is a series of hex digits separated by hyphens, like this: c1b9d5a2-f162-11cf-9ece-0020afc76f16. The UUID parameter may also be one of the following:

clear  clear the filesystem UUID
random generate a new randomly-generated UUID
time   generate a new time-based UUID

The UUID may be used by mount(8), fsck(8), and /etc/fstab(5) (and possibly others) by specifying UUID=uuid instead of a block special device name like /dev/hda1.


I realize this is kind of an old question, but I found there was a new change, and this was what google snooped up for me, so I'll post the answer I found here.

when I tried to change my root filesystem's uuid (to a well known beginning and a serial number suffix) on new 14.04 ubuntu, I found to my horror tune2fs reported back: I can't do that to mounted file systems. I depend on being able to use a template image with a well known uuid, and change each install to a serialized uuid. I found the problem wasn't insurmountable.

There's a flag that needs to be disabled, to allow mounted-uuid changes with the new tune2fs. this is what my process looked like:

root@ubuntu1404:~# blkid
/dev/sda1: UUID="2ec827b0-72be-4c73-b58a-102a37aa24a3" TYPE="ext4"
root@ubuntu1404:~# uuid="deafcafe-abba-daba-deca-fc0ffee05065"
root@ubuntu1404:~# root_disk=$(df /|grep /|cut -d' ' -f1)
root@ubuntu1404:~# echo $root_disk
/dev/sda1
root@ubuntu1404:~# tune2fs -U $uuid $root_disk
tune2fs 1.42.9 (4-Feb-2014)
The UUID may only be changed when the filesystem is unmounted.
root@ubuntu1404:~# tune2fs -O ^uninit_bg $root_disk
tune2fs 1.42.9 (4-Feb-2014)
root@ubuntu1404:~# tune2fs -U $uuid $root_disk
tune2fs 1.42.9 (4-Feb-2014)
root@ubuntu1404:~# tune2fs -O +uninit_bg $root_disk
tune2fs 1.42.9 (4-Feb-2014)
root@ubuntu1404:~# df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       7.3G  3.9G  3.0G  58% /
root@ubuntu1404:~# blkid
/dev/sda1: UUID="deafcafe-abba-daba-deca-fc0ffee05065" TYPE="ext4"
root@ubuntu1404:~#

For xfs see man xfs_admin

xfs_admin -U {uuid} {device}

{uuid} can be 'generate' to just get a new uuid.

For reiserfs see man tunefs.reiserfs

tunefs.reiserfs -i {uuid} {device}

For btrfs it seems the uuid is used thoughout the file systems so every node have to be updated. There is no safe way to do that yet.

Tags:

Filesystem