LVM Cheatsheet v1.4
LVM Cheatsheet v1.4
4
The following is a command summary for the basic operation of Linux LVM including Physical
Disks (PVs), Volume Groups (VGs) and Logical Volumes (LVs). It is assumed that the reader is
familiar with the concepts of such a system.
Command Cheatsheet
Physical Volume Tools
vgcreate <newvg> /dev/sdc /dev/sdd - Create new volume group from SDC & SDD
vgexport <vgname> - Prepare VG for move to another machine.
vgsplit {Too many options to list} - Split a VG in two, by moving one or more PV
- to a new VG (Study docs before proceeding!)
lvcreate −i2 −I4 −l100 −ntestlv testvg - Create a LV 100 extents in size with
- 2 stripes and stripe size 4 KB
LV’s can be reverred to by their /dev/ path name, as well as by name. (Eg. /dev/mapper/<lvname>)
To create an LV that uses the entire VG, use simething like vgdisplay testvg | grep "Total PE",
then take the “Total PE” value and proceed to populate a command like the following:-
lvcreate −l <Total PE> testvg −n mylv.
For Snapshot - Size is the max amount of change which we reserve space for.
lvcreate −L592M −s −n dbbackup databases
Always “lvremove” after use to recover space.
Create Volume
Using TRIM via LVM on striped or mirrored LV’s does work, but at the time of writing, it does not
work if LVM is nested on top of MDRAID, so please bear this in mind when reading the example
below..
# pvcreate --metadatasize 250k /dev/sdg2
(you'll need to adjust --extents according to the size of your device, this one is for 90GB)
# lvcreate -i2 -I128 -n lvssd vgssd --extents 42806
Set elevator to 'deadline', and increase queue size. I put this into my /etc/rc.local:-
echo deadline >/sys/block/sdg/queue/scheduler
echo deadline >/sys/block/sdh/queue/scheduler
find /sys/devices -name nr_requests -exec sh -c 'echo 4096 > {}' \;
Add noatime and discard (required for TRIM support) mount options to /etc/fstab