
我最近透過主機代管商的控制面板將 VPS 從 50GB SSD 調整為 300GB SSD。我現在正在嘗試使用 fdisk 調整主分割區的大小,以便能夠使用所有新空間。然而,fdisk 在啟動時給了我一個警告:
GPT PMBR size mismatch (104857599 != 629145599) will be corrected by w(rite).
GPT PMBR size mismatch (104857599 != 629145599) will be corrected by w(rite).
很明顯,它的大小是以前的六倍,因為我從 50GB 增加到了 300GB。所以,我決定按照提示寫表......
Command (m for help): w
GPT PMBR size mismatch (104857599 != 629145599) will be corrected by w(rite).
fdisk: failed to write disklabel: Invalid argument
..這不起作用。儘管有很多搜尋查詢,但我無法在任何地方找到導致該錯誤的原因。我不使用 LVM,我的分區表如下所示:
Disk /dev/vda: 300 GiB, 322122547200 bytes, 629145600 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: gpt
Disk identifier: 30D92031-0C13-42FF-AC16-D34F36DD3907
Device Start End Sectors Size Type
/dev/vda1 2048 32767 30720 15M BIOS boot
/dev/vda2 32768 16809983 16777216 8G Linux swap
/dev/vda3 16809984 104857566 88047583 42G Linux filesystem
請注意磁碟如何將其顯示為 300GiB,因此它確實識別了大小變更。
答案1
我設法相當簡單地解決了這個問題。我安裝了parted,當我運行時,它告訴我分區表沒有覆蓋整個磁碟(廢話),所以它問我,Fix/Cancel
我用Fix
.顯然,這成功了,因為我能夠使用將分割區修改為完整大小sudo fdisk /dev/vda
,但之後我確實需要運行sudo resize2fs /dev/vda3
才能應用更改。
答案2
當我嘗試擴大 GPT 分區時,這對我有用。與往常一樣,在更改分區表時,備份至關重要,以防更改未按計劃進行。
首先,並非所有 fdisk 都是一樣的。在 Ubuntu 18.04 上,這是我使用的 fdisk 版本:
$ fdisk -v
fdisk from util-linux 2.31.1
啟動 fdisk。使用“p”列印分區表並驗證現有分區表是 GPT:
Disklabel type: gpt
將分區資訊複製並貼上到另一個窗口,以便您可以使用完全相同的起始扇區重新建立分區。
按下「g」將舊的 GPT 分割區表替換為新的 GPT 分割區表。
再次按“p”列印出新的表格訊息,以驗證它現在顯示更大的尺寸。
按“n”重新建立分區。所有分割區都必須使用完全相同的起始磁區和最後磁區重新創建,最後一個分割區除外,它必須具有相同的起始磁區,但可以有較大的結束磁區。
如果您的分割區上有檔案系統,您應該看到如下內容:
Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: N
回應“N”,因為您想保留檔案系統簽名。
返回 fdisk 提示符,再次鍵入“p”查看表格以確認一切看起來都正常。
輸入“w”來寫入(提交)更改。
從那裡退出 fdisk 並按照標準流程調整檔案系統的大小(例如,e2fsck -f
如果resize2fs
是 ext4)。如果您正在使用原始磁碟映像檔(即,用於 QEMU),那麼您可以使用kpartx -av disk.img
來取得分割區的循環設備,以便您可以在這些循環設備上運行e2fsck
和。resize2fs
答案3
問題在於保護性MBR (PMBR) 太小。您可以使用以下方法變更保護性 MBR:
x
用於額外功能M
進入保護性/混合MBR- (
p
允許顯示保護性 MBR) r
返回主選單(仍處於保護性 MBR 模式!)d
刪除大小錯誤的保護性 MBR 分割區n
建立一個新分割區並 4xenter接受預設設定(主分割區、分割區號 1 和完整大小)t
並將ee
類型更改為 GPTx
用於額外功能M
離開保護/混合 MBR 模式r
返回主選單(現在再次處於 GPT 模式)w
來寫
這樣我就可以修復 GPT PMBR 大小不符的問題。
為了解決磁碟標籤問題,我必須使用轉儲分割區表,O
並將匯出腳本中的last-lba變更為磁碟大,如 中報告的fdisk
,負34(對於輔助GPT)。然後我使用重新導入腳本I
。
答案4
我用 gdisk 解決了這個問題。這是我所做的:
sudo fdisk --list
GPT PMBR size mismatch (41943039 != 62914559) will be corrected by w(rite).
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 62D6A220-B955-44BE-9730-CC89FE5CA928
# Naive fix attempt:
sudo fdisk /dev/sda
w
# ^^ fails with:
# GPT PMBR size mismatch (62914559 != 83886079) will be corrected by w(rite).
# fdisk: failed to write disklabel: Invalid argument
# try (because it is a GPT disk?)
viradmin@instance-2:~$ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): ?
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu
Command (? for help): w
Warning! Secondary header is placed too early on the disk! Do you want to
correct this problem? (Y/N): y
Have moved second header and partition table to correct location.
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 /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
# then
sudo reboot
然後我還做了以下操作,因為這是在 Google Cloud 中的 Ubuntu 機器上(按照指南https://slacker.ro/2019/07/17/how-to-increase-google-cloud-virtual-machine-disk-size/):
sudo apt install -y cloud-guest-utils
sudo growpart /dev/sda 1
sudo resize2fs /dev/sda1
stage@instance-2:/$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 30308240 16684136 13607720 56% /
# fixed:
sudo fdisk --list
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 62D6A220-B955-44BE-9730-CC89FE5CA928
Device Start End Sectors Size Type
/dev/sda1 227328 83886046 83658719 39.9G Linux filesystem
/dev/sda14 2048 10239 8192 4M BIOS boot
/dev/sda15 10240 227327 217088 106M EFI System
之後,磁碟和分割區正確成長到新的大小:
我希望這有幫助。