LVM can dynamically adjust the disk capacity while keeping the existing data unchanged, thereby improving the flexibility of disk management
Because the /boot partition is used to store boot files, the /boot partition cannot be created based on LVM
LVM is composed of multiple disk partitions
name
Description
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 (PE) with a default size of 4MB to form a physical volume. (Physical volume is a disk partition created by fdisk)
ON
PE is the basic unit of a physical volume with a size of 4M. Determined by the size of the logical volume and volume group
VG (volume Group, volume group)
One or more physical volumes form a whole, which is called a volume group, in which physical volumes can be dynamically added or removed
LV Logical volume, logical volume)
A piece of space divided from the volume group forms a logical volume. Use tools such as mkfs to create a file system on the logical volume
LVM management commands and operating steps
LVM management commands
Features
PV management
VG management
LV management
Scan
pvscan
vgscan
lvscan
Creata build
pvcreata
vgcreata
lvcreata
Display
pvdisplay
vgdisplay
lvdisplay
Remove
pvremove
vgremove
lvremove
Extend
——
vgextend
lvextend
Reduce
——
vgreduce
lvreduce
The main operation steps of LVM
1. Shut down the host, add two new hard disks, and restart the host
2. First use the fdisk tool to divide the disk devices /dev/sdb and /dev/sdc into primary partitions sdb1 and sdcl, and change the ID mark number of the partition type to "8e". The partition created with fdisk is created directly without formatting Physical volume
fdisk /dev/sdb fdisk /dev/sdc
3. Create a physical volume
pvcreate /dev/sdb1 /dev/sdc1
4. Create a volume group, the volume group is named vgnamel
vgcreate vgname1 / dev/sdb1/ dev/sdb2
5. Create a logical volume, the logical volume is named lvname1, the capacity is 15GB, and the generated file path is /dev/vgname1/lvname1
lvcreate -L 15G -n lvname1 vgname1
6. Format the logical volume, create an XFS file system, and mount it to /opt
mkfs -t xfs / dev/vgname1/lvname1
mount /dev/vgname1/lvname1 /opt
7. Further expansion
vgextend vgname1 / dev / sdc2
lvextend -L +5G /dev/ vgname1/ lvname1 If there is no "+" in front of 5G, it means that the disk space is at most 5G
xfs_growfs /dev/vgnamel/lvname1 refresh file system capacity (xfs)
resize2fs /dev/vgnamel/lvname1 refresh the file system capacity (ext4)
Disk quota
Overview of Disk Quota
Function: Limit the space used by the disk for the specified user or group, or limit the number of files created
Conditions for achieving disk quota
Need Linux kernel support
Install xfsprogs and quota packages
Features of Linux Disk Quota
Scope: for the specified file system (partition)
Restricted object: user account, group account
Restriction type: disk capacity, number of files
Limitation method: soft limit, hard limit
Why use the disk quota function?
Because when the disk space of the Linux root partition is exhausted, the Linux operating system will no longer be able to create new files, and at the same time, failures such as service program crashes and system failures may occur. Therefore, in order to avoid problems like insufficient disk space in the server, the disk quota function can be enabled to limit the disk space and the number of files used by the user in the specified file system (partition) to prevent individual users from maliciously or unintentionally occupying a large amount. Disk space to maintain the stability and continuous availability of system storage space.
In the CentOS system, different file systems use different disk quota configuration management tools. For example, the XFS file system is managed by the xfs quota tool; the EXT3 and EXT4 file systems are managed by the quota tool.
Disk quota operation steps (CentOS7)
1. Check whether the xfsprogs and xfs_quota packages have been installed
View: rpm -q xfsprogs quota
If not: yum install -y xfsprogs quota
2. Mount the file system in a way that supports the quota function
umount / dev / vgname1 / lvname1 unmount
mount -o usrquota,grpquota /dev / vgname1/ lvname1 /opt Add mount parameters "usrquota, grpquota" to increase support for user and group quota functions
Because of the temporary mounting, the mounting of the mount will be invalid after the restart, so use the following editing /etc/fstab to mount to prevent the restart from failing