First, what is LVM
Traditionally, if a partition size is static. If the user has no space on the partition, then he either repartitioning (may need to reinstall the system) or use the assembly machine like a symbolic connection.
A partition is the evolution of the concept of a series of contiguous blocks of data on a physical disk. Most Unix-like systems now have the ability to decompose physical disks into many units. Storage units on multiple drives can be aggregated into one logical volume, which can be assigned to partitions, and cells can be added and removed from the partition as space requirements change.
For example, we have a 1G hard disk, we created the/home partition 600MB, imagine we have no space, then we decided that/home needs 1GB. So with the concept of traditional partitioning, we need to have another 1GB size drive, then we can add this disk, create a new home/home, and copy the existing data over.
With LVM, however, we only need to add 400MB of disk to it, and it adds its storage unit to the/home partition, other tools let us adjust the size of the original filesystem, we just need to adjust the size of/home to use a larger partition, then we return to business.
Of course, LVM can also take a snapshot of itself, which allows us to make a backup of some non-moving targets.
Second, the basic composition of LVM
Physical media-----The physical media, which means that it is just a hard disk or a partition, such as/DEV/HDA,/DEV/SDA,/DEV/SDA4 and so on.
Physical volume-----Physical Volume (PV) A PV is just a physical medium that has a lot of management data added to him, and once we add it, LVM can think of it as a hard disk holder.
Physical partition----physical extents (PE) The physical partition here is much like some data block, which is 4MB by default.
Volume Group--------Volume Group (VG) A VG has a number of physical partitions (possibly from multiple physical volumes or hard disks), although this is likely to lead us to a VG consisting of several hard disks, such as/dev/hda and/DEV/SDA, but more specifically, It is comprised of many of the PE provided by these hard drives.
Logical Volume-----Logic Volume (LV) A logical volume is usually the end result of our work, and here is where we store information, which equates to our traditional partitioning.
Logical partitioning----Logical extents (LE), in the same volume group, the size of LE is the same as the size of the PE, and one by one corresponds.
Third, the basic steps of LVM production
The first step: implementing the partitioning phase, our common command is FDISK, our goal is to rewrite the system ID to 8e, we can get some partitions such as/DEV/HDA1,/DEV/HDA5,/DEV/HB1 and so on.
The second step: The PV phase, our common command is pvcreate and Pvscan, our goal is to build and observe the PV, we can get some of the PV, such as/DEV/HDA1,/DEV/HDA5,/DEV/HB1 and so on.
The third step: the VG phase, our main command is vgcreate and Vgdisplay, our goal is to use PV to build the VG, we can get a corresponding VG, it can contain a number of PE.
Fourth step: The LV phase, our main command is lvcreate and Lvdisplay, we from the VG to split the LV, we can get a number of LV.
Fifth step: File system use stage, our main command when MKFS and mount, we format the system, directly mounted to the Linux file system.
IV, some notes
Starting with the Linux kernel 2.6.9, the Device-mapper module is already included, and we just need to load it. Loading the Mapper module we use the command modprobe dm_mod to see if loading we use Lsmod | grep Dm_mod to implement. If our kernel is above 2.6.9 without this module, we can install it using the Yum install Device-mapper command, if our kernel is below 2.6.9, then we need to compile and install the Device-mapper module.
Five, common commands
Common commands for creating PV:
(1) Pvcreate entity partion is created as PV
(2) Pvscan searches the current system for any disk or partition with PV
(3) Pvdisplay shows the PV status above the current system
(4) Pvremove The PV attribute is removed so that the partition no longer has the PV property
Example of creating a PV command:
(1) Create pv:pvcreate/dev/hdb on disk
(2) Create PV on the partition (first you need to set the partition type to 8e using fdisk): PVCREATE/DEV/DHB1
Common commands for creating VG:
(1) vgcreate Create VG command
(2) Whether the Vgscan search system has a VG presence
(3) Vgdisplay shows the status of VG above the current system
(4) vgextend add additional PV inside the VG
(5) Vgreduce remove PV within VG
(6) Vgchange configuration VG whether Qidong (active)
(7) Vgremove Delete a VG
To create a VG example:
(1) For example, we add/dev/hda1 and/dev/hdb1 into the Xin Volume group: vgcreate XIN/DEV/HDA1/DEV/HDB1
To create the LV command:
(1) lvcreate create LV
(2) Lvscan search system above the LV
(3) Lvdisplay display system above the LV status
(4) Lvextend add capacity inside LV
(5) Lvreduce reduces the volume inside the LV
(6) lvremove Delete a LV
(7) Lvresize the size adjustment of LV
To create the LV paradigm:
(1) Create a 1500MB lv:lvcreate-l 1500m-n star Xin named star
(2) Create a lv:lvcreate-l 100-n star Xin named Star,pe number 100
Format Mount command:
(1) mkdir Create a directory
(2) mkfs Create file system
(3) Mount mounted
Format and mount the example:
(1) Create File System example: Mkfs-t Ext3/dev/xin/star
Six, other features
Stop vg:vgchange-a N Xin
Delete Vg:vgremove Xin
Add PV to Vg:vgextend XIN/DEV/HDC1
Remove Pv:vgreduce xin/dev/hda1 from VG
Delete a Lv:umount/dev/xin/star
Lvremove/dev/xin/star
Extended LV to 12g:lvextend-l 12g/dev/xin/star
Increase LV to 1g:lvextend-l +1g/dev/xin/star
Seventh, a parameter explanation
We usually use lvcreate in the following two formats:
(1) Lvcreate [-L N[MGT]] [-n LV name] VG Name
(2) Lvcreate [-L N] [-n LV name] VG Name
Explanation of parameter options:
(1)-L: After the capacity, the unit of capacity can be m,g,t and so on, it should be noted that the minimum unit is PE, so this number must be a multiple of PE, if not, the system will automatically calculate the closest capacity.
(2)-L: Can be followed by the number of PE, rather than capacity. If you want to do this, please calculate the number of PE yourself.
(3)-N: followed by the name of the LV
Eighth, note
Before also wrote an article about LVM, but the feeling summed up not strong, interested friends can also read, the summary of the relatively better.
Sinsing organizing LVM in Linux