DEV Community

John  Ajera
John Ajera

Posted on

Extending Root Partition to Use All Disk Space in Ubuntu

Introduction

If your Ubuntu system is not using all available disk space, you can expand the root partition using LVM (Logical Volume Manager). This guide will walk you through extending the root volume (/) to utilize the full disk space.

Steps

1. Check Current Disk Usage

Run the following command to see the current disk layout:

lsblk
Enter fullscreen mode Exit fullscreen mode

Example output:

NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sr0                        11:0    1    2K  0 rom
vda                       253:0    0   75G  0 disk
├─vda1                    253:1    0    1G  0 part /boot/efi
├─vda2                    253:2    0    2G  0 part /boot
└─vda3                    253:3    0  71.9G  0 part
  └─ubuntu--vg-ubuntu--lv 252:0    0   36G  0 lvm  /
Enter fullscreen mode Exit fullscreen mode

This shows that the logical volume is only using 36GB, while vda3 has 71.9GB available.

2. Extend the Logical Volume

First, check free space available in the volume group:

sudo vgdisplay
Enter fullscreen mode Exit fullscreen mode

If there is free space, extend the logical volume:

sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Enter fullscreen mode Exit fullscreen mode

3. Resize the Filesystem

Once the volume is extended, resize the filesystem based on its type:

If using ext4

sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
Enter fullscreen mode Exit fullscreen mode

If using XFS

sudo xfs_growfs /
Enter fullscreen mode Exit fullscreen mode

4. Verify Changes

Check the updated disk usage:

df -h
Enter fullscreen mode Exit fullscreen mode

You should now see the root partition (/) using all available space.

Conclusion

You have successfully extended the root partition to utilize all available disk space. This ensures your system has enough storage for applications and data. 🚀


Have questions? Drop a comment below!

Top comments (0)