I havent looked into the source code of hfs.util and it is probably too late to be useful for you, but I think I can contribute something useful.
The UUIDs used for HFS+ volumes seem to be all of the variant covered by the UUID specification and be of the version 3 type, that is a namespace and a name converted to an UUID via MD5 (see details on wikipedia).
It seems likely that the actual disk identifier (taking the place of the name in the specification) is just 64 bits, converted into a 128 bits UUID according to the specification by prepending the UUID of whatever namespace Apple is using for volume identifiers and then applying an MD5 hash.
This does not involve computer component values, current time etc. Those are used for other kinds of UUIDs. However it does involve a «namespace» UUID (to identify the fact that we are «naming» a disk volume) and then a «name» (the actual identifier of the disk).
One thing that makes me think so is not only @chriv’s statement that it the code seems to only use 64 bits but also the way the UUIDs are handled by the «secret» utility that comes with SuperDuper!
The SuperDuper! backup utility for Mac OS X has a «hidden» command line tool that would let you retrieve and set a volume UUID. But it both retrieves and sets it as a sequence of 64 bits (expressed in hex). And it seems those bits are quite different than the actual values reported by Apple disk utilities.
For more information see:
http://www.shirt-pocket.com/forums/archive/index.php/t-1186.html
http://www.shirt-pocket.com/forums/archive/index.php/t-6173.html
Note: read those support discussions all the way through as it seems there are some gotchas, like sometimes a need to reboot.
Update
I have glanced at Apple sources. I confirm what I wrote above. What is saved on disk is a 64bits identifier for the volume (which is generated randomly by taking the first 64 bits of the SHA1 hash of a set of pseudo random bits of data: uptime, boot time, host id, host name, kernel release string, kernel version string, load average, VM statistics and current time).
In Version 3 UUID parlance this is a «name». So what is saved on the disk is a 64bit «name» of the volume, not the UUID.
The 128bits UUID that is reported by the tools is not saved, it is computed each time, for display purposes, from the «name» and the «namespace» (the namespace is fixed and is that kFSUUIDNamespaceSHA1 constant the OP had to manually add to the source because the header containing it is missing: it represent the «namespace» for volume «names» which are the 64bit things that are actually saved on the volumes to identify them).
It’s easy to go from the «name» to the UUID (basically you apply the standard algorithm for Version 3 UUIDs) but it’s basically impossible to go back from the UUID to the «name».
In other words the answer to the OP is: it’s possible if you know the «name» of the volume (for example if you want to restore a backup to a new disk AND you have saved the name of it as well as the data), but not if you only know the UUID. Setting the name correctly will result in the expected UUID, but you need the name and cannot compute it from the UUID.
Notes on Apple’s code (read these and look at the code and everything becomes clear):
As I wrote, all there is on disk is the «name». The UUID is computed only for visualization, using the Version 3 algorithm (an UUID for a «name» in a «namespace»).
- kFSUUIDNamespaceSHA1 is the «namespace» constant, as explained above.
- uuid_create_md5_from_name is the Version 3 UUID algorithm that computes a Version 3 UUID given a «namespace» and a «name».
- GenerateVolumeUUID generates a new random «name» (note: just the «name», not the UUID, despite the name of the function).
Setting and getting the «name» to disk is different depending whether the volume is currently mounted. The «name» is stored in the «Finder Info» of the volume. Getting and setting the «Finder Info» data for a mounted volume can be done with getattrlist and setattrlist but if the volume is not mounted they resort to accessing the volume data directly (this is unix, after all, and an unmounted volume is a block device which is accessible, by root, as a file).
- SetVolumeUUID, SetVolumeUUIDRaw, SetVolumeUUIDAttr, GetVolumeUUID, GetVolumeUUIDRaw, GetVolumeUUIDAttr do read/write the «name» (again, despite their name, they only handle the «name» of the volume, not the UUID). The *Raw functions handle direct access via the device «file» for unmounted volumes, the *Attr ones use the get/setattrlist API. The plain ones check if the volume is mounted and call the appropriate *Raw/*Attr version.
Then there are the «high level» functions that implement the functionality of the tool:
- DoGetUUIDKey gets the «name», adjusts for endianness, then computes the UUID for display.
- DoChangeUUIDKey creates a new, random, «name» and writes it to the volume.
So the best you can do is re-code the same functionality of the little command line tool embedded in Shirt Pocket’s SuperDuper! (see the links I posted above).
I havent looked into the source code of hfs.util and it is probably too late to be useful for you, but I think I can contribute something useful.
The UUIDs used for HFS+ volumes seem to be all of the variant covered by the UUID specification and be of the version 3 type, that is a namespace and a name converted to an UUID via MD5 (see details on wikipedia).
It seems likely that the actual disk identifier (taking the place of the name in the specification) is just 64 bits, converted into a 128 bits UUID according to the specification by prepending the UUID of whatever namespace Apple is using for volume identifiers and then applying an MD5 hash.
This does not involve computer component values, current time etc. Those are used for other kinds of UUIDs. However it does involve a «namespace» UUID (to identify the fact that we are «naming» a disk volume) and then a «name» (the actual identifier of the disk).
One thing that makes me think so is not only @chriv’s statement that it the code seems to only use 64 bits but also the way the UUIDs are handled by the «secret» utility that comes with SuperDuper!
The SuperDuper! backup utility for Mac OS X has a «hidden» command line tool that would let you retrieve and set a volume UUID. But it both retrieves and sets it as a sequence of 64 bits (expressed in hex). And it seems those bits are quite different than the actual values reported by Apple disk utilities.
For more information see:
http://www.shirt-pocket.com/forums/archive/index.php/t-1186.html
http://www.shirt-pocket.com/forums/archive/index.php/t-6173.html
Note: read those support discussions all the way through as it seems there are some gotchas, like sometimes a need to reboot.
Update
I have glanced at Apple sources. I confirm what I wrote above. What is saved on disk is a 64bits identifier for the volume (which is generated randomly by taking the first 64 bits of the SHA1 hash of a set of pseudo random bits of data: uptime, boot time, host id, host name, kernel release string, kernel version string, load average, VM statistics and current time).
In Version 3 UUID parlance this is a «name». So what is saved on the disk is a 64bit «name» of the volume, not the UUID.
The 128bits UUID that is reported by the tools is not saved, it is computed each time, for display purposes, from the «name» and the «namespace» (the namespace is fixed and is that kFSUUIDNamespaceSHA1 constant the OP had to manually add to the source because the header containing it is missing: it represent the «namespace» for volume «names» which are the 64bit things that are actually saved on the volumes to identify them).
It’s easy to go from the «name» to the UUID (basically you apply the standard algorithm for Version 3 UUIDs) but it’s basically impossible to go back from the UUID to the «name».
In other words the answer to the OP is: it’s possible if you know the «name» of the volume (for example if you want to restore a backup to a new disk AND you have saved the name of it as well as the data), but not if you only know the UUID. Setting the name correctly will result in the expected UUID, but you need the name and cannot compute it from the UUID.
Notes on Apple’s code (read these and look at the code and everything becomes clear):
As I wrote, all there is on disk is the «name». The UUID is computed only for visualization, using the Version 3 algorithm (an UUID for a «name» in a «namespace»).
- kFSUUIDNamespaceSHA1 is the «namespace» constant, as explained above.
- uuid_create_md5_from_name is the Version 3 UUID algorithm that computes a Version 3 UUID given a «namespace» and a «name».
- GenerateVolumeUUID generates a new random «name» (note: just the «name», not the UUID, despite the name of the function).
Setting and getting the «name» to disk is different depending whether the volume is currently mounted. The «name» is stored in the «Finder Info» of the volume. Getting and setting the «Finder Info» data for a mounted volume can be done with getattrlist and setattrlist but if the volume is not mounted they resort to accessing the volume data directly (this is unix, after all, and an unmounted volume is a block device which is accessible, by root, as a file).
- SetVolumeUUID, SetVolumeUUIDRaw, SetVolumeUUIDAttr, GetVolumeUUID, GetVolumeUUIDRaw, GetVolumeUUIDAttr do read/write the «name» (again, despite their name, they only handle the «name» of the volume, not the UUID). The *Raw functions handle direct access via the device «file» for unmounted volumes, the *Attr ones use the get/setattrlist API. The plain ones check if the volume is mounted and call the appropriate *Raw/*Attr version.
Then there are the «high level» functions that implement the functionality of the tool:
- DoGetUUIDKey gets the «name», adjusts for endianness, then computes the UUID for display.
- DoChangeUUIDKey creates a new, random, «name» and writes it to the volume.
So the best you can do is re-code the same functionality of the little command line tool embedded in Shirt Pocket’s SuperDuper! (see the links I posted above).
Does anybody have a solution to change the «Volume UUID» on Mac ?
I have this when using diskutil info from mac os x
asked Jan 23, 2018 at 17:48
2
Below is the applescript script to read UUID from an NTFS partition. All sudo are to be completed for your name and password, otherwise try removing the sudo. I do not advise you to modify the UUID, there is no information on their use. I left the inversion of the bytes in a very rudimentary way.
set hdd to {}
set dmg to do shell script "sudo ls /dev/disk**s** " & " | sed -e 's#[[:space:]]*$##;s#\/dev\/##;/^$/d'" user name "Your_Name" password "Your_Password" with administrator privileges
set doun to ""
set dor to ""
set uuidd to ""
set uuidd to {}
set hfsountfs to ""
set theVol1 to ""
set theVol to ""
set vhd to ""
set leplus to 0
set levhd to ""
set hd to {}
set _Result to the paragraphs of dmg
set n to 0
set n to count _Result
set j to 1
do shell script "echo " & n
repeat with i from 1 to n
set end of hdd to item i of _Result
end repeat
set theVolumeTemp to (choose from list hdd with prompt "Choisissez le Volume (partition) NTFS :" with empty selection allowed)
if theVolumeTemp is not false then
set theVolumeTemp to do shell script "echo " & theVolumeTemp
set theVol to "/dev/" & theVolumeTemp
set theVol1 to theVol
set theVol to do shell script "echo " & theVol & " | xxd -p | sed 's#0a##' | xxd -r -p "
try
set vhd to do shell script "diskutil info " & theVol & " | grep 'Disk Image' "
end try
try
set uuidd to do shell script "diskutil unmount " & theVol
end try
set uuidd to do shell script "sudo dd if=" & theVol & " iseek=48 bs=1 count=8 | xxd -p " user name "Your_Name" password "Your_Password" with administrator privileges
set theVol to do shell script "echo " & uuidd
set n to 0
set n to count uuidd
do shell script "echo " & n
repeat with i from 1 to 8
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set hd to do shell script "echo " & hd
set nDec to (do shell script "perl -e 'printf(hex("" & hd & ""))'") as integer
if vhd is not "" then
set leplus to 3320
set levhd to "c'est un Vhd ntfs"
else
set leplus to 3352
end if
set nDec to do shell script " echo $((" & nDec & " * 4096 + " & leplus & "))" as string
set uuidd to do shell script "sudo dd if=" & theVol1 & " iseek=" & nDec & " bs=1 count=16 | xxd -p " user name "Your_Name" password "Your_Password" with administrator privileges
set hd to {}
set n to 8
repeat with i from 1 to 4
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set end of hd to "-"
set n to 12
repeat with i from 1 to 2
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set end of hd to "-"
set n to 16
repeat with i from 1 to 2
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set end of hd to "-"
repeat with i from 17 to 20
set end of hd to item (i) of uuidd
end repeat
set end of hd to "-"
repeat with i from 21 to 32
set end of hd to item (i) of uuidd
end repeat
set hd to do shell script "echo " & hd
set lamft to do shell script " echo $((" & nDec & " - " & leplus & "))" as string
set doun to " Identifiant Universel Unique ou UUID du " & theVolumeTemp & " est :
" & hd
set doun to doun & "
La MFT du " & theVolumeTemp & " est à : " & lamft & " Octets du départ de la partition " & "
l'UUID se trouve plus loin de " & leplus & " Octets " & "
" & levhd
set uuiddd to do shell script "sudo dd if=" & theVol1 & " iseek=72 bs=1 count=8 | xxd -p " user name "Your_Name" password "Your_Password" with administrator privileges
set n to 0
set n to count uuiddd
do shell script "echo " & n
set uuiddd to do shell script "echo " & uuiddd & " | tr [:lower:] [:upper:] "
set hdd to {}
set les2 to (item 15 of uuiddd & item 16 of uuiddd & item 13 of uuiddd & item 14 of uuiddd)
set end of hdd to les2
set end of hdd to "-"
set les2 to (item 11 of uuiddd & item 12 of uuiddd & item 9 of uuiddd & item 10 of uuiddd)
set end of hdd to les2
set end of hdd to "-"
set les2 to (item 7 of uuiddd & item 8 of uuiddd & item 5 of uuiddd & item 6 of uuiddd)
set end of hdd to les2
set end of hdd to "-"
set les2 to (item 3 of uuiddd & item 4 of uuiddd & item 1 of uuiddd & item 2 of uuiddd)
set end of hdd to les2
set doun to doun & " Le numero de série des 8 Octets de l'offset 72 partition NTFS du " & theVolumeTemp & " est :
" & uuiddd & "
Toujours présenté sous cette forme : " & hdd
display alert (doun as string)
try
do shell script "diskutil mount " & theVol1
end try
end if
answered Jun 6, 2018 at 16:09
deek5deek5
3671 silver badge12 bronze badges
I am not sure about Mac but why would you use NTFS there.
But for Windows you could try the Set-Disk powershell command with the -Guid parameter.
Cheers,
Gabriel
answered Jan 28, 2018 at 12:34
Gabriel BerceaGabriel Bercea
1,1811 gold badge11 silver badges21 bronze badges
Есть ли у кого-нибудь решение изменить «Volume UUID» на Mac?
У меня это при использовании diskutil info из mac os x
2 ответа
Ниже приведен сценарий applescript для чтения UUID из раздела NTFS. Все sudo должны быть заполнены для вашего имени и пароля, в противном случае попробуйте удалить sudo. Не советую изменять UUID, информации об их использовании нет. Я оставил инверсию байтов в очень примитивном виде.
set hdd to {}
set dmg to do shell script "sudo ls /dev/disk**s** " & " | sed -e 's#[[:space:]]*$##;s#\/dev\/##;/^$/d'" user name "Your_Name" password "Your_Password" with administrator privileges
set doun to ""
set dor to ""
set uuidd to ""
set uuidd to {}
set hfsountfs to ""
set theVol1 to ""
set theVol to ""
set vhd to ""
set leplus to 0
set levhd to ""
set hd to {}
set _Result to the paragraphs of dmg
set n to 0
set n to count _Result
set j to 1
do shell script "echo " & n
repeat with i from 1 to n
set end of hdd to item i of _Result
end repeat
set theVolumeTemp to (choose from list hdd with prompt "Choisissez le Volume (partition) NTFS :" with empty selection allowed)
if theVolumeTemp is not false then
set theVolumeTemp to do shell script "echo " & theVolumeTemp
set theVol to "/dev/" & theVolumeTemp
set theVol1 to theVol
set theVol to do shell script "echo " & theVol & " | xxd -p | sed 's#0a##' | xxd -r -p "
try
set vhd to do shell script "diskutil info " & theVol & " | grep 'Disk Image' "
end try
try
set uuidd to do shell script "diskutil unmount " & theVol
end try
set uuidd to do shell script "sudo dd if=" & theVol & " iseek=48 bs=1 count=8 | xxd -p " user name "Your_Name" password "Your_Password" with administrator privileges
set theVol to do shell script "echo " & uuidd
set n to 0
set n to count uuidd
do shell script "echo " & n
repeat with i from 1 to 8
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set hd to do shell script "echo " & hd
set nDec to (do shell script "perl -e 'printf(hex("" & hd & ""))'") as integer
if vhd is not "" then
set leplus to 3320
set levhd to "c'est un Vhd ntfs"
else
set leplus to 3352
end if
set nDec to do shell script " echo $((" & nDec & " * 4096 + " & leplus & "))" as string
set uuidd to do shell script "sudo dd if=" & theVol1 & " iseek=" & nDec & " bs=1 count=16 | xxd -p " user name "Your_Name" password "Your_Password" with administrator privileges
set hd to {}
set n to 8
repeat with i from 1 to 4
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set end of hd to "-"
set n to 12
repeat with i from 1 to 2
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set end of hd to "-"
set n to 16
repeat with i from 1 to 2
set les2 to (item (n - 1) of uuidd & item n of uuidd)
set end of hd to les2
set n to n - 2
end repeat
set end of hd to "-"
repeat with i from 17 to 20
set end of hd to item (i) of uuidd
end repeat
set end of hd to "-"
repeat with i from 21 to 32
set end of hd to item (i) of uuidd
end repeat
set hd to do shell script "echo " & hd
set lamft to do shell script " echo $((" & nDec & " - " & leplus & "))" as string
set doun to " Identifiant Universel Unique ou UUID du " & theVolumeTemp & " est :
" & hd
set doun to doun & "
La MFT du " & theVolumeTemp & " est à : " & lamft & " Octets du départ de la partition " & "
l'UUID se trouve plus loin de " & leplus & " Octets " & "
" & levhd
set uuiddd to do shell script "sudo dd if=" & theVol1 & " iseek=72 bs=1 count=8 | xxd -p " user name "Your_Name" password "Your_Password" with administrator privileges
set n to 0
set n to count uuiddd
do shell script "echo " & n
set uuiddd to do shell script "echo " & uuiddd & " | tr [:lower:] [:upper:] "
set hdd to {}
set les2 to (item 15 of uuiddd & item 16 of uuiddd & item 13 of uuiddd & item 14 of uuiddd)
set end of hdd to les2
set end of hdd to "-"
set les2 to (item 11 of uuiddd & item 12 of uuiddd & item 9 of uuiddd & item 10 of uuiddd)
set end of hdd to les2
set end of hdd to "-"
set les2 to (item 7 of uuiddd & item 8 of uuiddd & item 5 of uuiddd & item 6 of uuiddd)
set end of hdd to les2
set end of hdd to "-"
set les2 to (item 3 of uuiddd & item 4 of uuiddd & item 1 of uuiddd & item 2 of uuiddd)
set end of hdd to les2
set doun to doun & " Le numero de série des 8 Octets de l'offset 72 partition NTFS du " & theVolumeTemp & " est :
" & uuiddd & "
Toujours présenté sous cette forme : " & hdd
display alert (doun as string)
try
do shell script "diskutil mount " & theVol1
end try
end if
1
deek5
6 Июн 2018 в 19:09
Вашему Mac, iPhone и iPad назначен универсальный уникальный идентификатор (UUID). Эти коды специфичны для каждого устройства и, как и серийный номер, используются разработчиками для идентификации каждого устройства в отдельности. Вот что вам нужно знать.
UUID — это строка букв и цифр, образующая уникальный шаблон. Ваш Mac, iPhone и iPad имеют один UUID, и никакое другое устройство не использует его. В этом отношении он похож на серийный номер, но в то время как серийные номера используются для идентификации вашего устройства Apple и вашим оператором сотовой связи, разработчики обычно вместо этого используют UUID.
Обычно вам не нужно знать (или иметь доступ) свой UUID. Но если вы регистрируете устройство в рамках программы Apple Developer Program, чтобы установить бета-версию программного обеспечения, оно вам понадобится. Разработчики приложений также могут запросить UUID вашего устройства, чтобы предоставить сборки, которые будут работать только на этом конкретном устройстве.
Как найти UUID вашего Mac
Щелкните логотип Apple в строке меню, а затем выберите параметр «Об этом Mac».
Нажмите кнопку «Системный отчет».
Обратите внимание на текст рядом с UUID оборудования.
При необходимости вы можете скопировать текст прямо из окна.
Как найти UUID вашего iPhone и iPad
Подключите свой iPhone или iPad к компьютеру, а затем откройте iTunes. Щелкните значок устройства вверху.
UUID вашего устройства по умолчанию скрыт — нажмите «Серийный номер», и он изменится и отобразит ваш UUID.
Вы также можете скопировать UUID прямо из iTunes.
Другие идентификаторы на заметку
Есть и другие идентификаторы, которые могут вам встретиться.
Идентификаторы модели используются для выделения модели конкретного устройства. Они не уникальны для этого устройства, а скорее относятся к модельному диапазону, в который оно входит. Например, iPhone 7 известен как iPhone9, x, а iPhone XS — как iPhone11, x. Эти цифры обычно используются только Apple, но иногда они появляются в утечках о будущих устройствах.
Apple и ее поставщики используют номера моделей для идентификации устройств и рынка, для которого они разработаны. Например, iPhone XS, продаваемый в США, имеет номер A1920, а в Японии — A2098.
Номера IMEI, также известные как международные идентификационные номера мобильного оборудования, используются операторами связи. Они уникальны для любого устройства, которое подключается к сотовой сети, и часто используются для блокировки устройств, которые были заявлены как украденные или утерянные.
Что вы думаете об этой статье?