我最近需要克隆我的硬盘(坏块 FTW)。当时我正在使用 Clonezilla。
但是,Clonezilla 拒绝复制 HFS+ 分区,所以我手动完成了。问题是 UUID 不同步。
为 HFS+ 设置特定 UUID 的命令是什么?
答案1
首先我将创建一个500M的图像文件:
$ cd /tmp
$ fallocate -l $((1024*1024*500)) ./disk
现在我给它一个 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
用于创建新的 GPT。
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y
n
用于创建新分区。之后我只需按 Enter 键即可选择所有默认值。
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
将更改写入磁盘。
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)
$ sudo mkfs.vfat -n SOMEDISK "${lp}p1"
结果:
$ lsblk -o NAME,FSTYPE,LABEL,PARTUUID "$lp"
NAME FSTYPE LABEL PARTUUID
loop0
└─loop0p1 vfat SOMEDISK f509e1d4-32bc-4a7d-9d47-b8ed0f280b36
现在,要改变这一点。首先,销毁块开发:
$ sudo losetup -d "$lp"
现在,编辑 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
提供有关单个分区的扩展信息。如果我有多个分区,接下来会提示我输入其分区号。后面的命令也是如此c
。
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
是x
perts 菜单。
Command (? for help): x
c
用于更改 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
将更改写入磁盘(或者,在本例中,到我的图像文件)。
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)
结果:
$ lsblk -o NAME,FSTYPE,LABEL,PARTUUID "$lp"
NAME FSTYPE LABEL PARTUUID
loop0
└─loop0p1 vfat SOMEDISK f509e1d4-32bc-4a7d-9d47-b00b135d15c5
答案2
gdisk 只能更改分区 UUID(在 GPT 中)。 HFS+ 卷的卷 ID 有所不同。它来自 FinderInfo 中的 64 位 VSDB 卷 ID。 macOS 将其转换为版本 3 UUID 以表示卷 UUID。 FinderInfo 位于 HFS+ 的卷标头或 HFS 的主目录块中。该bless --info
命令可用于查看FinderInfo。我不知道如何编辑 FinderInfo 除了使用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