A comprehensive guide to managing and using LVM in Ubuntu

Shaya Hosseini

Logical Volume Management (LVM) is a helpful tool that makes managing disk storage space in Linux a lot more flexible. LVM lets you create, resize, and move volumes across multiple drives with ease.

Linux is an open-source operating system (OSS) that is used in many devices such as computers, servers, and embedded systems. Ubuntu, which is one of the most widely used Linux distributions, is a free OSS that supports LVM right out of the box. LVM allows users to create partitions that span multiple layers. These layers span multiple physical disks. Unlike traditional partitioning, LVM allows complex resizing, movement, and management of storage volumes with minimal disruption.

This guide explores the benefits, setup, and best practices for using LVM in Ubuntu.

LVM, Logical Volume Management, Ubuntu, Linux, Open-Source Operating System, OSS
Freepik / Freepik / “Abstract technology ssl illustration” / FreePik license

Understanding how LVM works

LVM is essentially a system that gives you more flexibility when managing your storage. Instead of working directly with physical partitions, LVM creates abstractions of layers. That means you can create and modify volumes without being limited to one physical disk. It separates your set up into three main layers: physical volumes, volume groups, and logical volumes. These components make disk management smoother by working together to resize, reallocate, or back up data.

Key benefits of LVM

  • Dynamic resizing: You can easily expand or shrink logical volumes without affecting existing data.
  • Efficient space utilization: LVM lets you pool multiple physical drives into a single volume group, so you’re not restricted to the size of one disk.
  • Snapshot support: You can take point-in-time copies of your volumes, which is perfect for backups or quick system restores.
  • Simplified disk management: LVM makes it easier to move, extend, remove volumes without needing to shut down your system.

Installing LVM tools in Ubuntu

To begin using LVM, you’ll want to make sure the required tools are installed. On most Ubuntu systems, LVM comes pre-installed, but you can check by running lvm version in your terminal. If it’s not there, just update your package list and install it using sudo apt update followed by sudo apt install lvm2. Once it’s set up, you’re ready to start building out your LVM storage setup.

Preparing disks for LVM

The LVM command is often times pre-installed in most Linux distributions. To ensure the LVM tools are installed use lmv version. If it is not installed, you can add it with the command, sudo apt-get/ sudo apt install lvm2

Begin by identifying which disk you want to use. You can list available disks with the lsblk command. After picking your disks, you need to convert them into physical volumes using the pvcreate command. For example, sudo pvcreate /dev/sdX will initialize the disk, making it ready for LVM use. Make sure you replace /dev/sdX with the correct device name.

Creating volume groups

Once you’ve set up your physical volumes, the next step is to create a volume group. This step pools your physical volumes together into one manageable unit. You can combine multiple physical volumes into a volume group with a command like sudo vgcreate my_vg /dev/sdX /dev/sdY. This volume group acts as the foundation for creating your logical volumes, and you can continue to add more physical volumes to it later if needed.

Making and mounting logical volumes

With your volume group in place, you can now create logical volumes. These are the actual partitions you’ll format and use to store data. To create one, you could use a command like sudo lvcreate -L 10G -n my_lv my_vg, which creates a 10GB logical volume named my_lv. To use this volume, format it with a file system using sudo mkfs.ext4 /dev/my_vg/my_lv. Then create a mount point with sudo mkdir /mnt/mydata. If you want this setup to persist across reboots, you’ll need to add an entry to your /etc/fstab file.

Adjusting logical volumes after setup

One of LVM’s biggest strengths is how easy it is to adjust your setup later on. To expand a volume, use sudo lvextend -L +5G /dev/my_vg/my_lv and then resize the file system with sudo resize2fs /dev/my_vg/my_lv. Shrinking volumes require more caution. First, unmount the volume with sudo umount /dev/my_vg/mg_lv, then resize the file system with sudo resize2fs / dev/my_vg/my_lv 8G, and finally reduce the volume using sudo lvreduce –L 8g/dev/my_vg/my_lv. When that’s done, remount the volume so you can continue using it.

Removing LVM volumes

If you ever need to remove a logical volume, start by unmounting so its no longer in use by the system. You can do this with the command sudo umount /dev/my_vg/my_lv. This guarantees that no files or provesses are actively using volume. Once the logical volume is unmounted, you can safely remove it by running sudo lvremove /dev/my_vg/my_lv. This can help free up space in your volume group so you can reallocate it elsewhere.

Backups using LVM snapshots

LVM also includes support for snapshots; which allows you to temporarily freeze the view of your data that can be backed up or restored later. To create a snapshot, use the command sudo lvcreate -L 5G -s -n my_snapshot /dev/my_vg/my_lv. Snapshots are especially helpful if you want to back up data while services are still running, without interrupting anything in the process.

Final thoughts on using LVM in Ubuntu

If you’re looking for a smart and efficient way to manage disk space on Ubuntu, LVM definitely provides an advanced and flexible method to scale storage, manage backups, and optimize your system without the difficulties of traditional partitions. Once you get used to the command-line setup, it becomes a reliable part of your workflow. Whether you’re working with servers or just want more control over your desktop storage, understanding LVM is a skill that pays off.

All rights reserved ©2016 - 2026 Achievable, Inc.

Discover more from Achievable Test Prep

Subscribe now to keep reading and get access to the full archive.

Continue reading