The system prompts me that the capacity is insufficient, so use LVM to expand the capacity.
The system is RHEL7 (centos7 is almost the same)
Check the disk information and root directory first
fdisk -l
Note: sda is a hard disk, and the root directory of the system needs to be expanded. Here, the system root directory of RHEL is /dev/mapper/rhel-root (the system is different, and the root directory is different)
Shut down the system, go to vmware—>Settings—>Hard Disk—>Extension—>Enter a number greater than the current system memory—>Click Expand
Power on and then check disk information
fdisk -l
Note: It can be seen that the sda disk has increased, but the root directory has not yet been added, that is to say, the added space has not been partitioned, and has not been divided into the root directory.
Create a new partition for the newly added space
fdisk /dev/sda
n //Add new partition
p //Create primary partition 3//Partition number 3(1, 2 already has)
Press enter//Start sector selection default
Enter default//In order not to waste space
t //Change partition format
8 e //Change the partition format to LVM
p //View the prepared partition (blocks is the partition size in kb)
w //Save partition and exit
The partition is built but needs to be restarted to take effect
reboot
Convert partition to physical volume
pvcreat /dev/sda3
View existing volume group name
vgdisplay
Note: The name of the volume group is the name of the volume group after VG Name, where the volume group name is rhel, and VG Size is the size of the volume group. Pay attention to the comparison later
Start to expand and expand /dev/sda3 to volume group rhel
vgextend rhel /dev/sda3 //rhel is the volume group name
Check the volume group again
vgdisplay
Note: The size of VG Size has changed
Check the logical volume and remember his LV Path path
lvdisplay //The LV Path path here is/dev/rhel/root
Expand space for logical volume
lvextend /dev/rhel/root /dev/sda3 //lvextend parameters-L is the specified size if not entered-L +10G will use all space by default
Use the resize2fs command to update the file system size recognized by the system
resize2fs /dev/mapper/rhel-root
Resize2fs may report an error due to system version issues. Change the command xfs_growfs
xfs_growfs /dev/mapper/rhel-root
Finally, check
df -h
Note: It can be seen that the root directory (dev/mapper/rhel-root) has been increased
Of course, you can also expand the capacity by adding hard drives
Recommended Posts