Cloning

從 PartedMagic 更改 HFSPlus UUID

  • October 8, 2018

我最近需要複製我的硬碟驅動器(壞塊 FTW)。我當時正在使用 Clonezilla。

但是,Clonezilla 拒絕複製 HFS+ 分區,所以我手動進行了。問題是 UUID 不同步。

為 HFS+ 設置特定 UUID 的命令是什麼?

首先,我將創建一個 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'

xxperts 菜單。

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

引用自:https://unix.stackexchange.com/questions/154171