Increase the root physical volume size of a server after replacing the hard disk by the new one larger

This article describes how to manually increase the root physical volume size of a server after replacing the hard disk by the new one larger. Follow the first steps to see if your physical volume size needs to be increased.

Step 1

After the disk space increase for your server has completed, log into the server via SSH.

Step 2

Type fdisk -l and press ENTER. You are looking for the total size of the disk highlighted below in red. You should also notice that one of the partitions is Linux LVM.


 

Step 3

Type the pvs command which stands for physical volume show and press ENTER.


 
Next, check to make sure that the difference in size between the fdisk output and the PSize value shown from the pvs command is more than 100GB. If the difference in size between the two is less than 100GB, you do not need to follow the next steps.

Step 4

Type fdisk /dev/xvda (the value after fdisk may change depending on your server. You should use the Disk name shown in the output of fdisk -l) and press ENTER.

Tip: The fdisk command actually stands for format disk and the value afterward specifies the location of the disk.


 

Step 5

Fdisk will prompt you to enter a command. Type p for print and press ENTER to print the partitions on the disk.

You will see a similar output as the fdisk -l command. The last partition should be an LVM type. We will delete this partition and re-create it to use all available space from the disk size increase. Deleting the partition and creating a new, larger partition in its place will not delete the data on the disk. We must delete and recreate the partition since it is not possible to resize.

Tip: If at any time you believe you have made a mistake, type q and press ENTER to quit without saving changes and then start the process over.


 

Step 6

Type d for delete and press ENTER.
Type 3 and press ENTER to specify the 3rd partition is the one to delete.


 

Step 7

Type p and press ENTER again to show the partitions. The third partition should now be gone.


 

Step 8

Type n to create a new partition and press ENTER.
Next, type p for primary parition and press ENTER.
Type 3 as the partition number and press ENTER.
When prompted for the First cylinder, simply press ENTER to use the default value.
When prompted for the Last cylinder, simply press ENTER again to use the default value.


 

Step 9

Type p and press ENTER again to view the partitions. There should now be a third partition. You will notice that the partition is no longer a Linux LVM type but simply a Linux type. We will have to change this.


 

Step 10

Type t to change the partition type and press ENTER.
Type 3 as the partition number and press ENTER.
Type 8e as the Hex code and press ENTER.

You should see that the partition type has been changed to Linux LVM.


 

Step 11

Type p and press ENTER to list the partitions again. This time the third partition should be Linux LVM as we just changed it in the last step.


 

Step 12

Type w and press ENTER to write (save) changes and quit fdisk.

You will receive a notice that the new partition table will be used after the next reboot.


 

Step 13

Reboot the server by typing shutdown -r now and pressing ENTER.


 

Step 14

Give the server a few minutes to reboot, then connect via SSH again.

Type fdisk -l and press ENTER again to check the disk size. The disk size listed by fdisk should not have changed.


 

Step 15

Type pvs and press ENTER to check the physical volume size. The value should not have changed and the difference between the two should still be off by more than 100GB.


 

Step 16

Type pvresize /dev/xvda3 (the value after fdisk may change depending on your server. You should use the Disk name shown in the output of fdisk -l) and press ENTER.

You will receive a notice that the physical volume has been resized.


 

Step 17

Type pvs one last time and press ENTER. The PSize value should now be slightly less that thefdisk output size, but not by more than 100GB. You are now finished!


 
Step 18
You may want to Increase the Size of the Logical Volume now to increase a logical volume that may be running out space.