从 PartedMagic 更改 HFSPlus UUID

Kaz*_*lfe 5 cloning uuid hfs+ parted-magic gdisk

我最近需要克隆我的硬盘驱动器(坏块 FTW)。我当时正在使用 Clonezilla。

但是,Clonezilla 拒绝复制 HFS+ 分区,所以我手动完成了。问题是 UUID 不同步。

为 HFS+ 设置特定 UUID 的命令是什么?

mik*_*erv 4

首先我将创建一个500M的图像文件:

\n\n
$ cd /tmp\n$ fallocate -l $((1024*1024*500)) ./disk\n
Run Code Online (Sandbox Code Playgroud)\n\n

现在我将给它一个 GPT:

\n\n
$ gdisk ./disk\n\nGPT fdisk (gdisk) version 0.8.10\n\nPartition table scan:\n  MBR: not present\n  BSD: not present\n  APM: not present\n  GPT: not present\n\nCreating new GPT entries.\n
Run Code Online (Sandbox Code Playgroud)\n\n

o用于创建新的 GPT。

\n\n
Command (? for help): o\nThis option deletes all partitions and creates a new protective MBR.\nProceed? (Y/N): y\n
Run Code Online (Sandbox Code Playgroud)\n\n

n用于创建新分区。之后我只需按 Enter 键即可选择所有默认值。

\n\n
Command (? for help): n\nPartition number (1-128, default 1): 1\nFirst sector (34-1023966, default = 2048) or {+-}size{KMGTP}: \nLast sector (2048-1023966, default = 1023966) or {+-}size{KMGTP}: \nCurrent type is \'Linux filesystem\'\nHex code or GUID (L to show codes, Enter = 8300): \nChanged type of partition to \'Linux filesystem\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

w将更改写入磁盘。

\n\n
Command (? for help): w\n\nFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING\nPARTITIONS!!\n\nDo you want to proceed? (Y/N): y\nOK; writing new GUID partition table (GPT) to ./disk.\nWarning: The kernel is still using the old partition table.\nThe new table will be used at the next reboot.\nThe operation has completed successfully.\n
Run Code Online (Sandbox Code Playgroud)\n\n

现在我将其设置为分区块设备并使用文件系统格式化第一个分区:

\n\n
$ sync; lp=$(sudo losetup --show -fP ./disk)\n$ sudo mkfs.vfat -n SOMEDISK "${lp}p1"\n
Run Code Online (Sandbox Code Playgroud)\n\n

结果:

\n\n
$ lsblk -o NAME,FSTYPE,LABEL,PARTUUID "$lp"\n\nNAME      FSTYPE LABEL    PARTUUID       \nloop0                                \n\xe2\x94\x94\xe2\x94\x80loop0p1 vfat   SOMEDISK f509e1d4-32bc-4a7d-9d47-b8ed0f280b36  \n
Run Code Online (Sandbox Code Playgroud)\n\n

现在,要改变这一点。\n首先,销毁块开发:

\n\n
$ sudo losetup -d "$lp"\n
Run Code Online (Sandbox Code Playgroud)\n\n

现在,编辑 GPT:

\n\n
$ gdisk ./disk\n\nGPT fdisk (gdisk) version 0.8.10\nPartition table scan:\n  MBR: protective\n  BSD: not present\n  APM: not present\n  GPT: present\nFound valid GPT with protective MBR; using GPT.\n
Run Code Online (Sandbox Code Playgroud)\n\n

i提供有关单个分区的扩展信息。如果我有多个分区,接下来会提示我输入其分区号。后面的命令也是如此c

\n\n
Command (? for help): i\nUsing 1\nPartition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)\nPartition unique GUID: F509E1D4-32BC-4A7D-9D47-B8ED0F280B36\nFirst sector: 2048 (at 1024.0 KiB)\nLast sector: 1023966 (at 500.0 MiB)\nPartition size: 1021919 sectors (499.0 MiB)\nAttribute flags: 0000000000000000\nPartition name: \'Linux filesystem\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

xxperts 菜单。

\n\n
Command (? for help): x\n
Run Code Online (Sandbox Code Playgroud)\n\n

c用于更改 PARTUUID。

\n\n
Expert command (? for help): c\nUsing 1\nEnter the partition\'s new unique GUID (\'R\' to randomize): F509E1D4-32BC-4A7D-9D47-B00B135D15C5                  \nNew GUID is F509E1D4-32BC-4A7D-9D47-B00B135D15C5\n
Run Code Online (Sandbox Code Playgroud)\n\n

w将更改写入磁盘(或者在本例中写入我的图像文件)

\n\n
Expert command (? for help): w\n\nFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING\nPARTITIONS!!\n\nDo you want to proceed? (Y/N): y\nOK; writing new GUID partition table (GPT) to ./disk.\nWarning: The kernel is still using the old partition table.\nThe new table will be used at the next reboot.\nThe operation has completed successfully.\n\n$ sync; lp=$(sudo losetup --show -fP ./disk)\n
Run Code Online (Sandbox Code Playgroud)\n\n

结果:

\n\n
$ lsblk -o NAME,FSTYPE,LABEL,PARTUUID "$lp"\n\nNAME      FSTYPE LABEL    PARTUUID\nloop0                     \n\xe2\x94\x94\xe2\x94\x80loop0p1 vfat   SOMEDISK f509e1d4-32bc-4a7d-9d47-b00b135d15c5\n
Run Code Online (Sandbox Code Playgroud)\n