將修改後的 GPT 分割區映射儲存到 GParted 或類似工具中的文件

將修改後的 GPT 分割區映射儲存到 GParted 或類似工具中的文件

我可以用來sgdisk -b /dev/sdx將磁碟的 GPT 分割區映射儲存到檔案中。我想為具有一定大小的一個分割區的 GPT 產生這樣一個檔案。我認為執行此操作的唯一方法是在 GParted 等工具中實際格式化磁碟,然後用於gdisk保存 GPT。

有沒有辦法(最好是在 GParted 中)使用我想要的分割區設定 GPT 表,然後將其儲存到檔案而不是寫入磁碟?

其他不需要的選項:

  • 手動編輯轉儲sgdisk。要把事情做好太難了。
  • 建立所需大小的 VirtualBox 磁碟,對其進行格式化,然後使用sgdisk.我想要的 440GiB 磁碟將花費很長時間。編輯:實際上,如果我使用動態分配的虛擬磁碟,這很快,但這是一個笨拙的解決方案。

答案1

我了解您的問題與分區表和分區有關,而不是與資料有關。如果這是正確的,那麼您的答案已經在parted和的手冊頁中這裡

parted本質上創建一個創建 gpt 方案所需命令的腳本,然後

parted --script /dev/sdx [script commands]

可以將其放入 shell 腳本中並根據需要執行,或許可以將設備作為參數傳遞給腳本。

評論後編輯:根據該man sgdisk頁面,要取得「幻像」磁碟的 sgdisk 輸出,請使用「-P」選項,該選項在記憶體中執行任務,但不會將變更提交到磁碟。

我剛剛用 USB 嘗試過,它似乎可以工作

sudo sgdisk -p /dev/sdb

Disk /dev/sdb: 31653888 sectors, 15.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2016C547-548B-482E-8810-A5E7A1466CED
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 31653854
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        31651839   15.1 GiB    0700  IDEA    #old name


sudo sgdisk -P -c 1:random -p /dev/sdb                           #change the name

Setting name!
partNum is 0
REALLY setting name!
Disk /dev/sdb: 31653888 sectors, 15.1 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 2016C547-548B-482E-8810-A5E7A1466CED
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 31653854
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        31651839   15.1 GiB    0700  random   #name changed

重新執行

sudo sgdisk -p /dev/sdb


Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        31651839   15.1 GiB    0700  IDEA    #change not written

這一變化也反映在輸出中

sudo sgdisk -P -c 1:random --backup=phantomDisk /dev/sdb

相關內容