Mirroring Logical Volumes
Start course

The Logical Volume Manager introduces extra layers of abstraction between the disks or storage devices presented to a Linux system and the file systems placed on them. This course explores the service and its components. This course is part of the Linux Administration Bootcamp learning path, designed to get you up and running with Linux.

Learning Objectives

  • Understand what the LVM is and how it works
  • Create and remove physical volumes (PVs), volume groups (VGs), and logical volumes (LVs)
  • Extend volume groups and extend and mirror logical volumes
  • Migrate Data from one storage device to another

Intended Audience

  • Anyone with basic knowledge of Linux who wants to learn more
  • Professionals who want to learn more about Linux to enhance their career prospects


This is an intermediate-level course so some knowledge of Linux is expected. If you're just starting out, then try our Linux Fundamentals course first.


Just to demonstrate that you can have more than one volume group per Linux system, I'm going to create another VG called VG underscore safe. And I'm just going to pretend that I need the data stored in this volume group to be very safe, hence the name. Of course VGs are made up of Pvs, so let's create a couple of physical volumes for our new volume group. Again, we'll use our old process here of LVM disk scan. See what's available, SDD and SDE are available. So let's go ahead and create those.

Up until this point, we've just been creating one physical volume at a time but you can give the PV create command a list of storage devices. So let's just go ahead and give it both discs at the same time. Okay let's check out our physical volumes with the PVS command and it shows we have those two physical volumes that aren't yet assigned to a volume group. Just like we can provide a list of devices to PV create, we can also give VG create a list of PVs that we want in the volume group. So let's do this VG create, the name, VG underscore safe and then the path to our PVs.

Now if you look at the VGs command, we see VG underscore safe has two physical volumes and no logical volumes at this point because we haven't created any. So let's go ahead and do that now. Let's create a mirrored logical volume. Now this will ensure that an exact copy of the data will be stored on two different storage devices. And we do this with the LV create command, but this time the only slight differences dash M one. So we tell it how many additional copies of our data we want and we want one additional copy. So that means our data will be stored on two disks or have a total of two copies. Again, we'll just give it a size human readable five gigabytes, a name LV underscore secrets

 Let's pretend this is our company secret data. And then we'll give it the volume group name of VG safe. So Let's look at the LVS command and actually it kind of scrolled off to the side, but you can see here in this copy sync column, that it's currently 18.75. And let me just run this command another time or two here. So that copy present sync column indicates if the mirror is synced or not. Now, if it's at 100%, then all the data is synchronized. So let me run this command again.

Okay, at this point, we have exact copies of our data. If you were to replace a failed disc, for example the mirror would need to resync the data from the existing copy to the new disc. While that copy was in progress, the percent would be less than 100. And then when that finished syncing the data to that new device, it would be at 100%. Let's look at the LV's command with the dash A option, which stands for all. The logical volume we created is actually raid one. So a mirror and raid one are the exact same thing. Anyway, when you create a raid logical volume, LVM creates a metadata sub volume that is one extent and size for every data or parody sub volume in the array.

In this example, creating a two way raid one array results in two metadata sub volumes. And those are LV underscore secrets r-meta zero and LV underscore secrets underscore r-meta underscore one and two data sub volumes which are LV underscore secrets underscore r-image underscore zero, as well as r-image underscore one.

Now let's look at the map with PV display. PV display dash M. At the bottom of your screen, you see that LV underscore secrets underscore r-meta, underscore one and LVC secrets r-image underscore one reside on the forward slash dev forward slash SDE discs. It scored off the top of your screen but the output above that is for the dev SDD disc. And that's where the LV secrets are met at zero and LV secrets are image zero live.

To be clear we operate on this logical volume using the name we gave it. For example, let's create a file system on that logical volume and mount it and we'll be using the name that we gave it. So we'll do M-K-F-S dash T-E-X-T four and then the path of VG safe, which is volume group name and then the logical volume name that we gave it.

Okay, let's create ourselves a mount point here. And let's mount our logical volume. So we write to dev VG, underscore safe, LV underscore secrets and let the logical volume manager handle all the mirroring and all the sub volumes and all that metadata and everything else. We just use this false system like any other and we use the name that we gave the logical volume manager. So again, anything we were to write in forward slash secrets will actually be written to two underlying storage devices without us having to do anything extra.

About the Author
Learning Paths

Jason is the founder of the Linux Training Academy as well as the author of "Linux for Beginners" and "Command Line Kung Fu." He has over 20 years of professional Linux experience, having worked for industry leaders such as Hewlett-Packard, Xerox, UPS, FireEye, and Nothing gives him more satisfaction than knowing he has helped thousands of IT professionals level up their careers through his many books and courses.

Covered Topics