Extending LVM Volume on Ubuntu
If you’re running out of space on a volume, Ubuntu’s flexibility with LVM can be a real lifesaver. Below, I’ll guide you through the process to extend an LVM volume using the logical volume manager.
Prerequisites
First, this guide assumes that you have a system running Ubuntu with LVM already configured, and there’s free space available in your volume group. You can check for available space by running vgdisplay
which will show VG Size (total), and Free PE / Size.
Extending the Logical Volume
When you confirm that additional space is available, the next step is to extend the logical volume. Here’s how it’s done using two primary commands:
lvextend
Extending the Logical Volume: To increase the size of your logical volume, use the lvextend
command. This utility allows you to add space to your logical volume. Here’s what to type in your terminal:
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
In this command, -l +100%FREE
specifies that you want to use 100% of the remaining free space in the volume group for this volume. /dev/mapper/ubuntu--vg-ubuntu--lv
is the logical volume’s device path.
resize2fs
Resizing the Filesystem: After extending the logical volume, you need to resize the filesystem so it can use the new space. For most Linux distributions using ext4 file system, the resize2fs
command performs this operation:
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
This command resizes the filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv
to occupy all the space available in the logical volume.
Confirming the Change
To ensure your volume has been successfully resized, you can use the df -h
command to list the filesystem disk space usage. It should reflect the new size of your targeted volume.
Conclusion
Extending an LVM volume on Ubuntu is straightforward with these commands. It’s particularly beneficial for managing server spaces or when working in environments with dynamic data growth. This method avoids the need for data migration and minimizes system downtime, making it a robust solution for volume management.
Remember, always ensure you have backups before performing disk operations such as resizing, just to be safe against any data loss.