我在尝试扩展磁盘时遇到了一些问题。我在 ESXi 主机上使用 VMware Debian 9 虚拟机。
将虚拟磁盘大小扩展 32 GB 并重新启动虚拟机后,我看到:
bob@apollo:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 64G 0 disk
├─sdb1 8:17 0 16G 0 part /var/lib/jenkins
└─sdb2 8:18 0 16G 0 part /var/www
bob@apollo:~$ mount | grep sdb
/dev/sdb2 on /var/www type ext4 (rw,relatime,data=ordered)
/dev/sdb1 on /var/lib/jenkins type ext4 (rw,relatime,data=ordered)
bob@apollo:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).
GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).
Command (m for help): p
Disk /dev/sdb: 64 GiB, 68719476736 bytes, 134217728 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: 513133B6-1030-427A-8950-E43374665229
Device Start End Sectors Size Type
/dev/sdb1 2048 33554431 33552384 16G Linux filesystem
/dev/sdb2 33554432 67106815 33552384 16G Linux filesystem
我从潜伏在这个网站上学到的技巧是使用 fdisk 删除分区并创建一个新的更大的分区。我希望必要的写入也能解决我在 fdisk 中看到的 GPT PMBR 大小不匹配问题。
bob@apollo:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).
GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
Command (m for help): n
Partition number (2-128, default 2): 2
First sector (33554432-67108830, default 33554432):
Last sector, +sectors or +size{K,M,G,T,P} (33554432-67108830, default 67108830): 134217728
Value out of range.
Last sector, +sectors or +size{K,M,G,T,P} (33554432-67108830, default 67108830):
Created a new partition 2 of type 'Linux filesystem' and of size 16 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
Command (m for help): w
GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).
fdisk: failed to write disklabel: Invalid argument
bob@apollo:~$
这里发生了很多事情
- /dev/sdb 现在有 134,217,728 个扇区。但“有效范围”仅上升到原来的 67,108,830。
- 当我“重新创建”分区 2 及其原始大小并尝试写入更改时,fdisk 崩溃并显示“无效参数”。
如何扩大音量
答案1
fdisk
不擅长处理 GPT 表。首先使用以下方法修复 GPT 表parted
:
bob@apollo:~$ sudo parted -l
Warning: Not all of the space available to /dev/sdb appears to be used, you can
fix the GPT to use all of the space (an extra 67108864 blocks) or continue with
the current setting?
Fix/Ignore? F
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 68.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 17.2GB 17.2GB ext4 primary
2 17.2GB 34.4GB 17.2GB ext4 primary
其次,停止访问这些磁盘的所有服务并卸载该磁盘:
bob@apollo:~$ sudo systemctl stop jenkins.service
bob@apollo:~$ sudo systemctl stop apache2.service
bob@apollo:~$ sudo umount /dev/sdb1
bob@apollo:~$ sudo umount /dev/sdb2
第三,按您最初的意图扩展分区:
bob@apollo:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sdb: 64 GiB, 68719476736 bytes, 134217728 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: 513133B6-1030-427A-8950-E43374665229
Device Start End Sectors Size Type
/dev/sdb1 2048 33554431 33552384 16G Linux filesystem
/dev/sdb2 33554432 134217694 100663263 48G Linux filesystem
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
Command (m for help): n
Partition number (2-128, default 2): 2
First sector (33554432-134217694, default 33554432):
Last sector, +sectors or +size{K,M,G,T,P} (33554432-134217694, default 134217694):
Created a new partition 2 of type 'Linux filesystem' and of size 48 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
令人惊讶的是,您不需要从 重新挂载任何东西/dev/sdb
,只需在写入 /dev/sdb 后即可完成。如果您查看挂载点,数据应该仍在那里。重新启动您的服务以使一切恢复正常。