LVM2:
Lvm:logical Volume Manager,version2
Use pure software to organize one or more underlying hardware devices into an abstract logical device.
Dm:device Mapper (Device mapping Build): A module that organizes one or more underlying block devices to be called a logical device.
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/78/12/wKioL1Z1PiDRYkErAABClD4q_rQ029.png " Title= "LVM. PNG "alt=" Wkiol1z1pidrykeraabcld4q_rq029.png "/>
LVM mechanism:
The disk partition of the underlying block device is created into a physical volume PV, the PV is merged into a higher level VG volume group, can add more than one physical hard disk partition into a logical device, similar to the extended partition, there is no way to use directly, so to create a LV on the VG, this is the real logical volume, Each LV is a separate file system that can be formatted and used. The size can be any available size within the volume group, and settings can span multiple pv,vg to divide each added PV space into multiple fixed-size storage blocks (pe:phsical Extent), and the size of the PE depends on the definition of the VG, Only PV added into the VG will be divided into multiple PE for LV use. When PE is added into LV, it becomes LE (Logical Extend). Therefore, the logical volume LV can expand arbitrarily, when the need to expand the LV space is added from the volume group into the unused PE, when the need to reduce the LV space to subtract the PE in the LV, and does not damage the files within the LV (smaller space than the premise of storing files). Similarly, VG can expand the expansion space at will, when the space is small, add PV to expand the VG space, when you want to reduce space to remove the PV to reduce space (if the current PV does not store data files, if the PV memory data, the data transferred to other PV and then removed). But LV is based on software at a higher level of implementation, once the data is damaged, repair is very difficult.
Logical Volume Storage:/dev/mapper/vg_name-lv_name
Dev/mapper/vgol0-root
/dev/vg_name/lv_name
Dev/vol0/root
PV Management Tools :
PVS: Brief PV information display
Pvdisplay: Show Details of PV
Pvcreate Dev/device: Creating PV
Pvremoved:/dev/device: Remove PV
Physical volumes (PV) can be created on partitions, on disk, on raid
To create a physical volume:
First step: Create a disk partition, we have Sda3, Sda5 and Sda6 for us to use
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/78/12/wKioL1Z1RbiBn7_sAAAoZTJYOLQ572.png " title= "Disk partition. PNG "alt=" Wkiol1z1rbibn7_saaaoztjyolq572.png "/>
Step two: type T in the Fdisk command to change the IDs of these three partitions to 8e (physical volumes), SDA5 and Sda6 can be created as surrogate physical volumes.
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/78/12/wKioL1Z1Rn3D0CsCAAAeCqzDruY094.png " Title= "Be. PNG "alt=" Wkiol1z1rn3d0cscaaaecqzdruy094.png "/>
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/78/14/wKiom1Z1RxuRS4frAAAi2L3AelQ132.png " title= "Physical volume. PNG "alt=" Wkiom1z1rxurs4fraaai2l3aelq132.png "/>
Step Three: Pvcreate/dev/device create PV,
~]# Pvcreate/dev/sda3
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/78/14/wKiom1Z1SRuCoihbAAAMflWjWrQ635.png " Title= "Create PV. PNG "alt=" Wkiom1z1srucoihbaaamflwjwrq635.png "/>
Fourth step: PVs View PV
~]# PVs
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/78/13/wKioL1Z1Sd-D4ttAAAARvttDEqA545.png " Title= "PVs. PNG "alt=" Wkiol1z1sd-d4ttaaaarvttdeqa545.png "/>
Pvdisplay View more information
~]# Pvdisplay
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/78/13/wKioL1Z1Sjfy5ECPAAAipkTveQo662.png " Title= "Sda3. PNG "alt=" Wkiol1z1sjfy5ecpaaaipktveqo662.png "/>
VG Management Tools :
VGs
Vgdisplay
Vgcreate [-S#[MMGGTT]] (Specify PE size, default is 8M) Volumegroupname pvname[...]
Vgextend volumegroupname/dev/pvname: Extending VG Space
Vgreduce volumegroupname/dev/pvname: Reducing VG Space
( to move the data that may exist in the PV first pvmove/dev/pvname)
Vgremove volumegroupname: Delete VG
Create the TESTVG and add the PV created above:
The first step: vgcreate, create the VG, name Testvg,pe 16M, and the physical volume/dev/sda3 will enter:
~]# vgcreate-s16m Testvg/dev/sda3
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/78/14/wKiom1Z1TbCQMXwSAAAQKPcAKmE905.png " Title= "VG. PNG "alt=" Wkiom1z1tbcqmxwsaaaqkpcakme905.png "/>
Step Two: Expand TESTVG size, add/dev/sda5 and/dev/sda6
~]# Vgextend Testvg/dev/sda5
~]# Vgextend Testvg/dev/sda5
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/78/13/wKioL1Z1TmzjJL6zAAAWrGlhg0s358.png "title=" Extended. PNG "alt=" Wkiol1z1tmzjjl6zaaawrglhg0s358.png "/>
Step three: VGs view TESTVG Information
~]# VGS
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/78/14/wKiom1Z1T1iQQpzRAAARkji-vlc676.png " Title= "VGs. PNG "alt=" Wkiom1z1t1iqqpzraaarkji-vlc676.png "/>
~]# Vgdispaly
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/78/14/wKiom1Z1T53C_xyTAAAtzGPBNQ0312.png " Title= "Vgdisplay. PNG "alt=" Wkiom1z1t53c_xytaaatzgpbnq0312.png "/>
LV Management Tools :
Lvs
Lvdisplay
LVCREATE-L#[MMGGTT] (Specify logical volume size)-N NAME volumegroupname
Lvremove/dev/vg_name/lv_name: Delete LV
Create a logical volume of size 10G TESTLV:
The first step: on the above TESTVG lvcreate create the LV, the name is TESTLV, the size is 10G:
~]# Lvcreate-l10g-n TESTLV/DEV/TESTVG
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/78/14/wKioL1Z1UlujOh7rAAAKC3YPWrA091.png " Title= "LV. PNG "alt=" Wkiol1z1ulujoh7raaakc3ypwra091.png "/>
Step two: LVs query LV information:
~]# LVS
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/78/14/wKioL1Z1Ur7jqRy4AAAdI1JfkJY163.png " Title= "LVs. PNG "alt=" Wkiol1z1ur7jqry4aaadi1jfkjy163.png "/>
~]# Lvdisplay
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/78/14/wKioL1Z1UvmyH0QsAAA86j_Bibs316.png " Title= "Lvdisplay. PNG "alt=" Wkiol1z1uvmyh0qsaaa86j_bibs316.png "/>
You can use this logical volume when you mount TESTLV to the directory after you create the file system:
~]# mke2fs-t ext4-b 1024-l MYLV/DEV/TESTVG/TESTLV
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/78/14/wKioL1Z1VAzx2Bx6AAB3V1Ngb7s728.png " Title= "LV. PNG "alt=" Wkiol1z1vazx2bx6aab3v1ngb7s728.png "/>
~]# mount/dev/testvg/testlv/users
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/78/14/wKioL1Z1VGGQnDJ7AAAsZDUtV9Q899.png " Title= "Mount. PNG "alt=" Wkiol1z1vggqndj7aaaszdutv9q899.png "/>
Extending logical Volumes :
Since the current logical volume has been created and mounted on the directory for normal use, when the LV space is extended, only the space of the LV itself is extended, and the file system that is actually used does not extend, so we also need to extend the file system accordingly.
#lvextend-L[+]#[MMGGTT] ( extended to a size of #,+ to increase #)/dev/vg_name/lv_name
#resize2fs/dev/vg_name/lv_name ( no size extension to the size of the LV physical boundary )
Extended TESTLV space size to 15G
~]# LVEXTEND-L15G/DEV/TESTVG/TESTLV
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/78/15/wKiom1Z1VtHy7qWmAAAXCCFQSvE153.png "title=" Lvextend. PNG "alt=" wkiom1z1vthy7qwmaaaxccfqsve153.png "/> extension prompted to successfully change Testl from 10G to 15G, but we enter DF-LH to see the size of TESTLV or 10G:
~]# DF-LH
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/78/15/wKiom1Z1V5Hy5FYQAAApR-PNAlA352.png " Title= "Lvextend. PNG "alt=" Wkiom1z1v5hy5fyqaaapr-pnala352.png "/>
It is because the file system is not expanded, but only the physical system. So we're going to extend the file system:
~]# RESIZE2FS/DEV/TESTVG/TESTLV
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/78/14/wKioL1Z1WHKCUWhwAAAjkdnPE9g397.png " Title= "E2fs kuozhabn. PNG "alt=" Wkiol1z1whkcuwhwaaajkdnpe9g397.png "/>
Now look at the DF-LH:TESTLV has become 15G,
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/78/15/wKiom1Z1WJzA5U0_AAAjshI5eYo192.png " Title= "at this time. PNG "alt=" Wkiom1z1wjza5u0_aaajshi5eyo192.png "/>
Reducing logical volumes : ( risk is not recommended to reduce )
#umount/dev/vg_name/lv_name
#e2fsck-F/dev/vg_name/lv_name
#resize2fs/dev/vg_name/lv_name #[mmggtt] (reduced to a specified size)
#lvreduce-L [-]#[MMGGTT]-Indicates the size of the reduction, without-indicating the size of the reduction to /dev/vg_name/lv_name
#mount
We want to reduce the volume of the logical volumes, to ensure that the reduced size can accommodate all the files of the file system . You first have to unload the file system, then force check that the file system is undamaged, then reduce the logical system boundary, then reduce the LV physical boundary, and then mount and use it.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/78/14/wKioL1Z1XcTjs3g1AAAGHMxCGlc169.png "style=" float: none; "title=" 1.PNG "alt=" Wkiol1z1xctjs3g1aaaghmxcglc169.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/78/15/wKiom1Z1XbfgkPtWAAAhssKkyfE450.png "style=" float: none; "title=" 2.PNG "alt=" Wkiom1z1xbfgkptwaaahsskkyfe450.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/78/15/wKiom1Z1Xbjx_VgdAAAVtQv19zA939.png "style=" float: none; "title=" 3.PNG "alt=" Wkiom1z1xbjx_vgdaaavtqv19za939.png "/>
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/78/14/wKioL1Z1XcXz2 Q_Q aaa1np2piv0431.png "style=" float: none; "title=" 4.PNG "alt=" wkiol1z1xcxz2 Q_Q aaa1np2piv0431.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/78/14/wKioL1Z1Xcaj_xDcAAAHftB6OdE256.png "style=" float: none; "title=" 5.PNG "alt=" Wkiol1z1xcaj_xdcaaahftb6ode256.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/78/15/wKiom1Z1XiCTam6SAAAEbe5zJiw702.png "style=" float: none; "title=" 6.PNG "alt=" Wkiom1z1xictam6saaaebe5zjiw702.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/78/14/wKioL1Z1Xi6xHhR5AAAHT7XtwY4713.png "style=" float: none; "title=" 7.PNG "alt=" Wkiol1z1xi6xhhr5aaaht7xtwy4713.png "/>
In addition to dynamically scaling or shrinking, LVM also has a snapshot capability.
Snapshot : Snapshot (Saves the state of the past file system for backing up the current state of the LV file system
#lvcreate-L#[MMGGTT]-p r-s-N snapshotlv_name original_lv_name
#mount/dev/testvg/snapshotlv_name
Creating a snapshot of size 1G for TESTLV requires read-only access:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/78/16/wKiom1Z1YKLxe7TWAAAMU8op27I815.png "title=" snapshot. PNG "alt=" Wkiom1z1yklxe7twaaamu8op27i815.png "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/78/14/wKioL1Z1YT7jreKpAAAPIJKT4S0072.png "title=" mount the snapshot. PNG "alt=" Wkiol1z1yt7jrekpaaapijkt4s0072.png "/>
A snapshot can only back up the contents of the file system at the moment the snapshot is currently created, and subsequent changes will not be backed up.
Logical Volume Manager (LVM2) usage (CentOS6) and snapshot capabilities