root@king:~# lvm help
Available lvm commands:
Use 'lvm help ' for more information
dumpconfig Dump active configuration
formats List available metadata formats
help Display help for commands
lvchange Change the attributes of logical volume(s)
lvconvert Change logical volume layout
lvcreate Create a logical volume
lvdisplay Display information about a logical volume
lvextend Add space to a logical volume
lvmchange With the device mapper, this is obsolete and does nothing.
lvmdiskscan List devices that may be used as physical volumes
lvmsadc Collect activity data
lvmsar Create activity report
lvreduce Reduce the size of a logical volume
lvremove Remove logical volume(s) from the system
lvrename Rename a logical volume
lvresize Resize a logical volume
lvs Display information about logical volumes
lvscan List all logical volumes in all volume groups
pvchange Change attributes of physical volume(s)
pvresize Resize physical volume(s)
pvck Check the consistency of physical volume(s)
pvcreate Initialize physical volume(s) for use by LVM
pvdata Display the on-disk metadata for physical volume(s)
pvdisplay Display various attributes of physical volume(s)
pvmove Move extents from one physical volume to another
pvremove Remove LVM label(s) from physical volume(s)
pvs Display information about physical volumes
pvscan List all physical volumes
segtypes List available segment types
vgcfgbackup Backup volume group configuration(s)
vgcfgrestore Restore volume group configuration
vgchange Change volume group attributes
vgck Check the consistency of volume group(s)
vgconvert Change volume group metadata format
vgcreate Create a volume group
vgdisplay Display volume group information
vgexport Unregister volume group(s) from the system
vgextend Add physical volumes to a volume group
vgimport Register exported volume group with system
vgmerge Merge volume groups
vgmknodes Create the special files for volume group devices in /dev
vgreduce Remove physical volume(s) from a volume group
vgremove Remove volume group(s)
vgrename Rename a volume group
vgs Display information about volume groups
vgscan Search for all volume groups
vgsplit Move physical volumes into a new or existing volume group
version Display software and driver version information
root@king:~# lvm dumpconfig --help
dumpconfig: Dump active configuration
dumpconfig [-f|--file filename]
[ConfigurationVariable...]
root@king:~# lvm dumpconfig -f lvm-config.conf
会在当前目录生成LVM配置信息文件。
root@king:~# pvcreate --help
pvcreate: Initialize physical volume(s) for use by LVM
pvcreate
[--norestorefile]
[--restorefile file]
[-d|--debug]
[-f[f]|--force [--force]] #强制执行
[-h|-?|--help]
[--labelsector sector] #标签所处扇区,默认第二个扇区,扇区1,从0开始。可选0-3
[-M|--metadatatype 1|2]
[--pvmetadatacopies #copies] #元数据备份数
[--metadatasize MetadataSize[bBsSkKmMgGtTpPeE]] #元数据预留空间大小
[--dataalignment Alignment[bBsSkKmMgGtTpPeE]] #数据对齐段
[--dataalignmentoffset AlignmentOffset[bBsSkKmMgGtTpPeE]] #数据对齐偏移段,和前者一起决定了1stPE的位置
[--setphysicalvolumesize PhysicalVolumeSize[bBsSkKmMgGtTpPeE] #覆盖自动检测到PV大小
[-t|--test] #测试模式
[-u|--uuid uuid] #指定UUID
[-v|--verbose] #输出信息
[-y|--yes] #对于所有询问回复y
[-Z|--zero {y|n}] #s是否擦除设备的前4个扇区,2048字节
[--version]
PhysicalVolume [PhysicalVolume...] #实际的物理卷,可以跟接多个物理卷
创建偏移PV
root@king:~# pvcreate --dataalignment 80m --dataalignmentoffset 30m /dev/sdb1
Physical volume "/dev/sdb1" successfully created
root@king:~# pvs -o+pe_start
PV VG Fmt Attr PSize PFree 1st PE
/dev/sdb1 lvm2 a-- 1.00g 1.00g 110.00m
数据对齐80MB,对齐偏移30MB,则第一块PE位置110MB。
root@king:~# pvremove -h
pvremove: Remove LVM label(s) from physical volume(s)
pvremove
[-d|--debug]
[-f[f]|--force [--force]] #强制删除
[-h|-?|--help]
[-t|--test] #测试模式
[-v|--verbose] #详细输出
[-y|--yes] #所有询问,输入y
[--version]
PhysicalVolume [PhysicalVolume...] #所要删除的物理卷
root@king:~# pvchange -h
pvchange: Change attributes of physical volume(s)
pvchange
[-a|--all]
[-A|--autobackup y|n] #是否自动备份
[-d|--debug] #debug模式
[-f|--force] #强制更改
[-h|--help]
[-t|--test] #测试模式
[-u|--uuid] #生成新的UUID
[-x|--allocatable y|n] #是否分配Physical Extent在该PV,如果PV尚未纳入某个VG,则此操作无效。
[--metadataignore y|n] #是否忽略PV上的元数据,如果忽略,LVM将不存储元数据在这个PV的元数据区域。
[-v|--verbose]
[--addtag Tag] #
[--deltag Tag] #
[--version]
[PhysicalVolumePath...]
root@king:~# pvresize --help
pvresize: Resize physical volume(s)
pvresize
[-d|--debug]
[-h|-?|--help]
[--setphysicalvolumesize PhysicalVolumeSize[bBsSkKmMgGtTpPeE] #扩展或者收缩自动检测到的磁盘大小,
[-t|--test]
[-v|--verbose]
[--version]
PhysicalVolume [PhysicalVolume...]
实际操作
root@king:~# pvresize --setphysicalvolumesize 40m /dev/sdb1
Size must exceed physical extent start of 225280 sectors on PV /dev/sdb1.
Physical volume "/dev/sdb1" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
root@king:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 a-- 40.00m 40.00m
如果新收缩的大小尾部,处于分配的PE上,则会拒绝收缩。
root@king:~# pvmove --help
pvmove: Move extents from one physical volume to another
pvmove
[--abort] #过程中中断进程
[-A|--autobackup {y|n}]
[--alloc AllocationPolicy]
[-b|--background] #在后台运行守护进程
[-d|--debug]
[-h|-?|--help]
[-i|--interval seconds] #按周期进程进度百分比报告
[--noudevsync]
[-t|--test]
[-v|--verbose]
[--version]
[{-n|--name} LogicalVolume] #迁移指定LV的PE从源PV上
SourcePhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]} #源物理卷
[DestinationPhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]...] #目的物理卷
指定LV的PE迁移到指定PV上,目的PV未指定,则调用VG的分配规则。
如果pvmove被任何原因中断,比如宕机。重新不带参数执行pvmove,重启上次最后检查点的任何move进程。另外pvmove --about在任何时间,在最后检查点终止。
一次可以运行多个pvmove来移动不同源PV,但是额外的pvmove将忽略已经进行中的数据被改的LV,所以一些数据可能不会移动。
pvmove工作流程:
镜像迁移不支持,快照和快照原始卷。
root@king:~# lvm pvdata
There's no 'pvdata' command in LVM2.
Use lvs, pvs, vgs instead; or use vgcfgbackup and read the text file backup.
Metadata in LVM1 format can still be displayed using LVM1's pvdata command.
部分命令在LVM2中不支持
root@king:~# pvck --help
pvck: Check the consistency of physical volume(s)
pvck [-d|--debug]
[-h|--help]
[--labelsector sector]
[-v|--verbose]
[--version]
PhysicalVolume [PhysicalVolume...]
默认,4扇区作为PV的标签扫描,从扇区0开始。指定不同的扫描扇区,在数据恢复很有用。比如分区表错误,怀疑在100M位置有LVM分区,可以用labelsector来指定扫描位置,【100*1024*1024/512=204800】,示例pvck --labelsector 204800 /dev/sda。
root@king:~# pvdisplay --help
pvdisplay: Display various attributes of physical volume(s)
pvdisplay
[-c|--colon]
[-d|--debug]
[-h|--help]
[--ignorelockingfailure]
[-m|--maps] #显示物理块到逻辑卷和逻辑块的映射
[--nosuffix]
[-s|--short] #只显示指定PV的大小
[--units hHbBsSkKmMgGtTpPeE]
[-v|--verbose]
[--version]
[PhysicalVolumePath [PhysicalVolumePath...]]
pvdisplay --columns|-C
[--aligned]
[-a|--all]
[-d|--debug]
[-h|--help]
[--ignorelockingfailure]
[--noheadings]
[--nosuffix]
[-o|--options [+]Field[,Field]]
[-O|--sort [+|-]key1[,[+|-]key2[,...]]]
[--separator Separator]
[--unbuffered]
[--units hHbBsSkKmMgGtTpPeE]
[-v|--verbose]
[--version]
[PhysicalVolumePath [PhysicalVolumePath...]]
-c 参数,以冒号分割返回PV属性。分比为:PV设备名;卷组名;物理卷大小KB;内部PV号;PV状态;
root@king:~# pvs --help
pvs: Display information about physical volumes
pvs
[-a|--all] #显示未被pvcreate初始化设备信息
[--aligned]
[-d|--debug]
[-h|-?|--help]
[--ignorelockingfailure]
[--nameprefixes] #增加LVM2_的前缀
[--noheadings]
[--nosuffix]
[-o|--options [+]Field[,Field]]
[-O|--sort [+|-]key1[,[+|-]key2[,...]]]
[-P|--partial]
[--rows]
[--segments]
[--separator Separator]
[--trustcache]
[--unbuffered]
[--units hHbBsSkKmMgGtTpPeE]
[--unquoted]
[-v|--verbose]
[--version]
[PhysicalVolume [PhysicalVolume...]]
root@king:~# pvs -o help
Logical Volume Fields
---------------------
lv_all - All fields in this section.
lv_uuid - Unique identifier.
lv_name - Name. LVs created for internal use are enclosed in brackets.
lv_path - Full pathname for LV.
lv_attr - Various attributes - see man page.
lv_major - Persistent major number or -1 if not persistent.
lv_minor - Persistent minor number or -1 if not persistent.
lv_read_ahead - Read ahead setting in current units.
lv_kernel_major - Currently assigned major number or -1 if LV is not active.
lv_kernel_minor - Currently assigned minor number or -1 if LV is not active.
lv_kernel_read_ahead - Currently-in-use read ahead setting in current units.
lv_size - Size of LV in current units.
lv_metadata_size - For thin pools, the size of the LV that holds the metadata.
seg_count - Number of segments in LV.
origin - For snapshots, the origin device of this LV.
origin_size - For snapshots, the size of the origin device of this LV.
data_percent - For snapshot and thin pools and volumes, the percentage full if LV is active.
snap_percent - For snapshots, the percentage full if LV is active.
metadata_percent - For thin pools, the percentage of metadata full if LV is active.
copy_percent - For mirrors and pvmove, current percentage in-sync.
move_pv - For pvmove, Source PV of temporary LV created by pvmove.
convert_lv - For lvconvert, Name of temporary LV created by lvconvert.
mirror_log - For mirrors, the LV holding the synchronisation log.
data_lv - For thin pools, the LV holding the associated data.
metadata_lv - For thin pools, the LV holding the associated metadata.
pool_lv - For thin volumes, the thin pool LV for this volume.
lv_tags - Tags, if any.
lv_time - Creation time of the LV, if known
lv_host - Creation host of the LV, if known.
modules - Kernel device-mapper modules required for this LV.
Physical Volume Label Fields
----------------------------
pv_all - All fields in this section.
pv_fmt - Type of metadata.
pv_uuid - Unique identifier.
dev_size - Size of underlying device in current units.
pv_name - Name.
pv_mda_free - Free metadata area space on this device in current units.
pv_mda_size - Size of smallest metadata area on this device in current units.
Physical Volume Fields
----------------------
pv_all - All fields in this section.
pe_start - Offset to the start of data on the underlying device.
pv_size - Size of PV in current units.
pv_free - Total amount of unallocated space in current units.
pv_used - Total amount of allocated space in current units.
pv_attr - Various attributes - see man page.
pv_pe_count - Total number of Physical Extents.
pv_pe_alloc_count - Total number of allocated Physical Extents.
pv_tags - Tags, if any.
pv_mda_count - Number of metadata areas on this device.
pv_mda_used_count - Number of metadata areas in use on this device.
Volume Group Fields
-------------------
vg_all - All fields in this section.
vg_fmt - Type of metadata.
vg_uuid - Unique identifier.
vg_name - Name.
vg_attr - Various attributes - see man page.
vg_size - Total size of VG in current units.
vg_free - Total amount of free space in current units.
vg_sysid - System ID indicating when and where it was created.
vg_extent_size - Size of Physical Extents in current units.
vg_extent_count - Total number of Physical Extents.
vg_free_count - Total number of unallocated Physical Extents.
max_lv - Maximum number of LVs allowed in VG or 0 if unlimited.
max_pv - Maximum number of PVs allowed in VG or 0 if unlimited.
pv_count - Number of PVs.
lv_count - Number of LVs.
snap_count - Number of snapshots.
vg_seqno - Revision number of internal metadata. Incremented whenever it changes.
vg_tags - Tags, if any.
vg_mda_count - Number of metadata areas on this VG.
vg_mda_used_count - Number of metadata areas in use on this VG.
vg_mda_free - Free metadata area space for this VG in current units.
vg_mda_size - Size of smallest metadata area for this VG in current units.
vg_mda_copies - Target number of in use metadata areas in the VG.
Logical Volume Segment Fields
-----------------------------
seg_all - All fields in this section.
segtype - Type of LV segment.
stripes - Number of stripes or mirror legs.
stripesize - For stripes, amount of data placed on one device before switching to the next.
stripe_size - For stripes, amount of data placed on one device before switching to the next.
regionsize - For mirrors, the unit of data copied when synchronising devices.
region_size - For mirrors, the unit of data copied when synchronising devices.
chunksize - For snapshots, the unit of data used when tracking changes.
chunk_size - For snapshots, the unit of data used when tracking changes.
thin_count - For thin pools, the number of thin volumes in this pool.
discards - For thin pools, how discards are handled.
zero - For thin pools, if zeroing is enabled.
transaction_id - For thin pools, the transaction id.
seg_start - Offset within the LV to the start of the segment in current units.
seg_start_pe - Offset within the LV to the start of the segment in physical extents.
seg_size - Size of segment in current units.
seg_tags - Tags, if any.
seg_pe_ranges - Ranges of Physical Extents of underlying devices in command line format.
devices - Underlying devices used with starting extent numbers.
Physical Volume Segment Fields
------------------------------
pvseg_all - All fields in this section.
pvseg_start - Physical Extent number of start of segment.
pvseg_size - Number of extents in segment.