First draw a picture, as follows:
LVM is the abbreviation for Logical Disk volume management (logicalvolumemanager), which is a mechanism for managing disk partitions in a Linux environment, and LVM is a logical layer built on hard disks and partitions to improve the flexibility of disk partition management. The LVM system administrator makes it easy to manage disk partitions, such as connecting several disk partitions to a single block of volume group (volumegroup), forming a storage pool. Administrators can create logical volume groups (logicalvolumes) at will on a volume group and further create file systems on logical volume groups. The administrator can easily adjust the size of the storage volume group through LVM, and the disk storage can be named, managed and assigned as a group, for example, "development" and "sales", instead of using the physical disk name "SDA" and "SDB". And when a new disk is added to the system, the LVM administrator does not have to move the disk's files to the new disk to take full advantage of the new storage space, but instead directly extend the file system across the disk.
The above two images show the management logic diagram of LVM
The actual application situation is as follows:
1. To allocate a new hard disk for the server, when installing the Linux system, the system will use LVM to manage the hard disk, which is convenient for later expansion, especially dynamic expansion (without changing the original partition structure)
2. The system has been created, and later used, after the newly added hard drive, manually create the partition according to the following logic
2.1 Using the Fdisk software for partitioning, the partition will roughly use the following command:
Fdisk/dev/sd-----into the partition operator interface,Represents your physical hard drive number, usually a,b,c ...
M-----View Help
P-----Print out the current partition table
n-----New partition, usually by default
T-----Change the partition type
L-----List the available partition types
W-----Error configuration
Note: (1) DOS and GPT partition table selection problem, if the hard disk capacity of more than 2TB will automatically adopt the GPT partition table format, if it is a virtual disk, may be expanded to more than 2TB later, it is recommended to use GPT partitioned table format;
(2) After saving the configuration, the system needs to be restarted before it can be called via pvcreate;
3. Once the partition is created, use Pvcreate to create the physical volume and view the command using Pvdisplay
Pvcreate/dev/sd-----The first one is the number of the physical hard disk, the second is the partition sequence number, usually the three-in-one ...
4. At this stage in two cases, one is to create a new VG (Volumegroup), one is to expand the original VG, we start from the creation of a new VG, and then introduced to the expansion of VG;
5. Create a new VG, use the command vgcreate command to view commands using Vgdisplay
Vgcreate <name> <partition>-----Names is the name of the VG, partition is the partition, the general format is/DEV/SD
6. After creating the VG, start wearing a LV (logicvolume), using the command: lvcreate, view command using Lvdisplay
Lvcreate-n name-l size <VG name>----name is a logical volume, size is a logical volume, in GB,VG name is the VG in the previous step
7. Once the logical volume is created, it is the format logical volume, with a lot of commands, and what type of format are you prepared for, here are examples of EXT4 and XFS
MKFS.EXT4/DEV/<VG name>/<lv name>----VG name is VG, and LV name is the name of the logical volume
Mkfs-t XFS/DEV/<VG name>/<lv name>
8. The next step is to enlarge the VG, and then the last one to mount
9. Expansion VG,PV After the creation is complete, you can expand the VG, using the command: Vgextend
Vgextend <VG name>/dev/sd**
10. You can view the VG's free space by Vgdisplay after the previous step has increased
11. Add free space to the LV, using the command: Lvextend
Lvextend-l +100%FREE/DEV/<VG name>/<lv name>----+100%free is 100% of the available space and can be set to a different percentage
12. One more step is needed to really increase the space, using the command: RESIZE2FS
RESIZE2FS/DEV/<VG NAME>/<LV name>
13. Back to mount step, the expansion is not required to re-mount, the new only need to mount, manual mount using mount, automatic mount need to modify the/etc/fstab file.
14. At this point, the basic introduction is complete;
A summary of the use of LVM in Linux