How to Use Logical Volume Management (LVM)

LVM - Logical Volume Manager - tools used to create and manage logical volumes.

When you attach a new hard drive to your Linux system, you'll likely need to create new particions and volumes. To do that, we're going to work with LVM; a storage layer that came about to solve many of the problems of traditional partitioning which is too rigid by comparison. Being able to quickly create, increase or decrease, and copy a volume is not something available to us with the old particioning method.

Using LVM, we can on-the-fly change volume sizes, merge multiple physical or virtual disks into single usable volume, and create snapshot copies. Sounds real nice. Even better though, is that LVM is pretty much absolutely stable, having gone through multiple iterations coming nearly to the point of perfection. Even though it adds another layer of abstraction, it simplifies common operations without compromising your disk systems' performance.

I would say that using LVM is an easy recommendation to use in modern Linux installations and for any new disk you add to them.

Some might recommend using ZFS, which is a hybrid file system and volume manager.  I prefer applying UnixWay, that a program needs to do one thing and do it well and, to me, LVM fits the criteria. On top of that LVM is compatible with any file system you want - ext3, ext4, xfs, raiserfs - within its volumes, which is something ZFS can't do.

Ok, well... maybe it's not completely perfect. The deficit in write performance after making a snapshot leaves much to be desired, so I advise to only create one temporarily - to make a directory backup for instance - and delete it immediately after. 

Let's go over some basic terminology first, and then look at some examples of what working with LVM is like.

Physical Volume

This is the basis of LVM. A physical volume is any drive space for use by the system. A hard drive, partition, virtual machine, or raid array are all considered physical volumes and can be used with LVM as long as a conflicting file system isn't set up on them.. If a drive already has a traditionally partitioned volume, a LVM Physical Volumes can be allocated next to it.

Logical Volume

Logical volumes is what this whole system is about. Logical volumes can be created by allowing you to allocate any amount of storage space you have to discrete volumes to serve the functions you want. I often set up 3 logical volumes on my servers: //var, and /back. If you have a LAMP server, and you don't know ahead of time whether your files or your database will take up more space, you can assign volumes /var/www and /var/lib/myseql. 

Volume Group

Improves the organization of volumes, by grouping together physical and logical volumes. Pretty simple.


So, how can you tell that a system is using LVM? Even if your system has been setup on LVM, there's really not much the system can tell you about itself without installing a lvm2 package. That's easy enough to do:

yum install lvm2

Now you can check your system's physical volumes:


Or logical volumes:


And, of course, volume groups:



Let's play around with LVM a bit, shall we. For our first trick, let's take an empty, unpartitioned disk and create a physical volume, a volume group, and a logical volume. 

In this example, "vdb" is a 400gb drive. We'll designate it in its entirety as a physical volume:

pvcreate /dev/vdb

Physical volume "/dev/vdb" successfully created

You can use the command "pvcreate --help" to look through other useful parameters, but generally you won't need them. Just like before, you can use "pvdisplay."

Now let's create a volume group over this physical volume. You can name volume groups, and generally you want to use a name that's functional. I will use a backup group and will name it as such

vgcreate backupVG /dev/vdb

Similarly to "pvcreate" you can use "vgcreate --help" to your advantage.

Finally, let's make a logical volume. When making it, you need to specify the size of the volume, its name and the volume group it will belong to.

lvcreate -1 100% free -n backupLV backupVG

Notice how the size is labeled as a % of the total space in the group. We could specify the space in bytes but... well, let's see what happens:

lvcreate -L400G -n backupLV backupVG

Volume group "backupVG" has insufficient free space (102399 extents): 102400 required.

Oh, well of course, not only is our original drive probably not exactly 400 gigs, but LVM itself takes up some small amount of space itself using percent will allocate the correct amount automatically.

Let's allocate an amount much smaller than the maximum.. let's say just 100 gigs:

lvreduce -L100G /dev/backupVG/backupLV

  WARNING: Reducing active logical volume to 100,00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce backupLV? [y/n]:

Let's just hit "y" for our exercise.

Do you really want to reduce backupLV? [y/n]: y
  Size of logical volume backupVG/backupLV changed from 400,00 GiB (102399 extents) to 100,00 GiB (25600 extents).

Nice. We can add another volume next to it at any point:

lvcreate -L100G -n YetAnotherLV /dev/backupVG

Logical volume "YetAnotherLV" created

Great! And just remember you can delete these volumes using "lvremove."

When you manipulate logical volumes that contain actual data, you obviously need to make sure you have a backup saved somewhere else. To do this, you can actually create a volume snapshot and send it to another server through SSH.

Create a logical volume on your remote server of a equal or greater value:

lvcreate -L100G –n VolumeForDump /dev/volumegroup00

Now we make a snapshot on the original server using the "-s" flag:

lvcreate -L100G -s -n SnapshotCopy /dev/backupVG/backupLV

  Logical volume "SnapshotCopy" created

Now just start the dump over SSH:

dd if=/dev/backupVG/SnapshotCopy | ssh backup@ -p 22 
dd of=/dev/volumegroup00/VolumeForDump

Obviously, the time it'll take depends on the size of the volume.

This about covers the basics of LVM and how to use it. Make sure you test all these examples on empty servers first, before messing with any sensitive data.

In our next article, we'll get into some advanced LVM territory. Keep up with us on Twitter and Facebook so you know when we drop that one.

Until next time!


This article was originally published June 2016

July 20 2020

Add or review comments

Please leave your comment

Existing comments

Comments 70

