In this tutorial, I will explain how to extend a disk’s partition and then the LVM disk.
To understand what we are going to do in this tutorial, I have a virtual machine with Ubuntu Server 20.04 installed on an LVM disk, following the addition of data, I must increase the storage capacity, for that I am going to expand the disk on the hypervisor first and then increase the space at the Ubuntu server level.
In order not to be lost, you should know that LVM disks are virtual disks that allow great flexibility.
To start, here is the output of the df -h command:
We can deduce that the current disk is 400GB and we can see the lvm disk is 389GB.
On Hyper-V, here is the virtual disk of the computer.
To extend the disk, I pass this one to 500GB:
After restarting the virtual machine, if we use the df -h command again, we still have the same result, the 100GB of space added are not visible, it’s not magic…
Enter the command below to display all disks and partitions:
On the capture, we can see that the sda disk is 500GB, on the other hand partition 3 and the LVM disk are at 396GB
This information can also be obtained with the command
sudo fdisk -l.
We can see a GPT MBR error which will be resolved, once the manipulation is finished, don’t panic…
Now, we are going to get serious in order to be able to use the additional 100GB, here is what we are going to do:
- Extend sda 3 partition to use all available space
- Extend the PV (Physical Volume) where the LVM disk is located
- Extend LV Disk
- Extend filesystem in LV to make disk space available
The paths used should be appropriate for your environment.
We start by extending the partition with the growpart utility:
sudo growpart /dev/sda 3
If we look at the partitions with the sudo lsblk command, we can see that the sda3 partition has been increased by 100 GB.
Extend the PV volume with the pvresize command:
sudo pvresize /dev/sda3
Now, we extend the LV over all the available space:
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Short break, if you use the sudo lsblk and df -h commands one after the other, we can see that the partition is 100Gb more as well as the LV, on the other hand the LV partition is still 396Gb.
All that remains is to resize the file system to make the additional 100GB usable.
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
If you use owe the df -h command, we have an additional 100 GB available.
Now you know how to extend disk and partition on Ubuntu server.
It is possible to do the same thing on the Desktop version of Ubuntu, you just need to install the cloud-utils package first. (
sudo apt install cloud-utils) which contains the growpart utility.
If you are not using LVM, the procedure is similar, just skip the pvresize command and use the resize2fs command on the partition that has been expanded.