How to Extend Logical Volumes on Ubuntu Server

Running out of disk space and managing disk 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 method for managing your server disk space. Unfortunately, when using these volumes, not all disk space is used up and this might leave you wondering where all your disk space went. Let’s take a look at how to adjust or increase your LVM hard disk space on Ubuntu.

Key Advantages of Logical Volumes

Logical Volume Manager (LVM) is a command-line utility for managing logical volumes on Linux. If you intend to have several partitions on your server or PC then it is highly recommended that you use logical volumes for managing your disk space.

LVM is more advanced and efficient in comparison to traditional ways of managing disks using partitions. Here are some of the major benefits of logical volumes on Linux:

  • Efficient: Logical volumes provide you with a more efficient way to utilize disk space
  • No need to restart servers: With logical volumes, you can modify disk size without the need to restart a server as is the case with regular partitions.
  • Store data across volumes: You can easily store data across multiple volumes over the entire disk

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

Extending Logical Volume on Ubuntu During Installation

When you get to the storage configuration page during the Ubuntu Server installation, select the ubuntu-lv partition mounted at root (/), press Enter, and select the Edit option.

On the next configuration page, you’ll see the maximum possible space that your server can use compared to the one that it is currently assigned. In this case, the current disk space is 25GB and the maximum possible space that the server can use is 22.996GB, but it is only utilizing 11.496GB at the moment.

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

It’s preferable to set the logical volume space during installation but in case you’ve forgotten or simply want to adjust the space on a live server, LVM also gives you that option.

Extending Logical Volume on Ubuntu Server After Installation

Before you can extend your logical volume space, you need to be aware of how much space you have available and how much you’ve used up. Normally, you’d do that with the df command, but it will not display the correct size of the logical volumes.

Instead, use the vgdisplay (Volume Group Display) command, which displays comprehensive information on volume groups and logical volumes.

You’ll need administrative privileges to run the command.

sudo vgdisplay

There are three important parameters you must pay attention to:

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

The df command only displays the allocated space and not the entire possible space, and this can lead you to assume that you do not have much space left on your server when a lot of space is lying idle as part of the volume group.

To extend the logical volume, use the lvextend command. But first, get the mount point of the logical volume using the lvdisplay command:

sudo lvdisplay

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

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

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

100% means using up the entire space, so assign the required percentage according to your needs, e.g. 50%, 60%, etc.

For the changes to take effect you also need to resize the file system comprising 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 command again, you will see that your root drive has increased in size.

Setting Up LVM on an Ubuntu Server Is Easy

LVM is a great tool that allows you to easily manage your disk utilization and logical volumes without the hassle involved in traditional disk partitions. Plus, if your server is running critical services, you do not need to restart it after adjusting disk size.

You can also set up LVM on your Ubuntu desktop for easy management of disk space.

[quads id=2]
Read the full article here

Related Articles

Leave a Reply

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

Back to top button