Copyright statement: This article is the original article of the blogger and follows the CC 4.0 by-sa copyright agreement. Please attach the original source link and this statement for reprinting.
Link to this article: https://blog.csdn.net/qq_38685754/article/details/85135264
LVM is the abbreviation of Logical Volume Manager (Logical Volume Management), which is implemented by Heinz Mauelshagen on the Linux 2.4 kernel. LVM logically aggregates one or more hard disk partitions, which is equivalent to a large hard disk to use. When the hard disk space is not enough to use, you can continue to add other hard disk partitions to it, which can realize the dynamic management of disk space , Compared with ordinary disk partitions, it has great flexibility.
Mainly introduce the following LVM terms:
The physical media (The physical media): This refers to the storage devices of the system: hard disks, such as: /dev/hda1, /dev/sda, etc., are the lowest storage unit of the storage system.
Physical volume: A physical volume refers to a hard disk partition or a device that has the same function as a disk partition (such as RAID). It is the basic storage logical block of LVM, but is different from basic physical storage media (such as partitions, disks). Etc.), but it contains management parameters related to LVM.
Volume Group: An LVM volume group is similar to a physical hard disk in a non-LVM system, which is composed of physical volumes. One or more "LVM partitions" (logical volumes) can be created on the volume group. The LVM volume group consists of one or more physical volumes.
Logical volume: LVM logical volume is similar to hard disk partition in non-LVM system, and file system (such as /home or /usr, etc.) can be established on the logical volume.
PE (physical extent): Each physical volume is divided into a basic unit called PE (Physical Extents). A PE with a unique number is the smallest unit that can be addressed by LVM. The size of the PE is configurable and the default is 4MB.
LE (logical extent): Logical volumes are also divided into basic addressable units called LE (Logical Extents). In the same volume group, the size of LE and PE are the same, and there is a one-to-one correspondence.
Simply put:
PV: is a physical disk partition
VG: The physical disk partition in LVM, which is PV, must be added to VG. VG can be understood as a warehouse or several large hard disks.
LV: It is the logical partition divided from the VG
1、 Switch root user
2、# fdisk -l //Through this command, check the remaining space
3、 Turn off the virtual machine and expand the disk size.
4、 Boot up, log in as the root user, enter the command line
5、 List the list of commands and add partitions (you can view the command “n” means adding a new partition)
Enter n and enter p by default after the prompt, which is used to create the partition number. Linux virtual machines generally have two sdas, sda1 and sda2, so the default input 3 indicates that a new volume sda3 is allocated. After entering 3 or pressing Enter, you will find the disk sector that prompts you. Generally, select default and press Enter all the way.
Command(m for help): w //w Save all and exit, there will be the following information after saving
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The newtable will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
6、 The default assigned Linux logical volume group management is not LVM and the id is changed to 8e (8e means LVM), so you need to change the newly assigned sda3 to the same LVM as sda2, and then use fdisk to change it to LVM.
# fdisk /dev/sda
Command(m for help): t
Partition number(1-3,default3):3
Hex code(type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'Command(m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The newtable will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
# reboot //Restart the system to enable the operation application
7、 Check the partition with fdisk -l, you will find that sda3 has become LVM and sda has become larger, but the actual file system has not become larger.
8、 Expand new partition
9、 vg has been extended, but lv has not been extended, so to extend lv, use the lvextend command
# lvextend -L +50G /dev/mapper/centos-root
Size of logical volume centos/root changed from<17.00GiB(4351 extents) to <67.00GiB(17151 extents).
Logical volume centos/root successfully resized.
10、 Enter the command on the command line to make the system re-read the size
# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from4455424 to 17562624
11、 Then use df -h to view, you can see that the root directory space becomes larger.
Recommended Posts