Centos扩容
CVM存储在 /var
下,虽然固态硬盘大部分存储空间,都给了 /var
,但是虚拟机多一点,就担心空间不足。于是便通过以下步骤对 /var
进行扩容。
更新--查看磁盘分区情况:
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 447.1G 0 disk
├─sda1 8:1 0 50M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 446.1G 0 part
├─centos00-root 253:0 0 80G 0 lvm /
├─centos00-swap 253:1 0 64G 0 lvm [SWAP]
└─centos00-var 253:2 0 742.1G 0 lvm /var
sdb 8:16 0 447.1G 0 disk
└─centos00-var 253:2 0 742.1G 0 lvm /var
sdc 8:32 0 447.1G 0 disk
-
查看分区
[root@localhost ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 40G 3.9G 37G 10% / devtmpfs devtmpfs 12G 0 12G 0% /dev tmpfs tmpfs 12G 0 12G 0% /dev/shm tmpfs tmpfs 12G 33M 12G 1% /run tmpfs tmpfs 12G 0 12G 0% /sys/fs/cgroup /dev/sdc2 xfs 497M 155M 343M 32% /boot /dev/sdc1 vfat 50M 12M 39M 23% /boot/efi /dev/mapper/centos-var xfs 375G 254G 121G 68% /var # 大小 375G tmpfs tmpfs 2.4G 0 2.4G 0% /run/user/0
-
查看磁盘编号
也可以使用
fdisk -l
查看磁盘信息。其中/dev/sdb
是用于扩容的磁盘。[root@localhost ~]# ls /dev/sd* /dev/sda /dev/sdb /dev/sdc /dev/sdc1 /dev/sdc2 /dev/sdc3
-
创建pv
[root@localhost ~]# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created.
-
查看vg组
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 3 0 wz--n- <446.59g 0 # 此时vfree为0
-
扩展vg
[root@localhost ~]# vgextend centos /dev/sdb Volume group "centos" successfully extended
-
再次查看vg组
[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 3 0 wz--n- <1.35t 931.51g # 此时vfree为 931.51g
-
扩展lv(+500G)
[root@localhost ~]# lvextend -L +500G /dev/mapper/centos-var Size of logical volume centos/var changed from <374.59 GiB (95895 extents) to <874.59 GiB (223895 extents). Logical volume centos/var successfully resized.
-
系统重新读取大小
[root@localhost ~]# xfs_growfs /dev/mapper/centos-var meta-data=/dev/mapper/centos-var isize=256 agcount=4, agsize=24549120 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 spinodes=0 data = bsize=4096 blocks=98196480, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=47947, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 98196480 to 229268480
-
查看扩容是否成功
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 40G 3.9G 37G 10% / devtmpfs 12G 0 12G 0% /dev tmpfs 12G 0 12G 0% /dev/shm tmpfs 12G 33M 12G 1% /run tmpfs 12G 0 12G 0% /sys/fs/cgroup /dev/sdc2 497M 155M 343M 32% /boot /dev/sdc1 50M 12M 39M 23% /boot/efi /dev/mapper/centos-var 875G 254G 621G 30% /var # 大小 375G + 500G = 875G tmpfs 2.4G 0 2.4G 0% /run/user/0