How I can increase my partition on CentOS, Debian or Ubuntu on LVM which is installed?

If you don’t have your Linux distribution installed with LVM, we recommend you to create a new partition instead of increasing the current.

Before continue check that Logical Volume Manager (LVM) is installed on your VPS.

1. Type the command lvdisplay. If LVM is not installed will show the output “No volume groups found. In this case you should create a partition, instead of expanding or reinstall the VPS.
In order to increase the partition, there should be first made an extra partition.

2. Type the command fdisk /dev/sda and then press enter. Then press ‘p’ to display the current partition table.

3. Look at this table where sector number ends with at the final partition. This can be found under the heading End. Write down this number (in the example 41 940 991).

Device     Boot Start      End Sectors Size Id Type
/dev/sda1  * 2048   499711 497664  243M 83 Linux
/dev/sda2       501758 41940991 41439234 19.8G  5 Extended
/dev/sda5       501760 41940991 41439232 19.8G 8e Linux LVM

4. Press ‘n’ to create a new partition. You will be asked whether the partition should be logical or primary. Use “p” for primary. Choose number for the new partition. Refer to the table in the previous step to confirm which partitions 1 to 4 are not yet occupied and choose one here of this.

5. Next you will be asked for a sector number. It is important that the new partition is connected to the previous sector (in the example 41 940 991). When choosing the sector you dial the number of the previous one, plus one (in the example 41 940 991 + 1 = 41 940 992) and press enter. Press enter again. The partition is created.

6. Press ‘t’ and then select the type of partition and select the number of the newly created partition. Then enter ‘8e’ for LVM.

7. Press ‘p’ to check the new partition (eg /dev/sda3).

8. Press ‘w’ to save the changes. We may get a lot of “ioctl” warnings just ignore them.

9. Reboot a VPS to activate the new partition.

The partition has been created, you can now increase the partition.

10. Firstly create a physical volume group for the newly created partition by using command “pvcreate /dev/sdaX”. Replace X with the partition number that you chose in step 4.

11. Find the particular logical volume and volume group name that you want to increase (root is default), through

lvdisplay | more

and write down respectively the’ LV Path ‘and’ VG Name “. are shown multiple logical volume groups.

12. Make this physical volume a part of the volume group in which the logical volume is that you want to enlarge with the command lgextend “vgextend [VG Name] /dev/sdaX for example

vgextend debian-vg /dev/sda3

13. Delete all the free space to the logical volume with the command lvextend “lvextend -l + 100% FREE [LV Path] for example

lvextend -l +100%FREE /dev/debian-vg/root.

14. As a final step we increase the actual filesystem with the command resize2fs “resize2fs [LV Path],” for example,

resize2fs /dev/debian-vg/root

. This may take some a time.

Pay attention! Within CentOS 7 resize2fs replaced xfs_growfs

15. Reboot VPS and make sure the partition is enlarged with the following command:

df -h

Leave a Reply

Your email address will not be published. Required fields are marked *