• Help & contact
    • Spring Offers
      %

    In this article, we'll show you how to adjust the Logical Volume after increasing the size of your SSD in Ubuntu/Debian.

    On cloud servers, the Logical Volume Manager (LVM) is used to manage storage space. The Logical Volume Manager puts a logical layer between the file system and the partitions of the data storage used. This makes it possible to create a file system that spans multiple partitions and/or disks. In this way, the storage space of several partitions or disks can be combined. In addition, the Logical Volume Manager gives you the option to increase a logical volume on the fly.

    After you have increased the size of your cloud server's SSD, you must manually adjust the size of the Logical Volume.

    Please Note

    We recommend that you perform a backup before manually adjusting the logical volume.

    Requirements
    • You have restarted the server after enlarging the SSD.

    • You have logged in to the server as an administrator.

    Preparation

    • If you have the distribution Ubuntu 18.04, Ubuntu 20.04 or Ubuntu 22.04 installed on your server, the growpart program is already installed by default. If you have the distribution Debian 10 or Debian 11 installed on your server, you need to install the growpart program. If this program is not installed on your server, you can install it using the commands below. After entering the appropriate command, follow the instructions displayed.

      Debian 10 and Debian 11

      [root@localhost ~]# apt-get install cloud-utils

      Ubuntu 18.04, Ubuntu 20.04 and Ubuntu 22.04

      [root@localhost ~]# apt-get install cloud-guest-utils

    • To check the available space of the logical volume, enter the following command:

      [root@localhost ~]# df -h

      After entering the command, the following partitioning is displayed, for example:

      Filesystem             Size  Used Avail Use% Mounted on
      udev                   963M     0  963M   0% /dev
      tmpfs                  198M  772K  197M   1% /run
      /dev/mapper/vg00-lv01   77G  1.6G   72G   3% /
      tmpfs                  986M     0  986M   0% /dev/shm
      tmpfs                  5.0M     0  5.0M   0% /run/lock
      tmpfs                  986M     0  986M   0% /sys/fs/cgroup
      /dev/sda1              464M   60M  377M  14% /boot
      tmpfs                  197M     0  197M   0% /run/user/0

    • Note the logical volume that is to be expanded. This is mounted under /. In the above example, the logical volume is /dev/mapper/vg00-lv01.

    • To view the partitioning of the Logical Volume, type the command below.

      [root@localhost ~]# fdisk -l

      After entering the command, the file system structure is displayed:

      root@localhost:~# fdisk -l
      Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disklabel type: dos
      Disk identifier: 0xe68dc2ef

      Device     Boot  Start       End   Sectors  Size Id Type
      /dev/sda1  *      2048    999423    997376  487M 83 Linux
      /dev/sda2       999424 167772159 166772736 79.5G 8e Linux LVM

      Disk /dev/mapper/vg00-lv01: 77.6 GiB, 83336626176 bytes, 162766848 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes

      Disk /dev/mapper/vg00-lv00: 1.9 GiB, 2046820352 bytes, 3997696 sectors
      Units: sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes

      In this example the partition sda2 is to be adjusted manually.

    • To determine the file system, enter the following command:

      [root@localhost ~]# df -Th | grep "^/dev"

      In the following example, the logical volume /dev/mapper/vg00-lv01 uses the ext4 file system:

      root@localhost:~# df -Th | grep "^/dev"
      /dev/mapper/vg00-lv01 ext4       77G  2.5G   71G   4% /
      /dev/sda1             ext4      456M  147M  276M  35% /boot

    Increasing the Size of the Partition with growpart

    Use the following growpart command to grow the /dev/sda2 partition. Take note of the fact that there is a space between the device name and the partition number.

    [root@localhost ~]# growpart /dev/device-name

    Example:

    [root@localhost ~]# growpart /dev/sda 2

    Increasing the Logical Volume Manually

    • To display the detailed information about the physical volumes, enter the following command:

      [root@localhost ~]# pvdisplay

      After entering the command, the following information is displayed, for example:

      root@localhost:~# pvdisplay
        --- Physical volume ---
        PV Name               /dev/sda2
        VG Name               vg00
        PV Size               79.52 GiB / not usable 3.00 MiB
        Allocatable           yes (but full)
        PE Size               4.00 MiB
        Total PE              20357
        Free PE               0
        Allocated PE          20357
        PV UUID               NseCRU-3JHj-Hwcq-BNpX-coVV-jBSy-l0EKWu

    • To increase the physical volume, enter the following command:

      [root@localhost ~]# pvresize /dev/sda2

      After entering the command, the following information is displayed:

      [root@localhost ~]# pvresize /dev/sda2
        Physical volume "/dev/sda2" changed
        1 physical volume(s) resized or updated / 0 physical volume(s) not resized

    • To check the status of the logical volumes, type the following command:

      root@localhost:~# lvdisplay
        --- Logical volume ---
        LV Path                /dev/vg00/lv00
        LV Name                lv00
        VG Name                vg00
        LV UUID                2DoZKM-A912-o9z8-2R1U-HbII-gNRF-lIKM1m
        LV Write Access        read/write
        LV Creation host, time somehost, 2019-03-07 16:43:12 +0000
        LV Status              available
        # open                 2
        LV Size                <1.91 GiB
        Current LE             488
        Segments               1
        Allocation             inherit
        Read ahead sectors     auto
        - currently set to     256
        Block device           253:1

        --- Logical volume ---
        LV Path                /dev/vg00/lv01
        LV Name                lv01
        VG Name                vg00
        LV UUID                dB1lWB-1TBC-Sl6S-g09N-v2lk-kXOv-yFYuFf
        LV Write Access        read/write
        LV Creation host, time somehost, 2019-03-07 16:43:12 +0000
        LV Status              available
        # open                 1
        LV Size                77.61 GiB
        Current LE             19869
        Segments               1
        Allocation             inherit
        Read ahead sectors     auto
        - currently set to     256
        Block device           253:0

    • Note the path of the logical volume that you want to enlarge. In this example, the path is /dev/vg00/lv01.

    • To increase the size of the logical volume with the lvresize program, type the lvresize command in the following format:

      [root@localhost ~]# lvresize -l +100%FREE [PATH OF LOGICAL VOLUME]

      Example:

      [root@localhost ~]# lvresize -l+100%FREE /dev/vg00/lv01
        Size of logical volume vg00/lv01 changed from 77.61 GiB (19869 extents) to 97.61 GiB (24989 extents).
        Logical volume vg00/lv01 successfully resized.

    • Resize the file system to use the new space. To resize the file system to the new size using resize2fs, enter the resize2fs command in the following format:

      [root@localhost ~]# resize2fs [PATH OF LOGICAL VOLUME]

      Example:

      root@localhost:~# resize2fs /dev/vg00/lv01
      resize2fs 1.44.1 (24-Mar-2018)
      Filesystem at /dev/vg00/lv01 is mounted on /; on-line resizing required
      old_desc_blocks = 10, new_desc_blocks = 13
      The filesystem on /dev/vg00/lv01 is now 25588736 (4k) blocks long.

      If the partition uses file system xfs, enter the following command to resize it to the new size:

      [root@localhost ~]# xfs_growfs [PATH OF LOGICAL VOLUME]

      Example:

      [root@localhost ~]# xfs_growfs /dev/vg00/lv01

    • To check if the file system has been adjusted, enter the following command:

      [root@localhost ~]# df -h