LVM依赖于内核Device Mapper模块
LV设备文件: /dev/mapper/VG_NAME-LV_NAME
- A layer of abstraction that allows easy manipulation of volumes
- Supports resizing of filesystems
- Allows filesystems to span multiple physical devices
- Block devices are designated as Physical Volumes
- One or more Physical Volumes are used to created a Volume Group
- Volume Groups are defined with Physical Extents of a fixed size
- Logical Volumes are composed of Physical Extents from Volume Group
- Filesystems may be created on Logical Volumes
yum install lvm2 -y # 安装lvm2
pvcreate
pvcreate /dev/PHYSICAL_PARTION

pvs & pvdisplay
pvs # 简要显示
pvdisplay # 详细显示


pvremove
pvremove /dev/PHYSICAL_PATIONSpvmove
pvmove SRC_PV DEST_PVpvscan
pvscan # scan all disks for physical volumes

PE默认大小: 4M
vgcreate
vgcreate [-s PE_SIZE[bBkKmMgG]] VG_NAME PV_NAME

vgs & vgdisplay
vgs # 简要显示
vgdisplay # 详细显示


vgchange
vgchange -s PE_SIZE[bBkKmMgG] # 修改PE的大小vgremove
vgremove VG_NAMEvgextend
vgextend VG_NAME PV_NAME

vgreduce
务必先考虑pvmove迁移数据, 再vgreduce
vgreduce VG_NAME PV_NAMEvgscan
vgscan # scan all disks for volume groups and rebuild cacheslvcreate
lvcreate -L LV_SIZE[mMgGtT] -n LV_NAME VG_NAME

lvs & lvdisplay


lvremove
lvremove /dev/mapper/VG_NAME-LV_NAME

lvscan
lvscan # scan all disks for Logical Volumes查看所属的VG是否有足够的剩余空间
vgs

*卸载要扩展的LV
umount /dev/mapper/vg0-lv_data
*强制检查要扩展的LV的文件系统
e2fsck -f /dev/mapper/vg0-lv_data
扩展LV的大小
lvextend -L +1G /dev/mapper/vg0-lv_data

扩展文件系统的范围
resize2fs /dev/mapper/vg0-lv_data

*挂载已扩展的LV
mount -a

危险警告: 尽量不要做缩减LV !!
一定要先卸载LV
umount /dev/mapper/vg0-lv_data
强制检查要缩减的LV的文件系统
e2fsck -f /dev/mapper/vg0-lv_data

缩减LV的文件系统的范围
resize2fs /dev/mapper/vg0-lv_data 1G

缩减LV的大小
强烈建议: 缩减后的LV大小要求略大于缩减后的文件系统大小 !!!
lvreduce -L 1.2G /dev/mapper/vg0-lv_data

挂载已缩减的LV
mount -a

- Snapshots are special Logical Volumes
- Snapshots are perfect for bacups where a temporary copy of an existing dataset is needed
- Snapshots only consume space where they are different from the original Logical Volume
创建快照
lvcreate -L 200M -s -n snap_data /dev/mapper/vg0-lv_data

挂载快照
mount -o ro /dev/mapper/vg0-snap_data /mnt/snap_data

压缩备份
tar -Jpcv -f snap_data$(date +"%Y%m%d-%H%M").txz /mnt/snap_data/*

卸载删除
umount /dev/mapper/vg0-snap_data
lvremove /dev/mapper/vg0-snap_data

原文:https://www.cnblogs.com/zakzhu/p/11616627.html