Re-claiming unused disk space

vishvam@ubuntu:~$ lsblk
sda                         8:0    0   30G  0 disk 
├─sda1                      8:1    0    1M  0 part 
├─sda2                      8:2    0  1.8G  0 part /boot
└─sda3                      8:3    0 23.2G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0 23.2G  0 lvm  /

Here we can see that the disk size is 30G but we only have usable space of 23.2G inside the data partition where the remaining 5G of space is still allocated on the disk and we will now allocate the space in the data partition using the following steps :


Step -1 : Resizing partition

we can extend the partition sda3 using the parted utility with the following commands :

sudo parted /dev/sda

Here we can type help to get the manual and we can use the resize command to resize the partition

resizepart NUMBER END

In our case the partition numner is 3 so the command will look like :

resizepart 3 100%

This will resize the partition to its 100% capacity & the updated output should look like :

vishvam@ubuntu:~$ lsblk
sda                         8:0    0   30G  0 disk 
└─sda3                      8:3    0 28.2G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0 23.2G  0 lvm  /

The new size of sda3 is updated to 28.2G and the unallocated space is now allocated to sda3, Now we will have to update the lvm to claim the space.

sudo partprobe /dev/sda

Step -2 Extending LVM

First we will see the lvm name using the following command :

sudo lvdisplay

This will display the output like :

We will note down the LV_NAME and pass the command like :

sudo lvextend -l +100%FREE <LV_NAME>
#sudo lvextend -L +100%FREE /dev/ubuntu-vg/ubuntu-lv

Now we have successfully reclaimed to extended space on the ubuntu system.


Last updated