Logical Volume Management (LVM) is a highly flexible, advanced partitioning scheme available on Linux. It enables users to create, resize, and move partitions easily without the need to shut down the system.
This feature is especially useful in a dynamic virtual private server (VPS) environment where storage requirements can change rapidly. In this guide, we will dive deep into the world of LVM management on an Ubuntu VPS, offering practical examples and commands to help you master the art of managing your disk space efficiently.
Before we embark on the practical aspects, let’s lay down the fundamentals of LVM. At its core, LVM involves three key components:
The beauty of LVM lies in its ability to abstract the storage into flexible logical volumes, making it easier to manage disk space.
First, ensure your system is up to date and install the LVM2 package:
sudo apt update && sudo apt install lvm2
Assuming you have a new disk /dev/sdb
, you would initialize it as a physical volume:
sudo pvcreate /dev/sdb
To verify, use:
sudo pvdisplay
Now, let’s create a volume group named vg01
using /dev/sdb
:
sudo vgcreate vg01 /dev/sdb
Check the VG status with:
sudo vgdisplay
With the volume group ready, we can create logical volumes. For example, to create a 10GB logical volume named lv01
in vg01
:
sudo lvcreate -L 10G -n lv01 vg01
Verify the LV creation:
sudo lvdisplay
To extend lv01
by another 5GB, use:
sudo lvextend -L +5G /dev/vg01/lv01
Then, resize the filesystem:
sudo resize2fs /dev/vg01/lv01
Reducing an LV is a bit more complex as it requires filesystem shrinking first. Always backup data before reducing.
Shrink the filesystem (for ext4):
sudo resize2fs /dev/vg01/lv01 8G
Then, reduce the LV size:
sudo lvreduce -L 8G /dev/vg01/lv01
To remove an LV named lv01
:
sudo lvremove /dev/vg01/lv01
To remove a VG named vg01
:
sudo vgremove vg01
Finally, to remove a PV:
sudo pvremove /dev/sdb
LVM snapshots allow you to create a point-in-time copy of a logical volume. This is invaluable for backups or experiments.
To create a snapshot of lv01
named lv01-snap
with 2GB space:
sudo lvcreate -L 2G -s -n lv01-snap /dev/vg01/lv01
To revert to a snapshot:
sudo lvconvert --merge /dev/vg01/lv01-snap
Mastering LVM on Ubuntu VPS is a valuable skill for any system administrator or power user. With the flexibility and power that LVM offers, you can manage disk space more efficiently, ensuring that your server can adapt to changing storage needs without downtime.
The examples and commands provided in this guide serve as a foundation for exploring the vast capabilities of LVM. Whether it’s creating, extending, reducing, or snapshotting logical volumes, the control is now in your hands. Happy managing!
The benefits of SEO are obvious, so let’s look at 4 simplest SEO steps for WordPress that you can take… Read More
Large agencies looking to migrate servers from one hosting provider to another may be facing a number of issues. These… Read More
This article will provide a guide demonstrating how to backup WordPress Site to Microsoft OneDrive. This feature is available for… Read More
We are pleased to announce Debian 12 (Bookworm) is now available for VPS. This template is available for immediate deployment… Read More
This article provides a guide for how to install MySQL 8 on VPS server. Database Management Systems (DBMSs) are applications designed… Read More
This article provides a step-by-step guide to create WordPress Staging Site for testing and development. What is a WordPress Staging… Read More