Linux--LVM and Disk Quota

Preface

Every Linux user will encounter such a dilemma when installing Linux: When partitioning the system, how to accurately evaluate the LVM and allocate the capacity of each hard disk partition, because the system administrator not only has to consider the current capacity of a certain partition, but also Also foresee the maximum capacity that the partition may require in the future. Because if the estimation is not accurate, when a certain partition is not enough, the administrator may even have to back up the entire system, clear the hard disk, repartition the hard disk, and then restore the data to the new partition.

1. Overview of LVM

Insert picture description here
Insert picture description here

1.1, PV (Physical Volume, physical volume)

The physical volume is the basic storage device of the LVM mechanism, and usually corresponds to an ordinary partition or the entire hard disk. When creating a physical volume, a reserved block is created at the head of the partition or hard disk to record the attributes of LVM, and the storage space is divided into basic units (Physical Extent, PE) with a default size of 4MB to form a physical volume

1.2, VG ​​(Volume Group, volume group)

Volume group: One or more physical volumes form a whole. In the volume group, you can dynamically add or remove physical volumes. Many physical volumes can form different volume groups. The name of the volume group is customized by the user.

1.3, LV (Logical Volume, logical volume)

Logical volumes are built on volume groups and have no direct relationship with physical volumes. For logical volumes, each volume group is a whole, and a small piece of space is "cut out" from this whole as the basis for users to create file systems , This small space is called a logical volume, after using tools such as mkfs to create a file system on the logical volume, it can be mounted to the directory in the Linux system for use

Two, manage LVM

LVM management commands mainly include three categories: PV physical volume management, VG volume group management and LV logical volume management

The corresponding command program files start with "PV" "VG" "LV", as shown in the figure
Insert picture description here

2.1, PV physical volume management

2.1.1, pvsan command

The pvscan command is used to scan all physical volumes in the system and output related information.

2.1.2, pvcreate command

pvcreate is used to convert a partition or an entire hard disk into a physical volume, mainly adding LVM attributes and dividing PE storage units. This command needs to use the hard disk or partition device file as a parameter

2.1.3, pvdisplay command

The pvdisplay command is used to display the detailed information of the physical volume. You need to use the specified physical volume as the command parameter. By default, all physical volume information will be displayed.

2.1.4, pcremove command

The pvremove command is used to restore the physical volume to a normal partition or disk, and is no longer used in the LVM system. The removed physical volume will not be recognized by the pvscan command

2.2, VG ​​volume group management

2.2.1, vgscan command

The vgscan command is used to scan the established LVM volume groups and related information in the system

2.2.2, vgcreate command

The vgcreate command is used to create one or more physical volumes as a volume group, and the first command parameter is used to set the name of the new volume group. Then specify the physical volumes that need to be added to the volume group as parameters in turn

2.2.3, vgdisplay command

The vgdisplay command is used to display the detailed information of each volume group in the system. You need to specify the volume group name as the command parameter (if the volume group name is not specified, the information of all volume groups will be displayed)

2.2.4, vgremove command

The vgremove command is used to delete the specified volume group. Just specify the volume group name as a parameter. When deleting, make sure that there are no logical volumes in use in the volume group

2.2.5, vgextend command

The vgextend command is used to extend the disk space of a volume group. When a new physical volume is created and needs to be added to an existing volume group, the vgextend command can be used. The first parameter of the vgextend command is the name of the volume group whose capacity needs to be expanded, followed by the physical volumes that need to be added to the volume group

2.3, LV logical volume management

2.3.1, lvscan command

The lvscan command is used to scan the established logical volumes and related information in the system

2.3.2, lvcreate command

The lvcreate command is used to partition space from the specified volume group to create a new logical volume. You need to specify the logical volume size, name, and the name of the volume group as parameters. After the logical volume is created, it can be accessed through a device file in the form of "/dev/volume group name/logical volume name" (or /dev/mapper/volume group name-logical volume name)

2.3.3, lvdisplay command

The lvdisplay command is used to display detailed information about logical volumes. Need to specify the device file of the logical volume as a parameter, or use the volume group name as a parameter

2.3.4, lvextend command

The lvextend command is used to dynamically expand the space of a logical volume. When the currently used logical volume space is insufficient, additional space can be divided from the volume group for expansion. Just specify the size of the increased capacity and the location of the logical volume file. The premise is that there is still unallocated disk space in the volume group, otherwise the volume group capacity needs to be expanded first.

2.3.5, lvremove command

The lvremove command is used to delete the specified logical volume, directly using the device file of the logical volume as a parameter

2.4, LVM application examples

2.4.1, command demonstration

First, add two 10G hard disks to the VMware software centos 7 system
Insert picture description here

Convert the /dev/sdb and /dev/dbc partitions to physical volumes.
Insert picture description here
Integrate the above two physical volumes to create a volume group named vg01
Insert picture description here
. Create a logical volume named lv01 in the vg01 volume group and set the capacity to 15GB.
Insert picture description here
Use mkfs Command to format the logical volume lv01, create an xfs file system, and mount it to the /maibox directory.
Insert picture description here
Insert picture description here
Use the lvextend command to add 2GB to the logical volume lv01, and then use the xfs-grows command to update the file size recognized by the system
Insert picture description here
Insert picture description here

Three, disk quota

3.1 Overview of Disk Quota

3.1.1. Conditions for achieving disk quota

Insert picture description here

3.1.2 Features of Linux Disk Quota

Insert picture description here

3.2 Disk quota steps

Temporary settings (mostly achieved through commands), permanent settings (all configured through source files)

Most of the command settings are temporarily effective and invalid after restart

Configuration file is permanent

Edit the quota settings of user and group accounts: the group quota is fixed,

Insert picture description here

3.3 Start disk quota support

Add usrquota, grpquota mounting parameters,
temporary settings need to add -o parameter

3.4 Disk quota management

Edit quota settings for user and group accounts

Use the xfs_quota command to edit the quota settings
xfs_quota -x -c'limit -u bsoft =N bhard=N isoft=N ihard=N username' mount point
Common options
-u //user
-g //group
-x //expert Mode
-c //command (command)
limit field
bsoft //soft capacity limit
bhard //hard capacity limit (block block)
isoft //soft limit
ihard //number hard limit (inode node)

Verify disk quota function

Switch to set the quota partition (mount directory)
creates the specified number of files: the touch command, or cp command
creates the specified file capacity: dd command, or the cp command (equivalent to the copy command dd, generally used for verification)
See Quota usage
xfs_quota -x -c'report option' mount point
report common options
-a //all all
-i //nodes, number
-b //block block, capacity
-u //user
-g //group

View all user quotas
[root@localhost ~]# xfs_quota -x -c'report -a' /mount point

View user quota information, see capacity information
[root@localhost ~]# xfs_quota -c'quota -uv username' /mount point

View user quota information, see node information
[root@localhost ~]# xfs_quota -c'quota -iuv username' /mount point

Copy files continuously (/mail/demo01.txt is the file I just created), copy 1M each time, copy N times continuously
[root@localhost ~]# dd if=/dev/zero of=/mail/demo01.txt bs =1M count=80

Guess you like

Origin blog.csdn.net/weixin_48191211/article/details/107337225