LVM logical volume management
1. Overview of LVM
LVM (Logical Volume Manager), logical volume management
Ability to dynamically adjust the disk capacity while keeping the existing data unchanged, thereby improving the flexibility of disk management
The /boot partition is used to store boot files and cannot be created based on LVM
- Basic concept of LVM mechanism
PV (Physical Volume, physical volume)
physical volume is the basic storage device of the LVM mechanism, usually corresponding to a common partition or an 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.
VG (Volume Group) is
composed of one or more physical volumes as a whole, which is called a volume group. Physical volumes can be dynamically added or removed from the volume group.
LV (Logical Volume)
A piece of space divided from a volume group to form a logical volume. Use tools such as mkfs to create file systems on logical volumes.
Two. LVM management commands
Features | Physical volume management | Volume group management | Logical volume |
---|---|---|---|
Scan | pvscan | vgscan | lvscan |
Create | pvcreate | vgcreate | lvcreate |
Display | pvdisplay | vgdisplay | lvdisplay |
Remove | pvremove | vgremove | lvremove |
Extend | —— | vgextend | lvextend |
Reduce | —— | vgreduce | lvreduce |
3. The main command steps of LVM operation
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 sdc1, and change the ID mark number of the partition type to "8e"
fdisk /dev/ sdb.
Fdisk /dev/ sdc
3. Create physical volume
pvcreate /dev/ sdb1 /dev/ sdc1
4. Create a volume group, the volume group name is vgnamel
vgereate vgname1 /dev/ sdb1 /dev/ sdb2
5. Create a logical volume, the logical volume is named lvname1, the capacity is 20GB, and the generated file path is /dev/vgname1/lvname 1
lvcreate -L 20G -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
df -hT
7. Re-expand
vgextend vgname1 /dev/ sdc2
lvextend -L +10G /dev/vgname1/ lvname 1
resize2fs /dev/ vgname1/ lvname1 #Refresh the file system capacity
Four. LVM experiment operation steps
1. Shut down the host, add two new hard disks, restart the host
and check the partition status after creation:
2. First use the fdisk tool to divide the disk devices /dev/sdb and /dev/sdc into primary partitions sdb1 and sdc1, and change the ID mark number of the partition type to "8e"
Check the partition status: fdisk -l
3. Create a physical volume
pvcreate /dev/ sdb1 /dev/ sdc1
4. Create a volume group named vgnamel
vgcreate vgname1 /dev/ sdb1 /dev/ sdc1
5. Create a logical volume, logical volume The name is lvname1, the capacity is 20GB, and the generated file path is /dev/vgname1/lvname 1
lvcreate -L 20G -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
df -hT
7. Re-expand
vgextend vgname1 /dev/ sdc2
lvextend -L +10G /dev/vgname1/ lvname 1
resize2fs /dev/ vgname1/ lvname1 #Refresh the file system capacity