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?
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.If there is no specific reason for exclusively using UUID, you might consider alternatives like using
/dev/disk/by-partuuid
. It relies on information stored in the GPT rather than in the partition itself, so the identifier should remain fixed when you only reformat the partition./dev/disk/by-id
might also be interesting, it uses the hardware serial number. However, the controller type is part of the ID-string, so that might be a problem if you attach your disks differently each time.source: https://wiki.archlinux.org/index.php/persistent_block_device_naming