LVM
Introduction
LVM is a Logical Volume Manager. It helps creating storage spaces not restricted by physical storage drives. This flexibility is achieved by a mapping between logical storage units and physical storage units.
File systems are setup on Logical Volumes (LV). Space from a Volume Group (VG) is attributed to a Logical Volume (LV), while Logical Volumes (LV) combine Physical Volumes (PV) together.
LVM can be setup either:
- Directly on bare storage drives or,
- on top of a RAID array.
Prepare storage
Using bare drives
Using bare drives provides no data redundancy. The main advantage of this solution is that hard-drives of different sizes can be combined. Using this setup, hard-drives of increased capacity can be added as needed to an existing LVM to increase its storage size.
In this example, two hard-drives identified as /dev/sda
and /dev/sdb
are used:
Create a partition using 100% of space on each hard-drive.
parted -s /dev/sda mklabel gpt mkpart primary 1MiB 100% set 1 lvm on print
parted -s /dev/sdb mklabel gpt mkpart primary 1MiB 100% set 1 lvm on print
Using RAID
In contrast to bare drives, RAID provides data redundancy. To setup a RAID array, please follow these instructions.
In this example, two hard-drives identified as /dev/sda
and /dev/sdb
are represented (please note that some RAID levels, like RAID5, require at least 3 drives):
Create new LVM
-
Create the Volume Group VolGroup1 using the two partitions just created. The Physical Volumes are created automatically for each partition using 100% of the space.
-
Create Logical Volume (LV) VolData using space in VolGroup1.
lvcreate -l 100%FREE VolGroup1 -n VolData
This will use 100% of the available space in VolGroup1. To use a limited amount of space, replace
-l 100%FREE
by-L 500G
or-L 10T
. For example:lvcreate -L 500G VolGroup1 -n VolData
TipMultiple Logical Volumes (LV) can be created until VolGroup1 is full. -
Format the volume VolData (here using XFS).
-
Edit
/etc/fstab
- The configuration file
/etc/fstab
contains the necessary information to automate the process of mounting partitions. Learn more about this file on the Arch Wiki. Add an entry in/etc/fstab
the LVM nameddata
:LABEL=data /data xfs defaults 0 2
This standard entry can be added for any other LVM volume created. The 1st (LABEL) and 2nd (mount point) columns need to be adapted to the volume to be mounted.
- The configuration file
Modify LVM
Add physical space
Using bare drives
In case a new hard-drive (or partition) needs to be added to an existing Volume Group (VG), VG can be extended.
- Partition the new hard-drive, here
/dev/sdc
, to create/dev/sdc1
using parted as seen above. - Add the new space to VolGroup1 (the Physical Volume is created automatically).
vgextend VolGroup1 /dev/sdc1
- Eventually, extend the Logical Volume (LV) VolData to use this added space (see below).
Extend volume size
If space is available in a Volume Group (VG), Logical Volume (LV) can be extended and associated filesystem as well. To add space to the Logical Volume VolData:
lvresize -l +100%FREE --resizefs VolGroup1/VolData
To use a limited amount of space, replace -l 100%FREE
by -L +500G
or -L +10T
. For example:
lvresize -L +500G --resizefs VolGroup1/VolData
The option --resizefs
will automatically resize the filesystem on VolData.