How to Extend Logical Volumes on Ubuntu Server

Running out of disk space and managing hard drive partitions has long been a headache for IT engineers. Luckily, Linux tries to solve this problem by using logical volumes.


On Ubuntu Server, logical volumes are the default way to manage your server storage space. Unfortunately, not all of the disk space is used when using these volumes, and you may be wondering where all your disk space has gone. Let’s take a look at how to adjust or increase your LVM disk space on Ubuntu.


Main advantages of logical volumes

Logical Volume Manager (LVM) is a command line utility for managing logical volumes on Linux. If you intend to have multiple partitions on your server or PC, it is highly recommended to use logical volumes to manage your storage space.

LVM is more advanced and efficient compared to traditional methods of managing disks using partitions. Here are some of the key benefits of logical volumes on Linux:

  • Efficient: Logical volumes give you a more efficient way to use storage space
  • Servers do not need to be restarted: With logical volumes, you can resize disks without having to reboot a server, as is the case with normal partitions.
  • Store data across volumes: You can easily store data across multiple volumes on the entire disk

On Ubuntu Server, you can increase the logical volume either during installation or after installing the operating system. We’ll look at both options so you can decide which one suits you better. Unlike Ubuntu Desktop, Ubuntu Server comes with just a terminal by default.

Extending logical volume on Ubuntu during installation

When you get to the memory configuration page during the installation of Ubuntu Server, select the ubuntu-lv Partition mounted at root (/), Press Enterand select that To edit Possibility.

On the next configuration page you will see the maximum possible disk space your server can use compared to what it is currently allocated. In this case, the current disk space is 25 GB and the maximum possible disk space that the server can use is 22,996 GB, but it is currently only using 11,496 GB.

To use the entire disk, simply enter the maximum possible amount shown in brackets, or enter any custom disk size, then save your settings.

It is preferable to set the logical volume space during installation, but in case you forgot or just want to customize the space on a live server, LVM gives you this option too.

Extend logical volume on Ubuntu server after installation

Before you can expand the space of your logical volume, you need to know how much space you have available and how much you have used. Normally you would do this with the df command, but it doesn’t show the correct size of the logical volumes.

Use the instead vgad (Volume Group Display) command that displays comprehensive information about volume groups and logical volumes.

You need administrator rights to run the command.

sudo vgdisplay

There are three important parameters to look out for:

  1. VG size: This is the volume group size and shows the total disk size available. In this case it is 23 GB.
  2. Allok PE/Size: This shows the amount of disk space currently allocated to your server
  3. Free PE/Size: Displays the free storage space of the total possible storage space

That df The command only shows the allocated disk space and not the total possible disk space, and this can lead you to think that you are running low on disk space on your server if there is a lot of disk space unused as part of the volume group.

To extend the logical volume, use the expand Command. But first get the mount point of the logical volume with the lv display Command:

sudo lvdisplay

From the lvdisplay output you can see the disk is mounted on the path /dev/ubuntu-vg/ubuntu-lv.

Next, increase the logical volume space with the following command:

sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

100% means to use up all the space, so allocate the required percentage according to your needs, e.g. e.g. 50%, 60% etc.

For the changes to take effect, you must also resize the file system that makes up the logical volume. Get the file system path from the df-h Command; in this case it is /dev/mapper/ubuntu–vg-ubuntu–lv.

resize2fs /dev/mapper/ubuntu

Now if you run the df-h run it again, you will see that your root drive has grown.

Setting up LVM on an Ubuntu server is easy

LVM is a great tool that allows you to easily manage your disk usage and logical volumes without the hassle of traditional disk partitions. Also, if your server has critical services running, you don’t need to restart it after resizing the disk.

You can also set up LVM on your Ubuntu desktop to easily manage disk space.

Leave a Reply

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