VMware不关机扩容linux磁盘
来自三线的随记
注意在部分OS下,可能在扩容前 Disk 的相关 partition 信息在fdisk中是可以正常识别的,但是在 vsphere / esxi 对磁盘进行扩容以后
就发现 partition 丢了(特别是centos7.9 + fdisk -l + GPT)
这时候可以直接 parted /dev/sda
进入以后应该就会提示
Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)?
直接进行Fix并扩容即可
也找到原本的扇区记录,然后进入fdisk ,修改 partition table 为 GPT,根据相关扇区记录,把分区重新建立回来即可
lvm类型的分区
传统步骤扩容分区
- vm层面完成磁盘扩容
- 有时候会碰到vm无法感知到disk容量变化的情况出现,这时候需要手动rescan一下
echo 1 > /sys/class/block/sda/device/rescan
fdisk -l /dev/sda
- 使用fdisk /dev/sda 删除重建需要扩容的分区(增大分区容量,保留原本的LVM2_member signature, 起始扇区与原本一致)
partprobe /dev/sda
pvresize /dev/sda3
lvextend /dev/cl/root /dev/sda3
xfs_growfs /dev/mapper/cl-root
- 完成。。
Partition Resize In One Line
parted /dev/sda --script -- resizepart 3 100%
xfs_growfs /dev/xxxxxxxxx
vm disk as mount point
- vm层面完成磁盘扩容
- 同样手动rescan一下
echo 1 > /sys/class/block/sda/device/rescan
- 根据文件系统类型执行fs扩容,如
xfs_growfs
/resize2fs
- 例如⬇️
[root@192-168-157-39 ~]# lsblk /dev/sdb NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 150G 0 disk /var/lib/containers [root@192-168-157-39 ~]# echo 1 > /sys/class/block/sdb/device/rescan [root@192-168-157-39 ~]# lsblk /dev/sdb NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 155G 0 disk /var/lib/containers [root@192-168-157-39 ~]# cat /etc/fstab |grep cont /dev/sdb /var/lib/containers xfs defaults,pquota 0 0 [root@192-168-157-39 ~]# xfs_growfs /dev/sdb meta-data=/dev/sdb isize=512 agcount=4, agsize=9830400 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=39321600, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=19200, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 39321600 to 40632320 [root@192-168-157-39 ~]# df -h /var/lib/containers Filesystem Size Used Avail Use% Mounted on /dev/sdb 155G 19G 137G 12% /var/lib/containers [root@192-168-157-39 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1019M 0 part /boot └─sda2 8:2 0 49G 0 part └─centos-root 253:0 0 49G 0 lvm / sdb 8:16 0 155G 0 disk /var/lib/containers sr0 11:0 1 9.5G 0 rom [root@192-168-157-39 ~]#