yourstabs viagra <a href="">buy generic viagra by phone in australia</a> viagra onine [url=]viagra 100 mg generic[/url] ’
cocaine and viagra <a href="">generic viagra canadian pharmacy</a> cheep viagra [url=]viagra 300mg[/url] ’
canadian pharmacy <a href="">medicine online order</a> canadia online pharmacy
drugs online <a href=" ">Viagra Super Active</a> pharmacy northwest canada
prescription without a doctor's prescription <a href=" ">online viagra</a> best canadian online pharmacies
the canadian pharmacy <a href=" ">cialis super active</a> antibiotics
viagra for sale philippines <a href=" ">gold viagra x1</a> where can i find generic viagra
viagra dosage amounts <a href=" ">how can i buy viagra online</a> viagra canada fast shipping
buy viagra brisbane <a href=" ">viagra online with american express</a> sildenafil citrate (generic viagra)
buy cialis at walmart <a href=" ">cialis no consultation</a> buy cialis online free shipping
fast money loans bad credit <a href=" ">chase bank hard money loan</a> tennessee quick cash flex loans
cialis compresse 5 mg prezzo <a href=" ">metformina e cialis</a> preço caixa cialis
payday loans in temple tx <a href=" ">7 year old payday loan</a> payday loans bham
cialis retinopathy <a href=" ">cialis no ejaculation</a> mecanismo de accion cialis
viagra for sale fast shipping <a href=" "> </a> online pharmacy viagra 100mg
viagra no perscription <a href=" "> </a> viagra product
online pharmacy viagra <a href=" ">buy viagra online without a prescription with overnight delivery </a> whats better cialis or viagra
buying viagra online legal <a href=" ">india pharmacy viagra</a> indian viagra
viagra generic cost <a href=" ">buy viagra in mexico </a> generic viagra price
order generic cialis <a href=" ">cialis 20 mg tablets </a> cialis canada generic
[url=]help writing thesis[/url] writing a phd thesis <a href=" ">write a thesis</a> example thesis
[url=]buy essays cheap[/url] buy essay cheap <a href=" ">cheap essay buy</a> your essay writer
[url=]essay on service[/url] writing essays services <a href=" ">reviews for essay writing services</a> essay services reviews
[url=]how to get cialis prescription online[/url] [url=]cialis for bph[/url] [url=]how much viagra should i take the first time?[/url] [url=]free sample of viagra[/url] [url=]cvs cialis over the counter[/url]
[url=]viagra melanoma[/url] [url=]viagra boys band[/url] [url=]non prescription cialis[/url] [url=]cialis generico[/url] [url=]buy cialis online[/url]
[url=]dissertation paper[/url] best dissertation service <a href=" ">college dissertation</a> help with dissertation writing
[url=]education thesis[/url] buy a thesis <a href=" ">best thesis writing</a> writing a phd thesis
[url=]how do i write a thesis[/url] thesis writing assistance <a href=" ">editing thesis</a> what is thesis writing
cialis paypal pay with [url= ]order generic cialis by phone[/url] buy cialis with american express
tadalafil Mobic
levitra manufacturer levitra dose
tadalafil generic vs brand tadalafil tab 5mg
viagra contraindications buying viagra online legally
Azulfidine Accupril
cialis and douextine cialis (generic)
Tadapox canadian pharmaceuticals
when to take levitra for best results levitra doage
muscle relaxant walmart pharmacy online
cialis cheap cialis black wirkung
cialis no perscrption cialis with dapoxetine or viagra with dapoxetine better
cialis without a perscription buy 36 hour cialis without prescription
side effects of viagra viagra no prescription
where to buy viagra in paris viagra remboursГ©
ED Trial Pack [url= ]Biltricide[/url] Brand Viagra
brand cialis 20 cialis supplier uk
cialis dosage [url= ]how to order cialis[/url] cialis paypal accepted australia
cheap cialis generic order cialis online pharmacy
viagra prank dangerous [url= ]generic viagra pharmacy online[/url] what happens when a boy takes viagra
pharmacy tech us online pharmacy
viagra 100mg price viagra overnight delivery usa
canada pharmacy not requiring prescription drugs from canada online
cialis paypal cialis pills overnight
cialis with daproxene generic cialis for daily use
viagra prima del rapporto tiagra vs viagra
what is the active ingredient in viagra [url= ]viagra connect walgreens[/url] online viagra prescription
best online pharmacy for viagra Methocarbamol
domestic cialis online cheap [url= ]cialis fastest shipping[/url] cialis 20mg shopping
does viagra make you horny best time to take viagra
cheap cialis [url= ]cialis shop[/url] i need cialis
viagra available in kerala viagra eilbestellung
walgreens pharmacy online prescription drugs from canada
europe cialis [url= ]online cialis prescription[/url] how soon does cialis work
viagra cialis levitra [url= ]order cialis with dapoxtine[/url] tadalafil 20 mg
list of prescription drugs [url= ]drugs without prescription[/url] publix pharmacy online
canadian pharmacies for viagra [url= ]most addictive prescription drugs[/url] Voveran
how much does cialis cost in canada [url= ]cialis for sell[/url] cialis without prescription
canadian pharmacies that are safe [url= ]order prescription drugs online[/url] pharmacy course online
cialis controlled substance [url= ]cialis canada[/url] 40 mg cialis
cvs pharmacy store near me [url= ]buy viagra canadian pharmacy[/url] can you buy prescription drugs online legally
cialis without prescription [url= ]can i take cialis with daxpoteine[/url] cialis free trial 2018