Linux Gdisk Error

2025-02-06 linux

今天在實驗室中擴充一顆虛擬硬碟到 150 G,原先是 50G。但是不管是重新開機都無法識別。

後來發現 GPT 分割表未更新,如下

root@moniter:~# fdisk -l /dev/sda
GPT PMBR size mismatch (104857599 != 314572799) will be corrected by write.
The backup GPT table is not on the end of the device.
Disk /dev/sda: 150 GiB, 161061273600 bytes, 314572800 sectors
Disk model: QEMU HARDDISK   
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: 7F238892-1C86-461A-8E79-62365FFA4746

Device     Start       End   Sectors Size Type
/dev/sda1   2048 104855551 104853504  50G Linux filesystem

以下是處理方式

gdisk /dev/sda
x   # 進入 expert mode
e   # 修正 GPT 表到磁碟正確大小
w   # 寫入變更並退出

以下是處理過程

root@moniter:~# gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.9

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): x

Expert command (? for help): e
Relocating backup data structures to the end of the disk

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 /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.
root@moniter:~# fdisk -l /dev/sda

以下是處理結果

root@moniter:~# fdisk -l /dev/sda
Disk /dev/sda: 150 GiB, 161061273600 bytes, 314572800 sectors
Disk model: QEMU HARDDISK   
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: 7F238892-1C86-461A-8E79-62365FFA4746

Device     Start       End   Sectors Size Type
/dev/sda1   2048 104855551 104853504  50G Linux filesystem