创建LVM12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152# 创建物理卷[root@localhost ~]# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created.# 创建卷组[root@localhost ~]# vgcreate vg_example /dev/sdb Volume group "vg_example" successfully created[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <15.00g 0 vg_example 1 0 0 wz--n- <10.00g <10.00g# 创建逻辑组[root@localhost ~]# lvcreate -l 100%free -n lv_example vg_example Logical volume "lv_example" created.[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <15.00g 0 vg_example 1 1 0 wz--n- <10.00g 0[root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 13.39g swap centos -wi-ao---- 1.60g lv_example vg_example -wi-a----- <10.00g# 格式化逻辑组[root@localhost ~]# mkfs.xfs /dev/vg_example/lv_examplemeta-data=/dev/vg_example/lv_example isize=512 agcount=4, agsize=655104 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0data = bsize=4096 blocks=2620416, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0[root@localhost ~]# blkid grep vg_example/dev/mapper/vg_example-lv_example: UUID="83b3262d-d7d1-429e-ab04-67022e91865a" TYPE="xfs"# 创建挂载点[root@localhost ~]# mkdir /data[root@localhost ~]# cat /etc/fstab/dev/mapper/centos-root / xfs defaults 0 0UUID=95ef0912-08e6-4fc9-9dc1-179e47ffe304 /boot xfs defaults 0 0/dev/mapper/centos-swap swap swap defaults 0 0UUID=83b3262d-d7d1-429e-ab04-67022e91865a /data xfs defaults 0 0[root@localhost ~]# mount -a[root@localhost ~]# df -Th grep /data/dev/mapper/vg_example-lv_example xfs 10G 33M 10G 1% /data 扩容LVM12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455# 磁盘扩容10G[root@localhost ~]# fdisk -l /dev/sdbDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes# PV扩容[root@localhost ~]# pvresize /dev/sdb Physical volume "/dev/sdb" changed 1 physical volume(s) resized or updated / 0 physical volume(s) not resized[root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- <15.00g 0 /dev/sdb vg_example lvm2 a-- <20.00g 10.00g# VG自动扩容[root@localhost ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <15.00g 0 vg_example 1 1 0 wz--n- <20.00g 10.00g# LV扩容# 因为磁盘换算问题导致失败[root@localhost ~]# lvextend -L +10G /dev/vg_example/lv_example Insufficient free space: 2560 extents needed, but only 2559 available[root@localhost ~]# lvextend -L +9.99G /dev/vg_example/lv_example Rounding size to boundary between physical extents: 9.99 GiB. Size of logical volume vg_example/lv_example changed from 10.00 GiB (2560 extents) to 19.99 GiB (5118 extents). Logical volume vg_example/lv_example successfully resized.[root@localhost ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 13.39g swap centos -wi-ao---- 1.60g lv_example vg_example -wi-ao---- 19.99g # 文件系统扩容[root@localhost ~]# xfs_growfs /dev/vg_example/lv_example meta-data=/dev/mapper/vg_example-lv_example isize=512 agcount=4, agsize=655104 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=2620416, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 2620416 to 5240832[root@localhost ~]# df -Th grep /data/dev/mapper/vg_example-lv_example xfs 20G 33M 20G 1% /data# 扩容完成 使用xfs文件格式只能扩容磁盘,使用EXT4格式才能扩容和缩减磁盘。