2018-08-07 17:51:07 +03:00
[[chapter_lvm]]
2016-09-08 17:46:10 +03:00
Logical Volume Manager (LVM)
----------------------------
2016-10-08 18:22:48 +03:00
ifdef::wiki[]
:pve-toplevel:
endif::wiki[]
2016-09-08 17:46:10 +03:00
Most people install {pve} directly on a local disk. The {pve}
2016-09-12 13:18:27 +03:00
installation CD offers several options for local disk management, and
2022-11-18 14:09:45 +03:00
the current default setup uses LVM. The installer lets you select a
2016-09-12 13:18:27 +03:00
single disk for such setup, and uses that disk as physical volume for
2016-09-27 11:58:50 +03:00
the **V**olume **G**roup (VG) `pve`. The following output is from a
2016-09-12 13:18:27 +03:00
test installation using a small 8GB disk:
2016-09-08 17:46:10 +03:00
2016-09-12 13:18:27 +03:00
----
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 pve lvm2 a-- 7.87g 876.00m
# vgs
VG #PV #LV #SN Attr VSize VFree
pve 1 3 0 wz--n- 7.87g 876.00m
----
The installer allocates three **L**ogical **V**olumes (LV) inside this
VG:
----
# lvs
LV VG Attr LSize Pool Origin Data% Meta%
data pve twi-a-tz-- 4.38g 0.00 0.63
root pve -wi-ao---- 1.75g
swap pve -wi-ao---- 896.00m
----
2021-07-19 14:41:12 +03:00
root:: Formatted as `ext4`, and contains the operating system.
2016-09-12 13:18:27 +03:00
swap:: Swap partition
data:: This volume uses LVM-thin, and is used to store VM
images. LVM-thin is preferable for this task, because it offers
efficient support for snapshots and clones.
2016-09-08 17:46:10 +03:00
2016-12-01 12:36:28 +03:00
For {pve} versions up to 4.1, the installer creates a standard logical
volume called ``data'', which is mounted at `/var/lib/vz`.
Starting from version 4.2, the logical volume ``data'' is a LVM-thin pool,
used to store block based guest images, and `/var/lib/vz` is simply a
2016-10-12 15:23:33 +03:00
directory on the root file system.
2016-09-13 13:11:28 +03:00
Hardware
~~~~~~~~
We highly recommend to use a hardware RAID controller (with BBU) for
such setups. This increases performance, provides redundancy, and make
disk replacements easier (hot-pluggable).
LVM itself does not need any special hardware, and memory requirements
are very low.
Bootloader
~~~~~~~~~~
We install two boot loaders by default. The first partition contains
the standard GRUB boot loader. The second partition is an **E**FI **S**ystem
2023-07-28 16:21:12 +03:00
**P**artition (ESP), which makes it possible to boot on EFI systems and to
apply xref:sysadmin_firmware_persistent[persistent firmware updates] from the
user space.
2016-10-12 15:23:33 +03:00
Creating a Volume Group
~~~~~~~~~~~~~~~~~~~~~~~
Let's assume we have an empty disk `/dev/sdb`, onto which we want to
2016-12-01 12:36:28 +03:00
create a volume group named ``vmdata''.
2016-12-29 09:44:46 +03:00
CAUTION: Please note that the following commands will destroy all
2016-12-01 12:36:28 +03:00
existing data on `/dev/sdb`.
2016-10-12 15:23:33 +03:00
First create a partition.
# sgdisk -N 1 /dev/sdb
2016-12-01 12:36:28 +03:00
Create a **P**hysical **V**olume (PV) without confirmation and 250K
2016-10-12 15:23:33 +03:00
metadatasize.
# pvcreate --metadatasize 250k -y -ff /dev/sdb1
2016-12-01 12:36:28 +03:00
Create a volume group named ``vmdata'' on `/dev/sdb1`
2016-10-12 15:23:33 +03:00
# vgcreate vmdata /dev/sdb1
Creating an extra LV for `/var/lib/vz`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This can be easily done by creating a new thin LV.
# lvcreate -n <Name> -V <Size[M,G,T]> <VG>/<LVThin_pool>
A real world example:
# lvcreate -n vz -V 10G pve/data
Now a filesystem must be created on the LV.
2017-03-23 13:57:32 +03:00
# mkfs.ext4 /dev/pve/vz
2016-10-12 15:23:33 +03:00
At last this has to be mounted.
2016-12-01 12:36:28 +03:00
WARNING: be sure that `/var/lib/vz` is empty. On a default
installation it's not.
2016-10-12 15:23:33 +03:00
To make it always accessible add the following line in `/etc/fstab`.
# echo '/dev/pve/vz /var/lib/vz ext4 defaults 0 2' >> /etc/fstab
Resizing the thin pool
~~~~~~~~~~~~~~~~~~~~~~
2022-11-18 14:09:45 +03:00
Resize the LV and the metadata pool with the following command:
2016-10-12 15:23:33 +03:00
# lvresize --size +<size[\M,G,T]> --poolmetadatasize +<size[\M,G]> <VG>/<LVThin_pool>
2016-12-01 12:36:28 +03:00
NOTE: When extending the data pool, the metadata pool must also be
extended.
2016-10-12 15:23:33 +03:00
2016-12-01 12:36:28 +03:00
Create a LVM-thin pool
2016-10-12 15:23:33 +03:00
~~~~~~~~~~~~~~~~~~~~~~
A thin pool has to be created on top of a volume group.
2016-12-01 12:36:28 +03:00
How to create a volume group see Section LVM.
2016-10-12 15:23:33 +03:00
# lvcreate -L 80G -T -n vmstore vmdata