如何修復 GPT 磁碟 (/dev/sdaX) 上的分割區數量

如何修復 GPT 磁碟 (/dev/sdaX) 上的分割區數量

我使用 Gparted 刪除了輔助磁碟機上的 EFI (/dev/sda1) 和 Ubuntu (/dev/sda2) 分割區。第三個分割區 (/dev/sda3) 用於數據,因此我調整了它的大小,以便透過刪除前兩個分割區來使用我獲得的所有未分配空間。現在,磁碟上只有一個唯一的分割區,我想修復它的編號,以獲得 /dev/sda1。對於具有 GPT 分割區表的磁碟,最簡單的方法是什麼?謝謝你!

答案1

您可以使用gdisk重寫分區表:

sudo gdisk /dev/sda
p(p 指令在螢幕上列印最近的分割表)
s(s 指令對分區表條目進行排序)
p(再次使用 p 指令在螢幕上查看結果)
w(將更改的分割表寫入磁碟)
q(退出 gdisk)

您將在以下位置找到最有用的信息gdiskhttp://www.rodsbooks.com/gdisk/

答案2

出於對最後一個連結的興趣並熱衷於學習新知識,我使用 32GB USB 驅動器在我的系統上重播了 Generoso 的分區情況。以下是我的發現,但首先是我的:

結論:由於我的範例針對 1 個(最終)分區,因此在接近尾聲時我只是更改了其名稱。我沒有觸及實際的扇區。在我上面評論中的連結中,顯示了一個範例,其中扇區號被移動。我也照著做,結果慘遭誤操作,毀掉了U盤,這證明玩弄分區是多麼危險!
也許我的場景也適用於多個分割區,您可以自己嘗試。我敢說你用你的主分割區來做它..哈哈。
好的,這是我的:

結果:我使用 Gparted 建立了 3 個分割區,每個分割區 1 GB。

# fdisk -l /dev/sdc
Disk /dev/sdc: 30 GiB, 32176472064 bytes, 62844672 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf33657fc

Device     Boot   Start     End Sectors Size Id Type
/dev/sdc1          2048 2099199 2097152   1G 83 Linux
/dev/sdc2       2099200 4196351 2097152   1G 83 Linux
/dev/sdc3       4196352 6293503 2097152   1G 83 Linux

使用磁碟掛載分割區 3.
手動在其上放置檔案。

# ls -l /media/willem/cd4746ac-6d9f-4057-9396-a593ce2f301d/
total 21436
drwx------ 2 root root    16384 May 27 00:12 lost+found
-rw-r--r-- 1 root root 21930117 May 27 00:14 SomeFile.txt

使用磁碟卸載分割區
3。

# fdisk -l /dev/sdc
Disk /dev/sdc: 30 GiB, 32176472064 bytes, 62844672 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf33657fc

Device     Boot Start      End  Sectors Size Id Type
/dev/sdc3        8192 62844671 62836480  30G 83 Linux

使用磁碟掛載分割區3

# ls -l /media/willem/cd4746ac-6d9f-4057-9396-a593ce2f301d/
total 21436
drwx------ 2 root root    16384 May 27 00:12 lost+found
-rw-r--r-- 1 root root 21930117 May 27 00:14 SomeFile.txt

使用磁碟卸載分割區 3.
從磁碟機複製分割區表。
顯示分區表。

# sfdisk -d /dev/sdc > sdc.tab
# cat sdc.tab
label: dos
label-id: 0xf33657fc
device: /dev/sdc
unit: sectors

/dev/sdc3 : start=        8192, size=    62836480, type=83

用於vi sdc.tab將 sdc3 更改為 sdc1。
應用更改後的分區表。

# sfdisk --no-reread -f /dev/sdc < sdc.tab
Disk /dev/sdc: 30 GiB, 32176472064 bytes, 62844672 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf33657fc

Old situation:

Device     Boot Start      End  Sectors Size Id Type
/dev/sdc3        8192 62844671 62836480  30G 83 Linux

>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new DOS disklabel with disk identifier 0xf33657fc.
Created a new partition 1 of type 'Linux' and of size 30 GiB.
/dev/sdc2: 
New situation:

Device     Boot Start      End  Sectors Size Id Type
/dev/sdc1        8192 62844671 62836480  30G 83 Linux

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

指令完成後,分割區 1 就會自動掛載。
檢查文件。

# ls -l /media/willem/cd4746ac-6d9f-4057-9396-a593ce2f301d/
total 21436
drwx------ 2 root root    16384 May 27 00:12 lost+found
-rw-r--r-- 1 root root 21930117 May 27 00:14 SomeFile.txt

使用磁碟卸載分割區 1

附言。我cat SomeFile.txt每次都這樣做,但我覺得沒有必要包含該輸出。

答案3

您應該將 /dev/sda1 的大小調整為大於 /dev/sda3。然後將 sda3 複製到 sda1 上。檔案檢查 sda1,如果沒有問題,刪除 sda3,相應地調整 sda1 的大小。

相關內容