How to check if an LVM volume is active in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check if an LVM volume is active in Linux. You will use the lvs command to list LVM volumes and understand their attributes, including their active status.

You will also explore the /dev/mapper directory to verify how LVM logical volumes are mapped as device files and use the vgdisplay command to check the status of volume groups. These steps will provide you with the essential skills to monitor and understand your LVM setup.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/SystemInformationandMonitoringGroup(["System Information and Monitoring"]) linux(("Linux")) -.-> linux/BasicSystemCommandsGroup(["Basic System Commands"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux/BasicSystemCommandsGroup -.-> linux/echo("Text Display") linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/SystemInformationandMonitoringGroup -.-> linux/df("Disk Space Reporting") linux/SystemInformationandMonitoringGroup -.-> linux/ps("Process Displaying") subgraph Lab Skills linux/echo -.-> lab-558783{{"How to check if an LVM volume is active in Linux"}} linux/ls -.-> lab-558783{{"How to check if an LVM volume is active in Linux"}} linux/df -.-> lab-558783{{"How to check if an LVM volume is active in Linux"}} linux/ps -.-> lab-558783{{"How to check if an LVM volume is active in Linux"}} end

List LVM volumes with lvs

In this step, you will learn how to list Logical Volume Management (LVM) volumes using the lvs command. LVM provides a more flexible way to manage disk storage compared to traditional partitioning. It allows you to create logical volumes that can span across multiple physical disks and be easily resized.

First, let's open the terminal. If you closed it, click the Xfce Terminal icon on the left side of the desktop.

The lvs command is used to display information about logical volumes. It provides details such as the logical volume name, the volume group it belongs to, its size, and its attributes.

Type the following command in your terminal and press Enter:

lvs

You should see output similar to this:

  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Cpy%Sync Convert
  root ubuntu -wi-ao---- <...>g
  swap ubuntu -wi-ao---- <...>g

Let's break down the output:

  • LV: The name of the Logical Volume. In this example, you see root and swap.
  • VG: The Volume Group the Logical Volume belongs to. Here, both belong to the ubuntu volume group.
  • Attr: Attributes of the Logical Volume. -wi-ao---- indicates the volume is writable, active, open, etc.
  • LSize: The size of the Logical Volume. The exact size will vary depending on the system configuration.
  • Other columns like Pool, Origin, Data%, Meta%, Cpy%Sync, and Convert are related to more advanced LVM features like thin provisioning and snapshots, which you don't need to worry about for now.

The lvs command is a fundamental tool for understanding your LVM setup. It gives you a quick overview of the logical volumes available on your system.

Click Continue to proceed to the next step.

Verify volume mappings in /dev/mapper

In this step, you will explore the /dev/mapper directory to see how LVM logical volumes are mapped as device files. In Linux, devices like hard drives and partitions are represented as files in the /dev directory. LVM creates symbolic links in /dev/mapper that point to the actual device nodes for your logical volumes.

Open your terminal if it's not already open.

We will use the ls command to list the contents of the /dev/mapper directory. The ls command is used to list files and directories.

Type the following command and press Enter:

ls /dev/mapper/

You should see output similar to this:

ubuntu-root  ubuntu-swap

This output shows the device mappings for the logical volumes you saw in the previous step using lvs.

  • ubuntu-root: This corresponds to the root logical volume within the ubuntu volume group.
  • ubuntu-swap: This corresponds to the swap logical volume within the ubuntu volume group.

These entries in /dev/mapper are the device files that the operating system uses to access the logical volumes. For example, your root filesystem is likely mounted using /dev/mapper/ubuntu-root.

Understanding the /dev/mapper directory helps you see the connection between the logical volumes managed by LVM and the device files used by the system.

Click Continue to move on to the next step.

Check volume groups with vgdisplay

In this step, you will use the vgdisplay command to view detailed information about Volume Groups (VGs). A Volume Group is a collection of one or more physical volumes (like hard drives or partitions) that are combined into a single storage pool. Logical volumes are then created from this pool.

Open your terminal if it's not already open.

The vgdisplay command provides a comprehensive view of the configuration and status of your Volume Groups.

Type the following command and press Enter:

vgdisplay

You will see detailed output about the volume group(s) on your system. The output will be extensive, but let's look at some key lines, focusing on the ubuntu volume group you saw in the previous steps:

  --- Volume group ---
  VG Name               ubuntu
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  <...>
  VG Access             <...>
  VG Status             <...>
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <...> GiB
  PE Size               4.00 MiB
  Total PE              <...>
  Alloc PE / Size       <...> / <...> GiB
  Free  PE / Size       <...> / <...> GiB
  VG UUID               <...>

Let's highlight some important fields:

  • VG Name: The name of the Volume Group (ubuntu).
  • VG Size: The total size of the Volume Group.
  • Cur LV: The current number of Logical Volumes in this Volume Group (you saw root and swap, so this should be 2).
  • Cur PV: The current number of Physical Volumes in this Volume Group.
  • Free PE / Size: The amount of free space available in the Volume Group, shown in Physical Extents (PEs) and their total size. This is the space you can use to create new logical volumes or extend existing ones.

The vgdisplay command is invaluable for understanding the capacity and structure of your LVM Volume Groups.

Click Continue to complete this lab.

Summary

In this lab, you learned how to check if an LVM volume is active in Linux. You started by using the lvs command to list logical volumes and understand their attributes, including the active status indicated by the 'a' flag in the Attr column.

You then explored the /dev/mapper directory to verify the device mappings for active LVM volumes, confirming their presence as device files. Finally, you used the vgdisplay command to display detailed information about volume groups, which can also provide insights into the status of the logical volumes within them.