Logical Volume Manager
=========================================================================
LVM (Logical Volume Manager) Logical Volume Manager
The point of LVM is to elastically adjust the capacity of the file system!
LVM can consolidate multiple physical partitions together, making these partitions look like a single disk.
===================================================== ========================
PV (Physical Volume) physical volume
Create PV
[root@localhost ~]# pvcreate /dev/sdb /dev/sdc
Query PV
[root@localhost ~]# pvs
[root@localhost ~]# pvscan
[root@localhost ~]# pvdisplay
delete PV
[root@localhost ~]# pvremove /dev/sdc
===================================================== ========================
VG (Volume Group) volume group
vgcreate #New VG
vgscan #Query VG
vgdisplay #Display VG
vgextend #Add extra PV
in VG vgreduce #Delete PV in VG
vgchange #Set whether VG is active (active)
vgremove #Delete a VG
vgcreate -s 4M [VG_volume group name] [PV_physical volume name/dev/sdb1] #Create VG
[root@localhost ~]# vgcreate -s 4M my_vg /dev/sdb /dev/sdc
vgextend [VG_volume group name] [PV_physical volume name] #Add a single VG
[root@localhost ~]# vgextend my_vg /dev/sdc
vgreduce [VG_volume group name] [PV_physical volume name] #Remove a single VG
vgreduce my_vg /dev/sdc
vgremove [VG_volume group] #Remove the entire VG volume group
[root@localhost ~]# vgremove my_vg
===================================================== ========================
LV (Logical Volume) logical volume
lvcreate #Create LV
lvscan #Query LV
lvdisplay #Display LV
lvextend
#Increase capacity in LV lvreduce #Reduce capacity in LV
lvremove #Delete an LV lvresize #Adjust
the capacity of LV
Creation of LV
lvcreate -L [how much space to allocate] -n [specify LV name] [from which VG volume group to divide]
[root@localhost ~]# lvcreate -L 10G -n my_lv my_vg
[root@localhost ~]# mkfs.ext4 /dev/my_vg/my_lv
LV expansion
lvextend -L [how much space to allocate] [logical volume]
[root@localhost ~]# lvextend -L +5G /dev/my_vg/my_lv
[root@localhost ~]# resize2fs -f /dev/my_vg/my_lv
LV reduction
[root@localhost ~]# umount /dev/my_vg/my_lv #Unmount the logical volume
[root@localhost ~]# e2fsck -f /dev/my_vg/my_lv #Check the file system
resize2fs -f /dev/my_vg/my_lv [reduced file size]
[root@localhost ~]# resize2fs -f /dev/my_vg/my_lv 10G #Reduce the file system first
lvreduce -L [reduced file size] /dev/my_vg/my_lv
[root@localhost ~]# lvreduce -L 10G /dev/my_vg/my_lv #Reduce the logical volume
LV snapshot function
[root@localhost ~]# lvcreate -s -n mylv_back -L 200M /dev/my_vg/my_lv
-s #Indicates to take a snapshot
-n #Snapshot name (here mylv_back)
-L #Specify snapshot size (200M)
/dev /my_vg/my_lv #Take a snapshot of this device
[root@localhost ~]# mount /dev/my_vg/mylv_back /ghost/ #Data comes back after mounting
[root@localhost /]# lvremove /dev/my_vg/mylv_back #Uninstall snapshot
=========================================================================