Share an article, see watermark for the source.

A few days ago I encountered such a situation:

A server is provided as a VM. If you run the df -h command, you can find that the disk space of the server is only 30 GB. However, if you run the fdisk -l command, you can find that a 160 GB disk space is not mounted.

I have dealt with this kind of problem for several times before, but AFTER a period of time, I forgot it. I take this opportunity to share this case and deepen my memory.

Before we get to this example, let’s talk briefly about the logical volume management (LVM) that is used to deal with this problem.

Logical Volume Management (LVM) is a versatile hard disk system tool. It works great on Linux and other similar systems. Traditional partitions use fixed-size partitions, which can be cumbersome to resize. However, LVM can create and manage “logical” volumes rather than directly using physical disks. This allows administrators to flexibly manage the expansion and contraction of logical volumes without damaging stored data. Feel free to add new hard disks to LVM to directly extend existing logical volumes. LVM does not require a reboot to let the kernel know of the partition’s existence.

LVM uses a hierarchical structure, as shown in the figure below.


At the top of the figure, the actual physical disk with its partitions and the physical volume (PV) on it is shown first. One or more physical volumes can be used to create volume groups (VGS). Logical volumes (LVS) can then be created based on volume groups. You can create as many logical volumes as you want as long as there is free space in the volume group. File systems are created on logical volumes that can then be mounted and accessed on the operating system.

Example: Disk expansion

1. Check the available disk space and find that the available disk space is more than 30

[root@server tomcat-atm]# df -hCopy the code


2. View the details about the disk space pair. A 160 GB disk is displayed

[root@server tomcat-atm]# fdisk -lCopy the code


3. Create disk partitions and use type 8E to make them available to LVM

[root@server tomcat-atm]# fdisk /dev/sdbCopy the code


4. Create a physical volume

root@server tomcat-atm]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully createdCopy the code

5. Check whether the physical volume is created

[root@server tomcat-atm]# pvdisplayCopy the code


6. Expand the volume group

[root@server tomcat-atm]# vgextend centos /dev/sdb
Volume group "centos" successfully extendedCopy the code

7. View the volume group

[root@server tomcat-atm]# vgdisplayCopy the code


8. Expand the LVM volume

[root@server tomcat-atm]# lvextend -l +100%FREE /dev/mapper/centos-root
Size of logical volume centos/root changed from 35.47 GiB (9080 extents) to 185.50 GiB (47489 extents).
Logical volume root successfully resized.Copy the code

9. Expand capacity

[root@server tomcat-atm]# xfs_growfs /dev/mapper/centos-rootCopy the code


10. Check whether the disk space is successfully expanded



If you want to learn more about Linux knowledge systems, you can take a look at the hundreds of knowledge systems we spent over a month organizing hundreds of hours:

“Linux cloud computing from entry to master” Linux learning entry tutorial series combat notes