In CentOS 7, you can use the fdisk command to expand the hard disk and operate on LVM type partitions. Here's a user-friendly step-by-step guide:
-
First, use the fdisk command to view the current partition situation. Open a terminal and execute the following command as root user:
fdisk -l
This will list the partition information for the current hard drive.
- Find the hard disk to be expanded, and record its device name, such as /dev/sda.
-
Execute the following command to start partitioning the hard drive:
fdisk /dev/sda
- In the fdisk command line interface, enter
p
to view the current partition table information. - Select an existing partition to modify, or create a new partition according to the required expansion size. If you choose to modify an existing partition, enter the corresponding partition number (such as 1, 2, 3, etc.); if you choose to create a new partition, enter it
n
. - Follow the prompts to enter the starting location and size of the partition. For capacity expansion, you can choose to move the end position of the partition backward, or directly increase the size of the partition.
- Enter
t
to change the partition type. The code to select the LVM type partition is8e
. - Enter
p
to view the updated partition table information to ensure that the modification takes effect. - Enter
w
save and exit the fdisk command line interface. This will partition the hard drive. -
Reload the partition table so the operating system recognizes the new partition. Execute the following command:
partprobe /dev/sda
-
Use the pvresize command to expand the LVM physical volume of the expanded partition. For example, if you want to extend the /dev/sda1 partition, execute the following command:
pvresize /dev/sda1
-
Confirm whether the expansion of the physical volume is successful. Execute the following command:
pvdisplay
Check that "PSize" and "PFree" in the output reflect the partition expansion.
- If necessary, you can also use the lvextend command to extend the logical volume to take advantage of the newly added physical volume space.
Through the above steps, you can use the fdisk command to expand the hard disk and operate on LVM type partitions. Please note that partitioning a hard drive is a sensitive task and must be done with care, making sure to back up important data and understanding the risks and implications before proceeding.