Article overview

Help article

How do I grow a partition in Linux?

First you will need to check if the Logical Volume Manager is installed on your VPS. Type the command 'lvdisplay'. If you get a table with the name Logical Volume' it is proof that LVM is installed. If LVM is not installed you will receive the output 'No volume groups found'. In this case you will need to reinstall your VPS or choose to add a partition instead of growing one.Note: If not mentioned, a command is always followed by an enter.

In order to grow a partition you will first have to create one:

  1. First make sure that you are logged in as root, if your are not then use the command "su -". Use the command 'fdisk /dev/vda' and subsequently press Enter. Press 'p' to show the current partitioning table.
  2. Use the table to find the cylinder number on which your last partition ends. You can find this number beneath the header 'End'. Document the number (104855551 in the screenshot). Also note which of the primary partition numbers from 1 to 4 are not shown in the table. Numbers 3 and 4 are not shown in the screenshot, so in these partitions are still available.
  3. Press 'n' to create a new partition. You will be asked to create a logical partition or a primary partition. Choose for primary with 'p'. Choose a number for the new partition. You will know which numbers you can choose from because you documented the free partition numbers in step 2.
  4. You will be asked to submit a cylinder number. It is important that the new partition closely follows the cylinder number mentioned in step 2. Therefore you will need to submit the cylinder number from step 2 +1 (in our example 104855551+1=104855552). Press enter and press enter again to accept default settings. The partition is now created.
  5. Press 't' to submit the partition type and subsequently choose the number of the partition you just created. Now submit "8e" in order to choose LVM for this partition.
  6. Press 'p' to check if the new partition was created correctly. When you choose partition number 3 you should be able to see /dev/vda3 . Press 'w' to save your settings. A 'ioctl' warning might be shown as output. You can ignore this. Reboot your VPS to activate the partition. After this the partition is activated and it is time to grow it.
  7. First create a physical volume group for the new partition with the command 'pvcreate /dev/vdaX'. Replace the X with the partition number from step 3.
  8. Find the logical volume name and the volume group name that you want to grow by using the command 'lvdisplay | more'. Document the LV name and the VG name. Multiple logical volume groups will be shown. Choose the LV name and VG name of the group that you would like to choose (root is default).
  9. Now extend the volume group by typing 'vgextend [vgname] /dev/vdaX'. Replace the X with the partition number from step 2.
  10. Now extend the logical volume by using the just acquired free space 'lvextend -l +100%FREE [LV PATH]' . By adapting the percentage you can change how much free space will remain.
  11. The final step is growing the actual file system with the command 'resize2fs [LV PATH]'. In some cases (depending on the filesystem) you can use 'resize2fs [LV PATH]' in order to increase the partition. Reboot the VPS and check if the disk space was successfully added with 'df -h' .

Do you have a good idea?

Give us your idea! If it's popular we'll add it to the wishlist!

Has this article been helpful?

Create an account or log in to leave a rating.


Create an account or log in to be able to leave a comment.

Are you stuck?

Ask one of our specialists to assist you

Contact us