VMware不关机扩容linux磁盘

来自三线的随记
Admin讨论 | 贡献2023年3月6日 (一) 19:11的版本

lvm类型的分区

  1. vm层面完成磁盘扩容
  2. 有时候会碰到vm无法感知到disk容量变化的情况出现,这时候需要手动rescan一下 echo 1 > /sys/class/block/sda/device/rescan
  3. fdisk -l /dev/sda
  4. 使用fdisk /dev/sda 删除重建需要扩容的分区(增大分区容量,保留原本的LVM2_member signature, 起始扇区与原本一致)
  5. partprobe /dev/sda
  6. pvresize /dev/sda3
  7. lvextend /dev/cl/root /dev/sda3
  8. xfs_growfs /dev/mapper/cl-root
  9. 完成。。

vm disk as mount point

  1. vm层面完成磁盘扩容
  2. 同样手动rescan一下 echo 1 > /sys/class/block/sda/device/rescan
  3. 根据文件系统类型执行fs扩容,如xfs_growfs / resize2fs
  4. 例如⬇️
[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@dce-192-168-157-39 ~]# echo 1 > /sys/class/block/sdb/device/rescan
[root@dce-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 ~]#

额外延伸:How to scan\detect new LUN’s & SCSI disks in Linux?