Cart

    Sorry, we could not find any results for your search querry.

    How do I grow a partition in Linux?

    When upgrading the disk space of your VPS, this additional space must be assigned to a partition before your OS can make use of it. After upgrading your VPS or adding an SSD add-on the additional space will not be visible in your operating system or control panel until you've gone through these steps.

    The steps in this article are aimed at CentOS, Debian and Ubuntu, but are equally valid for many other (derived) operating systems. If your Linux distro has not been installed in combination with LVM, we recommend creating a new partition or using our gparted manual.

    • Create a snapshot before following these steps. The procedure described in this manual is sensitive to mistakens, so it is preferable to have a fallback option.
       
    • Use sudo, or the root user when following the steps below.
       
    • Our DirectAdmin, Plesk and cPanel installations come with LVM. This article can as such be used for adding disk space to VPSs with these control panels.

     

    Step 1

    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 have three options for how to proceed:

    • Use the manual for adjusting the partitions via gparted.
    • Assign the added disk space to a new partition.
    • Reinstall the VPS.

     

    Step 2

    Start fdisk (a command-line partitioning utility) using the command:

    fdisk /dev/vda
    

     

    Step 3

    Press the 'p' key on your keyboard to show the existing partition table. The output will look something like:

    partition table

    Use the table to find the cylinder number on which your last partition ends. You can find this number beneath the header 'End'. 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 this example these partitions are still available.


     

    Step 4

    Press the 'n' key to create a new partition. This may sound confusing, but with LVM this is required to be able to assign the new disk space to an existing 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 from amongst the free partition numbers which you've noted down at the end of step 3.


     

    Step 5

    You will be asked to submit a cylinder number. It is important that the new partition closely follows the cylinder number mentioned in step 3. Therefore you will need to submit the cylinder number from step 2 +1 (in our example 104855551+1=104855552). Press the 'Enter' key twice to accept default settings. The partition is now created.


     

    Step 6

    Press 't' to select the partition type and subsequently choose the partition type number for the partition you just created. In this case, type '8e' in order to choose LVM for this partition.


     

    Step 7

    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 .


     

    Step 8

    Press 'w' to save your settings. A 'ioctl' warning might be shown as output. You can ignore this.


     

    Step 9

    Reboot your VPS to activate the partition. After rebooting, the partition is activated and it is time to grow it.


     

    Step 10

    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.

    You may now see the message 'Device /dev/vdaX not found (or ignored by filtering)'. In that case the partition table needs to be reloaded using the command:

    partprobe /dev/vda

     

    Step 11

    Find the logical volume name and the volume group name that you want to grow by using the command:

    lvdisplay | more

    Note the 'LV path' and the 'VG name'. Multiple logical volume groups will be shown.


     

    Step 12

    Ensure the physical volume is part of the same volume group as the logical volume which you'd like to enlarge (i.e. your existing partition):

    vgextend vgname /dev/vdaX
    • Replace vgname using the VG name you wrote down in the previous step
    • Replace X in vdaX with the partition number from step 3/4

     

    Step 13

    Now extend the logical volume using all available disk space with the command: 

    lvextend -l +100%FREE lvpath

    Replace lvpath with the LV Path noted in step 11, for example:

    lvextend -l +100%FREE /dev/mapper/vg_transip-lv_root

     

    Step 14

    The final step is growing the actual file system with the command resize2fs (xfs_growfs for CentOS 7, see below):

    resize2fs lvpath

    Replace lvpath with the LV Path noted down in step 11, for example:

    resize2fs /dev/mapper/vg_transip-lv_root

    This command may take a while to process.

    CentOS 7 and newer

    Please note: if you're not using ext4 in CentOS, you'll need to use xfs_growfs instead. In order to use assign all available space use the command:

    xfs_growfs /
    

     

    Step 15

    Reboot the VPS and check if your partition has indeed grown using the command:

    df -h
    

     

    You're now ready to start using your newly available disk space!

    Should you have any questions left regarding this article, do not hesitate to contact our support department. You can reach them via the ‘Contact Us’ button at the bottom of this page.

    Need help?

    Receive personal support from our supporters

    Contact us