Cart

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

    Expanding the partition of your Linux VPS via LVM

    When you expand the disk space of your VPS, this extra space must first be assigned to a partition and/or LVM configuration before your OS can make use of it. After upgrading your VPS package or ordering an SSD AddOn, this extra space will therefore not be immediately visible in your operating system or web control panel. To use the extra space, there are two alternatives:

    • Expand an existing partition or logical volume (this is preferred), see this guide.
    • Create a new partition and add it to LVM, as described in this article.

    The steps below work for CentOS Stream, AlmaLinux, Rocky Linux, Debian and Ubuntu, but also work for many other (derived) operating systems that are configured with LVM. If you are not using LVM, we recommend either creating a new partition or following the guide for expanding a partition via gparted.

    • Before modifying partitions or logical volumes, always create a snapshot. Changes like these are error-prone and a snapshot makes recovery possible if something goes wrong.
       
    • Use sudo or the root user to complete the steps in this article.
       
    • Always check first on which device your extra space has become available. In this guide we use examples such as /dev/vda, but on your VPS this could also be /dev/sda or, for example, /dev/nvme0n1.
     

     

    Step 1

    First, check on which block device the extra space has become available and how your partitions are currently laid out. Use the following command:

    lsblk

    Note the name of the disk on which your existing LVM partitions are located, for example /dev/vda, /dev/sda or /dev/nvme0n1.


     

    Step 2

    Next, check whether your VPS is actually using LVM. Use the following commands:

    pvs
    vgs
    lvs

    If these commands show output containing a physical volume, volume group and logical volume, your VPS is using LVM and you can follow this guide.

    If no LVM output is shown, then you cannot follow this guide and you have the following options:


     

    Step 3

    Now start fdisk on the disk to which you have added extra space. In the command below, replace <disk> with the device you found in step 1:

    fdisk /dev/<disk>

    Examples are:

    fdisk /dev/vda
    fdisk /dev/sda
    fdisk /dev/nvme0n1

     

    Step 4

    Press p to display the current partition table and check which partitions already exist. Pay particular attention to the existing LVM partition(s) and the available free space.

    Note which partition number is still available for the new partition.


     

    Step 5

    Press n to create a new partition.

    Then:

    • Choose the next available partition number.
    • For the first sector, use the default value suggested by fdisk, unless you intentionally want to use a different layout.
    • Then also use the default value for the last sector to use all remaining free space, or specify a size yourself if you only want to use part of it.

    Please note: on systems with an MBR/DOS partition table, you may still be asked to choose between primary and extended/logical. In that case, choose primary. On GPT systems, you will usually not be asked this question.


     

    Step 6

    Now set the type of the new partition to Linux LVM.

    To do so, press t and select the number of the partition you have just created.

    • If you are using an MBR/DOS partition table, this is usually type 8e.
    • If you are using GPT, choose the Linux LVM partition type when fdisk asks you to do so.

     

    Step 7

    Press p again to check whether the new partition is visible and has been assigned the correct type. It will appear as, for example:

    /dev/vda3
    /dev/sda3
    /dev/nvme0n1p3

     

    Step 8

    Press w to save the changes.

    Then reload the partition table so that the operating system recognises the new partition immediately:

    partprobe /dev/<disk>

    You may see a warning appear. Afterwards, use lsblk to check whether the new partition is visible.


     

    Step 9

    Now make the new partition into a physical volume using the following command:

    pvcreate /dev/<partition>

    For example:

    pvcreate /dev/vda3

    If you receive a message such as Device not found, first check with lsblk whether the partition is visible and, if necessary, run partprobe again.


     

    Step 10

    Next, find which volume group and logical volume you want to expand. Use:

    vgs
    lvs
    lvdisplay

    Make a note of:

    • the name of the VG in which your root or data volume is located
    • the path of the LV you want to expand, for example /dev/vg_transip/lv_root or /dev/mapper/vg_transip-lv_root

     

    Step 11

    Add the new partition to the correct volume group using the following command:

    vgextend <vgname> /dev/<partition>

    For example:

    vgextend vg_transip /dev/vda3

     

    Step 12

    Then assign all free space in the volume group to the logical volume:

    lvextend -l +100%FREE <lvpath>

    For example:

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

    Tip: in many cases you can also grow the filesystem immediately by using:

    lvextend -l +100%FREE -r <lvpath>

    If you use that option, you can skip step 14.


     

    Step 13

    First check which filesystem is being used on the logical volume:

    lsblk --fs

    In the output, check which filesystem type belongs to the logical volume you have just expanded, for example ext4 or xfs.


     

    Step 14

    Now expand the filesystem.

    If you are using ext4, run:

    resize2fs <lvpath>

    For example:

    resize2fs /dev/mapper/vg_transip-lv_root

    If you are using XFS, run the command against the mount point, usually /:

    xfs_growfs /

    Running this command may take some time.


     

    Step 15

    Check whether the extra space is now available using:

    df -h

    In most cases, a reboot is not required. Only if the new partition is still not shown correctly after running partprobe may a reboot help.


    Need help?

    Receive personal support from our supporters

    Contact us