LVM基本操作

大道之行,天下为公。这篇文章主要讲述LVM基本操作相关的知识,希望能为你提供帮助。
LVM(Logical Volume Manager)

功能/命令
物理卷管理
卷管理
逻辑卷管理
扫描
pvscan
vgscan
lvscan
建立
pvcreate
vgcreate
lvcreate
显示
pvdisplay|pvs
vgdisplay|vgs
lvdisplay|lvs
删除
pvremove
vgremove
lvremove
扩容
-
vgextend
lvextend
缩小
-
vgreduce
lvreduce
创建LVM
  • 物理卷初始化
$ pvcreate /dev/sdb1 /dev/sdc2
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdc2" successfully created.

  • 查看可用作物理卷的块设备
$lvmdiskscan
/dev/centos/root [46.99 GiB]
/dev/sda1[1.00 GiB]
/dev/centos/swap [2.00 GiB]
/dev/sda2[< 49.00 GiB] LVM physical volume
/dev/sdb1[50.00 GiB] LVM physical volume
/dev/sdb2[< 50.00 GiB]
/dev/sdc1[20.00 GiB]
/dev/sdc2[< 30.00 GiB] LVM physical volume
2 disks
3 partitions
0 LVM physical volume whole disks
3 LVM physical volumes

  • 创建卷组
$ vgcreate tmp /dev/sdb1
Volume group "tmp" successfully created
$ vgs
VG#PV #LV #SN AttrVSizeVFree
centos120 wz--n- < 49.00g4.00m
data210 wz--n-49.99g < 48.00g
tmp110 wz--n- < 50.00g < 49.00g

  • 创建逻辑卷
$ lvcreate -n backup -L 1G tmp
Logical volume "backup" created.
$ lvs
LVVGAttrLSizePool Origin Data%Meta%Move Log Cpy%Sync Convert
rootcentos -wi-ao---- 46.99g
swapcentos -wi-ao----2.00g
datadata-wi-ao---- < 2.00g
backup tmp-wi-a-----1.00g

$ lvcreate -n backup -l +100%VG

  • 挂载逻辑卷
$ mkfs.xfs /dev/tmp/backup
$ mount /dev/tmp/backup /backup/
$ df -h /backup
文件系统容量已用可用 已用% 挂载点
/dev/mapper/tmp-backup 1014M33M982M4% /backup

扩容卷组有空间
$ umount /backup# 卸载磁盘
$ lvextend -L +1G --resizefs /dev/tmp/backup# 扩容1G空间
$ lvs # 查看逻辑卷
LVVGAttrLSizePool Origin Data%Meta%Move Log Cpy%Sync Convert
rootcentos -wi-ao---- 46.99g
swapcentos -wi-ao----2.00g
datadata-wi-ao---- < 2.00g
backup tmp-wi-a-----2.00g
$ lvextend -l +100%FREE --resizefs /dev/tmp/backup# 把卷组所有剩余空间扩展给backup逻辑卷
$ lvs
LVVGAttrLSizePool Origin Data%Meta%Move Log Cpy%Sync Convert
rootcentos -wi-ao----46.99g
swapcentos -wi-ao----2.00g
datadata-wi-ao----< 2.00g
backup tmp-wi-a----- < 50.00g

卷组没有空间
# 添加磁盘
$ umount /backup
$ pvcreate /dev/sdd
$ vgextend tmp /dev/sdd
$ lvextend -L +1G /dev/tmp/backup
$ lvs

扩容根分区
$ pvcreate /dev/sdx
$ vgextend centos /dev/sdx
$ lvextend -l +100%FREE /dev/centos/root
$ xfs_growfs /dev/centos/root

更新硬盘
# /dev/sdx # 磁盘切换 /dev/sdz 替换/dev/sdx,sdz空间大于等于sdx。
$ pvcreate /dev/sdz
$ vgextend centos /dev/sdz
$ pvmove /dev/sdx /dev/sdz
$ vgreduce centos /dev/sdx

【LVM基本操作】


    推荐阅读