Using the Logical Volume Manager (LVM) in Linux

Instructor: Daniel Arnold

Daniel has a bachelor's in Computer Science, is a CISSP and CEA. He is a cyber competition coach and speaks on Info Security at conferences.

In this lesson, we will be exploring the Logical Volume Manager (LVM). We will see how to use the tool to create and manage volumes and use it for monitoring free space on our volumes.

Logical Volume Manager

The Logical Volume Manager (LVM) is the tool that a system admin needs for managing a set of disks to be aggregated into logical units of storage that we refer to as a volume. In the early stages of our Linux System Admin journey, we usually interact with computer systems that are limited to just the drive/s that are installed inside the machine and typical peripheral drives such as flash drives and DVDs.

As we begin to work in more advanced systems, we may begin to encounter specialized storage systems that require different tools and techniques. Most pertinent to our purposes here is a system referred to as a Storage Area Network (SAN), which presents disk space in a block format for the server admin to organize according to their needs. At a high level, making storage available in a usable form with the LVM tools operates at three levels.

  1. Physical volumes that correlate to physical disks.
  2. Volume groups that are aggregations of the physical volumes.
  3. Logical volumes that are one or more divisions of volume groups (addressable drives).

Physical Volumes

Now let's walk through an example to make this concrete. In our scenario, we have three drives with which to create our disk layout - sda, sdb, and sdc. We'll first need to create partitions on each with the fdisk command. It looks like this:

disk /dev/sda

Then, we select n at the Command prompt to create a new partition. We will take the simplest options for partition number using 1, and hit enter for defaults on the cylinder questions. Example output is shown in Figure 1:

Figure 1: fdisk output
Figure 1: fdisk

Back at the fdisk menu, we'll need to change the partition ID by selecting t and then indicate the type of file system. There are a lot of options that we could use but typically we'll want to create a Linux LVM. The types are identified by hex codes and ours is 8e. See Figure 2 below:

Figure 2: fdisk label
Figure 2: fdisk continued

Last in this set of steps is to write the changes with the w menu option. See Figure 3:

Figure 3: fdisk write changes
Figure 3:  fdisk write changes

That concludes setting up the first physical volume - sda. Next, we repeat that process for sdb and sdc just as before. We use the fdisk command again as so:

fdisk /dev/sdb

We repeat the menu options and after writing those changes and repeat it all again for sdc. Those three repetitions of the fdisk tool operations give us three volumes on our three physical hard drives. Our next move will be to use the pvcreate command to lay out the file system.

pvcreate /dev/sda

Repeat the command for sdb and sdc.

Volume Groups

Now, we need to take our new volumes and aggregate them into a volume group which we can then divvy up into logical partitions on our server. Things get a bit simpler here as we can take all three of our volumes and add them to the new volume group in a single command - vgcreate. We type the command itself, followed by the desired name of our new volume group, and then the list of physical volumes to be included in the volume group. So, if we wish to name our volume group VG1, the command would look like this:

vgcreate VG1 /dev/sda /dev/sdb /dev/sdc

We can then verify by running the vgdisplay command as shown in Figure 4:

Figure 4: pvdisplay
Figure 4: pvdisplay

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 160 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Create an account to start this course today
Try it risk-free for 30 days!
Create An Account