Where does LVM store data

failure-resistancelvm

My questions are similar to this thread Does LVM increase the risk of data loss?, however, I couldn't find a satisfying answer.

So the question is, where does LVM store data/files, when I have a Volume Group (VG) of 3 physical disks?
What happens when one disk fails? Can I just unplug that disk, tell LVM to remove that physical disk from the VG and just continue working with the other disks?
So the real question is: Does LVM save a file on one disk or does LVM fragment the file and split it throughout the three disks?
The first option can't possible be right, because what happens when I have a 3GB file, my VG says that 3GB are free, but in fact each disk only have 1GB of space left.
So the latter is true? But then this means that I will definitely lose some other data other than from the failing disk?

Best Answer

The question is not very clear, but I will try to answer anyway.

First thing is that VG itself cannot store data (OK, it can, but there are little chances that you are using it this way). Second thing - LVM does not see disks, but physical volumes.

Usually data is stored on partitions defined under logical volumes. One VG can contain many LVs on many PVs. An image from Wikimedia may help:

LVM scheme

Now it depends on how have you configured your LVs - as linear, stripped or mirrored volumes. Also, normally LVs are placed on PVs in order, but you may force LVM to place them on specific PVs.

If a disk containig a PV will fail, there are two main things that can happen:

  • if a PV contained no LV, LVM will shout that it cannot find that PV, but data stored on other LVs will be safe
  • if there was at least a part of a logical volume on the missing PV, the filesystem defined on that LV will certainly be corrupted. Now it depends on the filesystem used how many data you will lose and how hard it will be to recover the remaining part.

Of course if you have configured LVM in stripped mode, most probably every single disk that fails will make all filesystems on all LVs corrupted.

If you want to read more about LVM internals, there is a good article in RedHat magazine: http://www.redhat.com/magazine/009jul05/features/lvm2/

Related Question