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+?

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

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
  • 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 '18 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 '18 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 '18 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.