Dynamically Increase Storage Capacity with LVM (Without Rebooting)

Backup Your Data!

Prerequisites

LVM Terminology

Install LVM

apt update
apt upgrade
systemctl reboot
apt install lvm2

Build LVM Storage Pool and Create a Logical Volume

lvmdiskscan
pvcreate /dev/vdb /dev/vdc
vgcreate group1 /dev/vdb /dev/vdc
lvcreate --extents 100%VG --name volume1 group1

Create a Filesystem and Mount it

mkfs.ext4 /dev/group1/volume1
mkdir /mnt/volume1
mount /dev/group1/volume1 /mnt/volume1

How to Migrate Data to a Logical Volume and Automatically Mount it at Boot

cp -axv /var/* /mnt/volume1/
echo '/dev/group1/volume1 /var ext4 defaults 0 2' >> /etc/fstab
systemctl reboot

How to Inspect LVM Structures

How to Extend Volume Groups and Resize Logical Volumes

pvcreate /dev/vdd
vgextend group1 /dev/vdd
lvextend --verbose --extents +100%FREE --resizefs /dev/group1/volume1

How to Replace Multiple Small Cloud Disks with One that is Larger

pvcreate /dev/vde
vgextend group1 /dev/vde
pvmove --atomic /dev/vdb /dev/vde
vgreduce group1 /dev/vdb
pvs
pvremove /dev/vdb

How to Manage LVM Snapshots

lvcreate --snapshot group1/volume1 --size 5G --name snap1
mkdir /mnt/snapshot
mount /dev/group1/snap1 /mnt/snapshot/
umount /mnt/volume1
lvconvert --merge group1/snap1
Can't merge until origin volume is closed.
Merging of snapshot group1/snap1 will occur on next activation of group1/volume1.

How to Create a Striped Volume to Increase Read/Write Performance

umount /mnt/volume1
lvremove /dev/group1/volume1
lvcreate --stripes 3 --size 10G --name stripedvolume group1

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store