lvm:logical Volume Manager, logical Volume Manager. It is a mechanism for disk partition management in the LIUNX environment. Shields the underlying disk layout and facilitates dynamic disk capacity adjustment. It can also be created on raid, adding redundancy. However,/boot is used to store the bootstrap file and cannot be applied LVM.
Its working mechanism is to combine the underlying physical volumes (PV, which can be multiple disks or multiple physical partitions) into a single volume group (VG), and then create one or more logical partitions (LV) in the volume group, and the logical partition (LV) can be moved to adjust the partition size without damaging the data, which facilitates the management of the disk. Details of each volume are as follows:
Pv:physical Volume, physical volume
Refers to an entire disk or a common partition created with tools such as Fdisk, or a raid that logically has the same functionality as a disk partition. It is an LVM basic storage logic block.
each physical volume PV is made up of multiple physical basic blocks of equal size (pe:phsical Extent), similar to sectors of a normal disk. Each PE has a unique number, which is the smallest unit that can be addressable by LVM, and its size can be configured by itself when creating the volume group VG, which defaults to 4MB.
Vg:volume Group, Volume group
It is an entire combination of one or more PV physical volumes. You can create one or more logical volumes (LVS) on a volume group.
Lv:logical Volume, Logical volume
A disk partition, similar to a non-LVM system, is a space separated from the volume group VG for creating file systems. Consists of multiple logical basic blocks of equal size (le:logical Extent), which is the basic unit of LV addressable, the same size as PE, and one by one corresponds.
Dm:device Mapper, Device mapping
A module that organizes one or more underlying block devices into a logical device with a device path of:/dev/dm-#
LVM Device File storage path:/dev/mapper/vg_name-lv_name or/dev/vg_name/lv_name, both of which point to/dev/dm-#的链接文件.
Create Management:
First, create the partition:
Partition creation tools, such as Fdisk, are used to create partitions, just like creating normal partitions, but you need to set the partition type to 8e (Linux LVM). The creation process is not detailed and the results are as follows:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/A6/wKioL1bsrb6jkIN9AAA2ycqPL7c142.png "title=" 1.png " alt= "Wkiol1bsrb6jkin9aaa2ycqpl7c142.png"/>
4 logical partitions with a size of 10G were created on the/dev/sdb disk,/DEV/SDB5/DEV/SDB6/DEV/SDB7/DEV/SDB8, with the partition type: Linux LVM.
Second, physical volume PV management
Create Pv:pvcreate/dev/device
Create a single partition: The pvreate command directly partitions the line
Pvcreate/dev/sdb5
Create multiple partitions: Multiple partitions are separated by a space after the pvreate command
Pvcreate/dev/sdb5/dev/sdb6/dev/sdb7/dev/sdb8
View PV Information:
View brief information: Pvs/dev/device
View more information: Pvdisplay/dev/device
The non-specific partition is to view all PV information in the system;
For example, create a/DEV/SDB5/DEV/SDB6/DEV/SDB7/DEV/SDB8 four partition as PV.
The creation process and results are as follows: View the PV details only as an example of viewing/DEV/SDB5.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7D/A6/wKioL1bssp7CdzCjAABImhw4Xrw897.png "title=" 1.png " alt= "Wkiol1bssp7cdzcjaabimhw4xrw897.png"/>
Delete Pv:pvremove/dev/device
You can delete a single partition, or you can delete multiple partitions, with the use of the Create PV command, no longer detailed.
Remove Pv:pvmove/dev/device
Note that the removal of PV, just remove the data on the PV, for the volume group VG capacity reduction, you can first understand,
Detailed when the VG shrinks.
Three, volume group VG Management
Create Vg:vgcreate [-S #[kkmmggttppee]] vg_name Pv_path [Pv_path ...]
Create a single PV as a volume group: vgcreate vg_name Pv_path
such as: Vgcreate MYVG/DEV/SDB5
Create multiple PV as a volume group: vgcreate vg_name pv_path Pv_path ... Multiple PV spaces separated
such as: Vgcreate MYVG/DEV/SDB5/DEV/SDB6/DEV/SDB7
-S #[kkmmggttppee]: Indicates the physical base block PE size specified, which defaults to 4MB.
To view the VG information:
View brief information: VGs vg_name;
View more information: Vgdisplay Vg_name
Do not add vg_name means to view all the VG information in the system;
For example, create a VG named MYVG that consists of three partitions of/DEV/SDB5/DEV/SDB6/DEV/SDB7.
Requires a PE size of 4MB. The creation process and results are as follows:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7D/A6/wKioL1bsuzGSH6TgAABVRasbA-U522.png "title=" 1.png " alt= "Wkiol1bsuzgsh6tgaabvrasba-u522.png"/>
Now you can see PV, you will find/dev/sdb5/dev/sdb6/dev/sdb7 these three partitions belong to the MYVG volume group,
View the results as follows:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7D/A6/wKioL1bsu_Lw3BmyAAAVxBtR4P4640.png "title=" 1.png " alt= "Wkiol1bsu_lw3bmyaaavxbtr4p4640.png"/>
Delete Vg:vgremove Vg_name
Vgremove command after adding vg_name will be able to delete the corresponding VG, very simple, no longer more described.
Iv. expansion and reduction of VG
When the VG capacity is not enough, can be extended to the VG capacity, but also to reduce the VG capacity, but to pay attention to reduce the need to first remove
The data in PV (of course, other PV remaining capacity can accommodate the removal of data within the PV), otherwise it will damage the original data.
Here's how:
1. Extended Vg:vgextend vg_name Pv_path [Pv_path ...]
Extending the front face, you need to create the partition beforehand and create the PV, you can extend a single partition to the VG, or you can simultaneously
Multiple partitions are extended to VG.
For example, extend the/DEV/SDB8 (partitioned and created PV) to a VG named MYVG.
The results are as follows;
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/AA/wKiom1bsv56Qy4LqAABgeF-QMtg618.png "title=" 1.png " alt= "Wkiom1bsv56qy4lqaabgef-qmtg618.png"/>o
Can see MYVG PV number from the original 3 has changed to 4 blocks, capacity due to the original 30G has been extended to 40G.
View/DEV/SDB8 's PV, is already belongs to MYVG's VG. The expansion was successful.
2, reduce vg:vgreduce vg_name Pv_path [Pv_path ...]
When you reduce VG, you can also shrink a single partition, or you can reduce multiple partitions at the same time. But be sure to remove the PV data before shrinking
For example: Reduce the/DEV/SDB8 from a vg named MYVG. The reduction process and results are as follows:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7D/A8/wKioL1bswsOD_21YAABkUzXDvqA270.png "title=" 1.png " alt= "Wkiol1bswsod_21yaabkuzxdvqa270.png"/>
You can see that the number of PV blocks in the MYVG is changed from 4 to 3, and the capacity is changed from 40G to 30G. View/DEV/SDB8, no longer part of
MYVG in the VG.
Note: When removing/DEV/SDB8 data, "No date to move for MYVG" is prompted because the original/DEV/SDB8
Even the entire MYVG VG has no data, so there are countless sources to remove, but it is important to remove the PV data in the production environment beforehand
Then do the VG reduction to avoid damage to the original data.
Five, logical volume LV Management
Create Lv:lvcreate-l #[mmggtt]-n lv_name vg_name
-L #[mmggtt]: Specifies the space size of the LV, the maximum can be the same as the VG space capacity, but not more than the VG space capacity
-N lv_name: Specifies the name of the LV.
View LV Information:
View brief information: LVS [/dev/vg_name/lv_name|/dev/mapper/vg_name-lv_name]
View more information: Lvdisplay [/dev/vg_name/lv_name|/dev/mapper/vg_name-lv_name]
When the LV path is not added, it can see all the LV information in the system;
For example, create a logical volume MYLV of size 10G in the MYVG volume group. The creation process and results are as follows:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7D/A9/wKioL1bs22nRnaV-AABgHitLDZI695.png "title=" 1.png " alt= "Wkiol1bs22nrnav-aabghitldzi695.png"/>
After the LV creation is complete, the LV is used normally after the file system is created on the LV and the mount is completed.
For example, to create a EXT4 format file system for MYLV LV, the volume is labeled mylv and mounted to the/MYLVM directory.
The operating procedures and results are as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7D/A9/wKioL1bs3pvhO7-aAABXjX-ZUEw638.png "title=" 1.png " alt= "Wkiol1bs3pvho7-aaabxjx-zuew638.png"/>
You can copy files to the/MYLVM directory and view the/MYLVM directory, verifying that the mount was successful, as follows:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7D/AC/wKiom1bs3tyhY-HiAAAXAlpKR74705.png "title=" 1.png " alt= "Wkiom1bs3tyhy-hiaaaxalpkr74705.png"/>
The/etc/fstaby file is successfully copied to the/MYLVM directory, and the Lost+fonud directory is stored under/MYLVM, and the Mount succeeds
Delete Lv:lvremove/dev/vg_name/lv_name
Lvremove command after the addition of the LV path, you can directly delete the LV, no longer detailed. Note, however, that you need to uninstall it first.
Vi. expansion and reduction of LV
LV, like VG, can also be scaled up or down as needed to dynamically adjust the LV capacity size. But not recommended for LV
Capacity reduction operations, which can easily cause existing data corruption. Specific as follows:
1. Extended Lv:lvextend-l [+]#[MMGGTT]/dev/vg_name/lv_name
-L [+]#[MMGGTT]: Indicates the size of the extended LV capacity, with "+" to indicate how large the extension, without "+" means the extension
Maximum size.
Note: After you readjust the LV capacity, you also need to update its size with the RESIZE2FS command, otherwise the LV is the original capacity.
For example: Extended mylv to 15G, requires the original file can not be lost, the extension process and results are as follows:
Extended LV and updated:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/AC/wKiom1bs5DuyJGSpAAAYVoul6-Y313.png "title=" 1.png " alt= "Wkiom1bs5duyjgspaaayvoul6-y313.png"/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7D/AC/wKiom1bs5J-Dcwv7AAAieyrVvdc330.png "title=" 1.png " alt= "Wkiom1bs5j-dcwv7aaaieyrvvdc330.png"/>
To view extended results:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7D/A9/wKioL1bs5V-BLcpYAABTSLFeC-M686.png "title=" 1.png " alt= "Wkiol1bs5v-blcpyaabtslfec-m686.png"/>
To view the original file:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7D/A9/wKioL1bs5gjhHO2cAAAUGQuAtTo981.png "title=" 1.png " alt= "Wkiol1bs5gjhho2caaaugquatto981.png"/>
2, reduce lv:lvreduce-l [-]#[MMGGTT]/dev/vg_name/lv_name
-L [-]#[MMGGTT]: Indicates reduced LV capacity size, with "-" indicates how much reduction, without "-" means reduction
Maximum size.
Note: (1) The LV is generally not recommended for capacity reduction operations, which is very easy to cause the existing data corruption;
(2) To ensure that the reduced capacity must be greater than the existing data occupied capacity, otherwise it will damage the data;
(3) To reduce the need to first uninstall equipment, and force detection of the file system;
(4) You need to update the logical capacity (that is, the RESIZE2FS command), and then reduce the LV;
For example: Reduce MYLV to 10G, require the original file cannot be lost. The specific operation and results are as follows:
Uninstalling the device and detecting the file system:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7D/AD/wKiom1bs6g7QGT63AAAmPwevyIk229.png "title=" 1.png " alt= "Wkiom1bs6g7qgt63aaampwevyik229.png"/>
Reduced LV:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7D/AD/wKiom1bs6teRhr5CAAAUyvaebFM039.png "title=" 1.png " alt= "Wkiom1bs6terhr5caaauyvaebfm039.png"/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7D/AD/wKiom1bs6v_gZAjBAAAt9mPHap8047.png "title=" 1.png " alt= "Wkiom1bs6v_gzajbaaat9mphap8047.png"/>
To mount and view the original file:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7D/AD/wKiom1bs64DQFXl1AAAWqu_py9Y740.png "title=" 1.png " alt= "Wkiom1bs64dqfxl1aaawqu_py9y740.png"/>
Mount successfully, the original file is not damaged.
Vii. Snapshots
The snapshot feature in LVM is that a snapshot is a backup of the specified data at a point in time, and the primary role is to
Perform backup and recovery of online data. The main working mechanism is copy-on-write (Copy-on-write,cow), in fact snapshot
Instead of copying the original data itself, the metadata for the physical location of the original data is copied, so the snapshot is created very quickly,
can be done instantaneously. Only when the original data block has changed, the snapshot will duplicate the original data block before the original data block has changed.
So that we access the data on the snapshot volume is still the original data, ensuring the consistency of the backup data. Actually snapshot
is not a true backup, but provides a channel for the backup to access the original data.
Implementation of snapshots in LVM:
Lvcreate-s-N snapshot_lv_name-l #[mmggtt]-p [R|RW] Original_lv_name
-S: Indicates the creation of the LV as a snapshot;
-N snapshot_lv_name: snapshot name;
-L #[mmggtt]: Indicates the size of the snapshot;
The snapshot size can be estimated by the amount of raw volume data changes and the scheduled snapshot lifetime. The snapshot is too large,
can cause wasted space and a snapshot that is too small can cause a snapshot backup to fail. The maximum size is the same as the original volume.
-P: Indicates permissions, either R (read-only) or RW (read-write);
Original_lv_name: Represents the original volume name, or it can be a directory or a file;
Note: 1, the snapshot is actually a logical volume;
2. Snapshots can only be backed up by logical volume LVM, and only logical volumes of the same volume group can be backed up;
For example: Create a snapshot of mylv, and try to backup data based on the snapshot, the function of positive snapshot;
1. Create snapshot Mysnap for Mylv, and look at the results:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7D/AE/wKiom1bs_zvDusD_AAB5n-Yfhp4828.png "title=" 1.png " alt= "Wkiom1bs_zvdusd_aab5n-yfhp4828.png"/>
Note: Creating fast homing eliminates the need to format the snapshot again.
2. Mount the Mysnap to the/mysnap directory to see if the directory has the data in the MYLV volume:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7D/AE/wKiom1btADDAB4y0AAAonP71_FA861.png "title=" 1.png " alt= "Wkiom1btaddab4y0aaaonp71_fa861.png"/>
The data in the MYLV volume is found in the snapshot.
3, make changes to the Fstab file in Mylv, and then copy the/etc/passwd file to the MYLV volume:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7D/AB/wKioL1btAgPAmQXsAABZo0WsiDQ110.png "title=" 1.png " alt= "Wkiol1btagpamqxsaabzo0wsidq110.png"/>
The/MYLVM directory has a passwd file, and fstab the last line adds #hell content.
4. See if there are any changes in the contents of the snapshot:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7D/AE/wKiom1btAgOQjhAUAABNLBZlm5s561.png "title=" 1.png " alt= "Wkiom1btagoqjhauaabnlbzlm5s561.png"/>
There is no change in the contents of the file in the snapshot/mysnap directory.
5. Copy the snapshot to the ~/BACK_MYLV directory and restore the MYLV data:
Backup:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7D/AE/wKiom1btCWixdECYAAAXHElOFUM064.png "title=" 1.png " alt= "Wkiom1btcwixdecyaaaxhelofum064.png"/>
Recovery:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7D/AB/wKioL1btDEDBZFoQAABXf245LlQ064.png "title=" 1.png " alt= "Wkiol1btdedbzfoqaabxf245llq064.png"/>
Found fstab file recovery in Mylv. Note: The Passwdy file in MYLVM is still in, as this only restores the
Fstab file. If the MYLV partition is damaged and then restored, only the snapshot is then file, and no subsequent modifications or additions
File.
6. Delete Snapshot:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7D/AB/wKioL1btDeaTJkGhAAAR9y_Fd8I665.png "title=" 1.png " alt= "Wkiol1btdeatjkghaaar9y_fd8i665.png"/>
The snapshot was deleted and the snapshot mission ended.
Basic application of LVM