给虚拟机的根目录下,添加40G磁盘空间。
查询当前磁盘情况
~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 8.0G 1.9G 6.2G 24% /
~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
........
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM
添加的磁盘空间分区为sda3
~]# fdisk /dev/sda
......
Command (m for help): n #新建分区
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p #选择 primary
Partition number (3,4, default 3): #需要新建的分区编号,回车为sda3
First sector (20971520-104857599, default 20971520): #分区在磁盘的开始位置,回车默认
Using default value 20971520
Last sector, +sectors or +size{K,M,G} (20971520-104857599, default 104857599): #分区在磁盘的结束位置,回车默认
Using default value 104857599
Partition 3 of type Linux and of size 40 GiB is set
Command (m for help): t #输入t修改分区类型
Partition number (1-3, default 3): #需要修改的分区,回车为sda3
Hex code (type L to list all codes): 8e #输入8e修改分区类型为LVM
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w #配置写入磁盘,并生效
The partition table has been altered!
#运行partprobe命令或者重启主机
查询磁盘
[root@zabbix-3 ~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
......
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM
/dev/sda3 20971520 104857599 41943040 8e Linux LVM #新加入的分区
查询当前vg组
~]# vgdisplay
--- Volume group ---
VG Name centos #当前vg组名
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <9.00 GiB #vg容量
扩展lvm
#新建pv
~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
~]# pvs #查询pv
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <9.00g 0
/dev/sda3 lvm2 --- 40.00g 40.00g #新建的pv
#加入vg组
~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
~]# vgs #查询vg
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz--n- 48.99g <40.00g #新建的pv ,已加入vg组
#扩展lvm卷
~]# lvextend -L +39.9G /dev/mapper/centos-root #此数值应小于新建的pv
Logical volume centos/root successfully resized.
~]# lvs #查询lvm
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <47.99g #根目录挂载的lvm卷已扩展
swap centos -wi-ao---- 1.00g
扩展现有的XFS文件系统
~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 8.0G 1.9G 6.2G 24% / #查询扩展前
~]# xfs_growfs /dev/mapper/centos-root #扩展现有的XFS文件系统
meta-data=/dev/mapper/centos-root isize=512 agcount=24, agsize=524032 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=12450816, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 12450816 to 12579840
~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 48G 1.9G 47G 4% / ##查询扩展后,扩展成功