Linux: logical volume management

July 13, 2022

Lang: cs en de es

The Linux OS is a powerful tool. You can manage partitions on the fly, even enlarge, add and move them between physical disks. All on the fly and without downtime. Logical Volume Management technology is designed to do all this and more. I'll describe what LVM can do and how to use this technology in this article.

In a previous article I described how to Linux software RAID. LVM can do RAID too, plus it can do a lot of other things and is suitable for servers, where storage space requirements may change and you may need to make changes to disks while the system is running without service interruption.

For example, you will encounter LVM if you are using proxmox. And a lot of automatic installers will use LVM for disk management by default. So it may be useful to at least know LVM so you won't be surprised when you come across this technology.

What is LVM

Features

  • change (increase) the size of the block device (disk) at runtime
  • moving a block device to another physical disk
  • RAID1
  • merging multiple disks into one (equivalent to RAID0)
  • creating block devices for Virtual Private Servers (VPS)
  • snapshots
  • atd

Disadvantages?

With options come complexities, making LVM more difficult to understand and navigate. The same is true with LVM, so you need to study and try the technology.

There is more work involved with LVM and unless you are planning major partition changes and disk purchases, it is unnecessary. Where it raises the possibility of needing to increase disk storage with minimal downtime, LVM is the ideal solution, along with a filesystem that can be expanded on the fly.

Installation

In a Linux distribution, Debian, the following command will install LVM support:

apt install lvm2

LVM usage

Some basic commands:

  • pvs view Physical Volumes
  • vgs view Volume Groups
  • lvs display Logical Volumes

Creating LVM

You can create an LVM on a disk or better a partition as follows:

  1. Creating Physical Volumes:
    pvcreate /dev/sdc1
  2. Create Volume Groups:
    vgcreate home_vg /dev/sdc1
  3. Creating Logical Volumes:
    lvcreate -l 100%FREE -n home home_vg

Format the block device and modify filesystem parameters:

mkfs.ext4 -L server-backup /dev/mapper/home_vg-home
tune2fs -c 0 -i 0 /dev/mapper/home_vg-home

Changes to LVM

After increasing the dick in the VPS, it is necessary to increase the LVM PV (physical volumes), so that you use all the free capacity:

pvresize /dev/sda3
Creating LVM physical volumes on a new disk and adding them to LVM VG (volume group)
pvcreate /dev/sde1
vgextend home_vg /dev/sde1
Increasing LVM LV (logical volume):
lvextend /dev/home_vg/home /dev/sde1
#STEED:
lvextend -l +100%FREE /dev/home_vg/home
Extending the EXT file system over the entire partition:
resize2fs /dev/home_vg/home
The following command branches the logical volume /dev/myvg/homevol to 12GB
lvextend -L12G /dev/myvg/homevol
The following command adds 1GB to the existing logical volume size /dev/myvg/homevol.
lvextend -L+1G /dev/myvg/homevol

Enlarge the XFS filesystem:

xfs_growfs /

Enlarge partition #1 on the xvda disk to use empty space. Typically if in VMWare or Proxmox you enlarge the disk that the VPS is using. (Not directly related to LVM) You need to enlarge a given partition and then the EXT filesystem also needs to be enlarged.

growpart /dev/xvda 1
resize2fs /dev/xvda1
The growpart program is included in the cloud-utils package. If growpart reports this error:
unexpected output in sfdisk --version [sfdisk from util-linux 2.36.1]
It could also be that you are not using the English language on your system, and so the command in question does not understand the sfdisk program it is using. The solution is to set your environment variable to English with the following command:
export LANG=en_US.UTF-8

Deleting the LVM metadata on a given partition will also delete the RAID information or other signature of how the partition is used.

wipefs -a /dev/sdb3

Video tutorial

For a detailed and visual demonstration of how to use LVM, see this video tutorial on how to start using LVM:

More about LVM

Debian.org LVM
LVM
LVM howto

Articles on a similar topic

VMware vs Proxmox: performance comparison
GitLab CI/CD: test automation and application deployment
Migrating VPS from VMware to Proxmox
VMware licensing change
Running Microsoft SQL Server on Linux
Backup: the Proxmox Backup Server
Linux as a router and firewall
How to upload a docker image to the Docker Registry
Linux Software RAID
Running a web application behind a proxy
Mailbox migration
Docker multistage build
Backing up your data by turning on your computer
Podman
Importing Windows into Proxmox virtualization
Docker and PHP mail
Proxmox virtualization
Docker and Cron
Lenovo ThinkPad X1 Carbon: LTE modem EM7544 commissioning
Yocto Project: Build custom operating system for embedded devices
Preparing a Linux server to run a web application in Python
How to address poor file share performance in Docker
How to get started using Docker correctly
Installing Linux on a dedicated HPE ProLiant DL320e server
How to stress test a web application
Why use the JFS filesystem
How to boot from a 4TB drive with GTP using UEFI
Btrfs file system
Raspberry PI
WINE - running Windous programs under Linux
GNU/Linux operating system

Newsletter

If you are interested in receiving occasional news by email.
You can register by filling in your email news subscription.


+