Skip to main content

Managing Disk Space with LVM: A Comprehensive Guide

·
linux lvm disk
Hugo
Author
Hugo
DevOps Engineer in London
Table of Contents

Working with LVM (Logical Volume Management) can simplify the process of managing disk space. This post will guide you through enlarging a disk in LVM, migrating a non-LVM file system to LVM, and migrating the root file system to LVM.

Enlarging a Disk in LVM
#

Refer to this article for more information: Manage and Create LVM Partition Using vgcreate, lvcreate, and lvextend.

To enlarge an existing LVM:

  1. Check if the new disk is detected using lsblk. If not, scan it with:
echo "- - -" > /sys/class/scsi_host/host<N=1,2,3,4...>/scan
  1. Create a physical volume, extend the volume group, and extend the logical volume:
pvcreate <new_disk>
vgextend <vg> <new_disk>
lvextend -l +100%FREE -r <lvm>
  1. Resize the file system:

  2. You should able to see the resize disk on

df -h

Migrating Non-LVM File System to LVM
#

For example, if you want to move /var to LVM:

  1. Create the LVM.
  2. Mount it to a temporary location (e.g., /tmp/lvm).
  3. Copy data from /var to the LVM:
rsync -avz /var/ /tmp/lvm/
  1. Unmount it.
  2. Update /etc/fstab with the new LVM.
    • Use UUID to reference the file system.
    • Find the UUID with blkid.

Refer to fstab documentation for more details.

Migrating Root File System to LVM
#

Refer to Converting an Existing Root Filesystem to LVM Partition.

The steps are similar to migrating a non-LVM file system:

  1. Repeat the steps of migrating Non-LVM File System
  2. Perform additional steps:
    • chroot to update initrd.
    • Edit grub.conf with the new root.
  3. Restart the system.

Following these steps will help you manage disk space using LVM, whether you need to enlarge a disk, migrate a non-LVM file system to LVM, or migrate the root file system to LVM.