Is disk’s UUID a good identifier for disk

hard driveuuid

My tool working among 100 disks, some of them may attach or detach from the server during the tool running. I want to use disk's UUID as disk's id, and I got the question: If some disk disk_1 got a UUID, say 32c8da8b-e6d5-9a85-5cfc-1a8b59535263. When it's space full, I detached the disk and formatted it (mkfs.ext3), then re-attach to machine, will it's UUID change?

Best Answer

A filesystem's UUID is generated by mkfs, so a reformat will change the UUID.

One option is to create a label when you make the filesystem and look in /dev/disk/by-label rather than /dev/disk/by-uuid. An advantage of using a label is that you can re-label a filesystem after the fact if you need to. A disadvantage is that you are now responsible for maintaining the labels and preventing collisions.