잘못된 인수로 인해 파티션 fdisk 크기 조정이 실패함

잘못된 인수로 인해 파티션 fdisk 크기 조정이 실패함

최근에 호스팅 업체의 제어판을 통해 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로 늘었으니 이전보다 6배 정도 커진 건 당연해 보입니다. 그래서 나는 힌트를 따라 표를 작성하기로 결정했습니다 ...

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를 설치했고 실행했을 때 파티션 테이블이 전체 디스크를 포함하지 않는다는 것을 알려주었습니다(duh). 그래서 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를 종료하고 표준 절차에 따라 파일 시스템의 크기를 조정합니다(예: ext4의 e2fsck -f경우 resize2fs). 원시 디스크 이미지 파일(예: QEMU용)로 작업하는 경우 해당 루프 장치에서 실행할 수 kpartx -av disk.img있도록 파티션용 루프 장치를 가져오는 데 사용할 수 있습니다 .e2fsckresize2fs

답변3

문제는 보호 MBR(PMBR)이 너무 작다는 것입니다. 다음을 사용하여 보호 MBR을 변경할 수 있습니다.

  1. x추가 기능을 위해
  2. M보호/하이브리드 MBR로 들어가려면
  3. ( p보호 MBR 표시 허용)
  4. r메인 메뉴로 돌아가려면(여전히 보호 MBR 모드에 있습니다!)
  5. d잘못된 크기의 보호 MBR 파티션을 삭제하려면
  6. n새 파티션을 생성하고 enter기본 설정을 적용하려면 4배(기본, 파티션 번호 1 및 전체 크기)
  7. tee유형을 GPT로 변경 하려면
  8. x추가 기능을 위해
  9. M보호/하이브리드 MBR 모드를 종료하려면
  10. r메인 메뉴로 돌아가려면 (이제 다시 GPT 모드에 있음)
  11. w쓰기

이를 통해 GPT PMBR 크기 불일치를 해결할 수 있습니다.

O디스크 레이블 문제를 해결하려면 내 보낸 스크립트의 last-lba를 사용하여 파티션 테이블을 덤프하고 에서 보고된 디스크 크기 fdisk(보조 GPT의 경우)에서 34를 뺀 디스크 크기로 변경해야 했습니다. 그런 다음 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

그런 다음 디스크와 파티션이 새 크기로 적절하게 커집니다.

이게 도움이 되길 바란다.

관련 정보