LVM and disk quota principle and configuration

1. Overview of LVM

  • Logical Volume Managr, logical volume management
  • Advantages: It can ensure that the disk capacity can be dynamically adjusted under the condition that the existing data remains unchanged , thereby improving the flexibility of disk management
  • The /boot partition is used to store boot files and cannot be created based on VVM

2. Basic concepts of LVM

  • PV (Physical Volume, physical volume)

    • List item the entire hard disk, or ordinary partitions created with tools such as fdisk
    • Includes many PEs (Physical Extent, basic unit) with a default size of 4MB
  • VG (Volume Group, volume group)

    • A whole composed of one or more physical volumes
  • LV (Logical Volume, logical volume)

    • A piece of space separated from the volume group for the establishment of the file system

Three. LVM management

Function Physical volume management volume group management Logical volume management
Scan scan pvscan vgscan lvscan
Credte build pvcreate vgcreate lvcreate
Display pvdisplay vgdisplay lvdisplay
RemoveDelete pvremove vgremove lvextend
ExtendExtended vgextend lvextend
Reduce vgreduce lvreduce

3.1PV physical volume management

3.1.1pvscan command – scan all physical volumes in the system

Install the CentOS system using automatic partitioning. The system disk sda is divided into two partitions, sda1 and sda2. Among them, sda2 is divided into two physical volumes, and based on the physical volume VolGroup volume group
insert image description here

3.1.2pvcreate command – replace partition physical volume with physical volume

The main thing is to add LVM attribute information and divide PE storage units. This command needs to use the device file of the hard disk or partition as a parameter (there can be more than one). For example, doing the following will convert the partitions /dev/sdb1, dev/sdb2, dev/sdb3 into physical volumes
insert image description here

3.1.3pvdisplay command – display physical volume details

insert image description here

3.1.4pvremove command – restore the physical volume to a common partition or disk

insert image description here

3.2 VG volume group management

3.2.1vgscan -- scan the LVM volume group established in the system

insert image description here

3.2.2vgdisplay command – display the information of each volume group

insert image description here

3.2.3 vgremove command – delete the specified volume group

insert image description here

3.2.4 vgextend command – extend volume group disk space

insert image description here

3.3 LV logical volume management

3.3.1lvscan command – scan the existing logical volume information of the system

insert image description here

3.3.2lvdisplay–display logical volume details

insert image description here

3.3.3lvextend, command – extend logical volume space

insert image description here

3.3.4lvremove – delete logical volumeinsert image description here

Four. LVM instance configuration

4.1 Logical volume configuration example

4.1.1 Experiment content:

  1. Create physical volumes: Create /dev/sdb3 and /dev/sdc1 as physical volumes
  2. Create a volume group; create a volume group vg01, assign 2 physical volumes to vg01
  3. Create a logical volume: take 8G capacity from vg01 to create a logical volume lvmail
  4. Format logical volume: lvmail formatted as XFS file system
  5. Mount the logical volume: mount the logical volume lvmail to the /mnt/fang directory

2.1.2 Experimental steps;

1. Use the fdisk tool to plan partitions, and set the partition format of /dev/sdb3 and /sev/sdc1 to Linux LVM (the corresponding system ID is 8e) 2. The pvcreate command
insert image description here
creates physical volumes for /dev/sd3 and /dev/sdc1

insert image description here
3.vgreate, create volume group vg01, and assign 2 physical volumes to vg01
insert image description here
insert image description here
4.lvcreate command, take 8G capacity from vg01 to create logical volume lvmail
insert image description here
5.mkfs command, format logical volume lvmail into XFS file system
insert image description here
6. Modify the /dev/fstab file and mount the logical volume lvmail to the /mnt/fang directory
insert image description here

4.2 Example of Logical Volume Expansion

4.2.1 Experimental content

The current capacity of lvmail is only 8G, which is not enough, and now it is required to expand the capacity to 5G

4.2.2 Operational Thinking

1. Because the remaining capacity of the volume group vg01 is less than 2G, which does not meet the 5G expansion requirements, it is necessary to allocate a new physical volume for vg01, and the total capacity of the physical volume must exceed at least 3G.
2. Because all the current physical volumes have been used, a new physical volume needs to be created.
3. Only one partition has been created for the newly added hard disk /dev/sdc, and it has been used. Now to set up a new partition

4.2.3 Experimental steps

1. Use the fdisk tool to create a second partition for the hard disk /dev/sdc. The partition type is set to LVM, and the system ID is 8e

insert image description here
2. Create a new physical volume /dev/sdc2
insert image description here
3. Add the physical volume /dev/sdc2 to volume group vg01

insert image description here

4. Add 5G capacity for the logical volume /dev/vg01/lvmai *
insert image description here
5. The xfs_growfs command enables the XFS file system to recognize the newly added space and realize file system expansion .
insert image description here

4.3 Enable disk quota support

1. Check whether the xfsprogs and xfs_quota packages have been installed in the centos7 system

insert image description here
2. Add the disk quota attribute and enable the quota support of the file system
Use the mount command to add usrqupta, grpquota mount parameters
insert image description here
insert image description here

5. Summary

  • PE is the smallest unit in LVM, the default is 4M, the smaller the PE, the higher the utilization rate

  • Physical volume creation command: pvcreate partition (whole hard disk)

  • Volume group creation command: vgcreate volume group name partition or entire hard disk

  • Logical volume creation command: lvcreate -n name -L Create size volume group name (from which volume group to take PE)

  • Format: mkfs.xfs

  • mount

  • Expansion:

    • First check whether the physical volume and the volume group are sufficient. If it is enough, there is no need to expand the capacity. If it is not enough:

    • PVC device

    • vgextend volume group name device

    • lvextend -L + extended capacity /dev/volume group name/logical volume name

    • xfs_growfs /dev/volume group name/logical volume name

Guess you like

Origin blog.csdn.net/fyb012811/article/details/131931769