1 Viewing Current disk conditions
Fdisk-l
/DEV/SDA1 2048 6143 2048-up Linux
/DEV/SDA2 * 6144 1054719 524288 Linux
/dev/sda3 1054720 10508287 4726784 8e Linux LVM
I only/dev/sda a disk, the system has used the default sda1 sda2 Sda3, where sda1 forgot what to do, sda2 used as a logical volume BOOT,SDA3, is the base disk of other logical disks. Since up to 4 primary partitions are supported, it is now necessary to create all the remaining space as an extended partition, and then create logical partitions on this extended partition, which can be built arbitrarily and how much to build.
2 Creating a new extended partition and logical partition
Fdisk/dev/sda
Input n
Partition Type:
P Primary (3 primary, 0 extended, 1 free)
E Extended
Select (Default e): (choose e here, create an extended partition, assign all the space to it)
Once the previous extended partition is created, enter n again, because the primary partition is exhausted, so let's create the logical partition, start sector default, end sector +500m
Enter P to view the current creation
/DEV/SDA1 2048 6143 2048-up Linux
/DEV/SDA2 * 6144 1054719 524288 Linux
/dev/sda3 1054720 10508287 4726784 8e Linux LVM
/DEV/SDA4 10508288 41943039 15717376 5 Extended (the extended partition (primary partition) of all spaces is crossed.)
/dev/sda5 10510336 11534335 512000, Linux (the logical partition actually used)
After creating the logical partition, enter W to write the information to the system to complete the creation
3 Formatting a newly created logical partition
Before this, use Partprobe to refresh the partition table, otherwise the/DEV/SDA5 is not recognized by the system, some cases may need to restart the server (such as virtual machine)
Mkfs.ext4/dev/sda5
4 Creating a new PV
Pvcreate/dev/sda5
5 Add PV to the VG where root is located
The df-l and Vgdisplay commands allow you to know that root is inside a vg named CentOS.
Vgextend Centos/dev/sda5
Use Vgdisplay again to see that the VG has grown (500m of free space)
6 The LV where the extension root resides
The lvdisplay can be used to know that Root's LV path is/dev/centos/root
Lvextend-l +100%free/dev/centos/root
This time through Lvdisplay can see Root has been expanded, but df-l see the root is the original size, use the following command to sync
Resize2fs/dev/centos/root (centos7 ago)
Or
Xfs_growfs/dev/centos/root (CENTOS7)
7 Viewing results
Df-l to view current disk conditions
Extended root partition under Linux