Table of contents
Add 20G of disk space to the virtual machine.
The disk is mounted as a physical volume
Let the extended disk take effect
Background introduction
The current disk space of the virtual machine is limited and needs to be expanded. As shown in the figure below, the space of /var has reached 38% and is only 1G in size. The author plans to expand it.
As can be seen from the figure, since the entire system basically uses LVM logical volume partitioning, insufficient disk space can be easily expanded. Prepare to add 20G of disk space to /var. Convenient to install other software.
Add 20G of disk space to the virtual machine.
After expansion, you need to restart the virtual machine to discover the newly added disk.
After restarting, additional /dev/sdb disks were discovered, and the operating system discovered the disks.
The disk is mounted as a physical volume
First partition the disk
fdisk /dev/sdb
n
p
t
8th
w
After partitioning, check it out.
You can see that the sdb partition has been divided into a primary partition of sdb1. We will create a physical volume on this sdb1.
Create physical volume
pvcreate /dev/sdb1
Check vgs. Currently, the system only has one volume group, VG.
Okay, here's the idea, that is, directly expand the volume group, and then allocate the remaining maximum logical volume directly from the volume group.
Extend volume group
vgextend centos /dev/sdb1
Expand logical volume
To whom should it be extended? We can use df -hT to find the logical volume that needs to be extended.
We are extending var. So you see that the logical volume is /dev/mapper/centos-var
Execute command: lvextend -l 100%FREE /dev/mapper/centos-var
Allocate all remaining space in the volume group to the logical volume of var.
Let the extended disk take effect
xfs_growfs /dev/mapper/centos-var
Check the expansion status
df -hT to view added volumes
See it has taken effect.
Final summary:
There are a lot of screenshots here and now, let’s briefly summarize them.
1. Add disk scsi, 20G, reboot.
2. Use fdisk -l to view and partition fdisk /dev/sdb 8e
3. Create a physical volume pvcreate. View a wave of vgs, lvs, and pvs.
4. Expand the volume group vgextend centos /dev/sdb1 centos is the original volume group.
5. Expand the logical volume lvextend -l 100%FREE /dev/mapper/centos-var
6. Write to disk xfs_growfs /dev/mapper/centos-var
7. df -hT to view the added volume.