5

I needed to make a clone of my hard drive recently (bad blocks FTW). I was using Clonezilla at the time.

However, Clonezilla refused to copy the HFS+ partition, so I did it manually. The problem is that the UUIDs are out of sync.

What is the command to set a specific UUID for HFS+?

5
  • open it up in gdisk. x for xpert menu. c for change partition GUID.
    – mikeserv
    Sep 7, 2014 at 6:03
  • @mikeserv Can I set a specific UUID that way?
    – Kaz Wolfe
    Sep 8, 2014 at 0:21
  • sure. Have you tried? I'll do an answer and show you.
    – mikeserv
    Sep 8, 2014 at 0:53
  • @mikeserv Not yet. My new computer hasn't arrived yet.
    – Kaz Wolfe
    Sep 8, 2014 at 0:59
  • I did a step-by-step below. Let me know if you need anything else.
    – mikeserv
    Sep 8, 2014 at 1:38

2 Answers 2

4

First I'll create a 500M image file:

$ cd /tmp
$ fallocate -l $((1024*1024*500)) ./disk

Now I'll give it a GPT:

$ gdisk ./disk

GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

o for create new GPT.

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y

n for create new partition. I just press enter to select all defaults after that.

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-1023966, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-1023966, default = 1023966) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

w writes changes to disk.

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to ./disk.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

Now I'll set it up as a partitioned block device and format the first partition with a filesystem:

$ sync; lp=$(sudo losetup --show -fP ./disk)
$ sudo mkfs.vfat -n SOMEDISK "${lp}p1"

Results:

$ lsblk -o NAME,FSTYPE,LABEL,PARTUUID "$lp"

NAME      FSTYPE LABEL    PARTUUID       
loop0                                
└─loop0p1 vfat   SOMEDISK f509e1d4-32bc-4a7d-9d47-b8ed0f280b36  

Now, to change that. First, destroy the block dev:

$ sudo losetup -d "$lp"

Now, edit the GPT:

$ gdisk ./disk

GPT fdisk (gdisk) version 0.8.10
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
Found valid GPT with protective MBR; using GPT.

i gives extended info about a single partition. Had I more than one partition, I would next be prompted to enter its partition number. The same goes for the c command later.

Command (? for help): i
Using 1
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: F509E1D4-32BC-4A7D-9D47-B8ED0F280B36
First sector: 2048 (at 1024.0 KiB)
Last sector: 1023966 (at 500.0 MiB)
Partition size: 1021919 sectors (499.0 MiB)
Attribute flags: 0000000000000000
Partition name: 'Linux filesystem'

x is the xperts menu.

Command (? for help): x

c for change PARTUUID.

Expert command (? for help): c
Using 1
Enter the partition's new unique GUID ('R' to randomize): F509E1D4-32BC-4A7D-9D47-B00B135D15C5                  
New GUID is F509E1D4-32BC-4A7D-9D47-B00B135D15C5

w writes out the changes to disk (or, in this case, to my image file).

Expert command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to ./disk.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

$ sync; lp=$(sudo losetup --show -fP ./disk)

The results:

$ lsblk -o NAME,FSTYPE,LABEL,PARTUUID "$lp"

NAME      FSTYPE LABEL    PARTUUID
loop0                     
└─loop0p1 vfat   SOMEDISK f509e1d4-32bc-4a7d-9d47-b00b135d15c5
3
  • do I have to use 'w' to make the change of UUID take effect? If so, will this delete the data on the partition?
    – Wlad
    Aug 26, 2018 at 14:09
  • @Tset the GPT data is not written out to the partition header until the 'w'rite command is read. if the header is overwritten it can be as easily rewritten again. copying a backup is both advised and facilitated with the tools described. anyway, try rtfm.
    – mikeserv
    Aug 28, 2018 at 12:05
  • 1
    I gave it a try and I can confirm now that it does not delete the data. Also thank u for pointing me to RTFM - always love to learn new abbreviations ;-)
    – Wlad
    Aug 28, 2018 at 14:14
0

gdisk can only change the partition UUID (in the GPT). The volume ID of the HFS+ volume is something different. It comes from a 64-bit VSDB volume id in the FinderInfo. macOS converts that into a version 3 UUID to represent the Volume UUID. The FinderInfo is in the Volume Header for HFS+ or Master Directory Block for HFS. The bless --info command can be used to view the FinderInfo. I don't know how to edit the FinderInfo other than with dd.

bless --info /Volumes/Apps | grep id  
64-bit VSDB volume id:  0xB91C7A94DEF081CF

diskutil info /Volumes/Apps | grep "Volume UUID"
   Volume UUID:               A88791EF-94F3-3A71-95C4-4ECB25072EEA

vsdbtouuid () {
    local theuuid=""
    theuuid=$(printf "b3e20f39f29211d697a400306543ecac%s" "$1" | xxd -p -r | md5 | tr "a-f" "A-F" )
    printf "%s" "${theuuid:0:8}-${theuuid:8:4}-3${theuuid:13:3}-$(printf "%X" $(((0x${theuuid:16:1} & 3) | 8)))${theuuid:17:3}-${theuuid:20:12}"
}

vsdbtouuid B91C7A94DEF081CF
A88791EF-94F3-3A71-95C4-4ECB25072EEA

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .