5+ lvscan command examples in Linux [Cheat Sheet]


Rohan Timalsina

CheatSheet

Introduction to lvscan command

lvscan command scans for all logical volumes in the Linux system and lists them. It displays the status, path, size, and allocation policy in one line per logical volume.

 

Are you new to LVM and still learning how it works?

We have written detailed articles covering different areas of managing logical volumes, which you can follow using the below links:

Manage Logical Volume in Linux - One STOP Solution
Understand LVM Architecture
Create LVM during installation RHEL/CentOS 7/8
How to use LVM Snapshot for Backup and Restore
Create Mirrored Logical Volume
Create Striped Logical Volume

 

Different examples to use lvscan command

The syntax for lvscan command is as follows:

# lvscan [option]

The output of lvscan command indicates whether the logical volume is active or not, a snapshot or origin, the size of the device and its allocation policy.

 

1. lvscan command scan all logical volumes in all volume groups

You can use lvscan command without any arguments to scan all logical volumes in all volume groups and list them.

# lvscan

Sample Output:

lvscan command to scan for logical volumes

Here,

  • ACTIVE means the logical volume is active.
  • inherit is the default allocation policy for a logical volume.

You can change these attributes of a logical volume by using lvchange command. We have covered the different examples of lvchange command in 10+ lvchange command examples in Linux [Cheat Sheet].

 

2. Scan all logical volumes including internal logical volumes

You can use -a or --all to display the information of internal logical volumes that are components of normally-accessible logical volumes (e.g. mirrors), but are not independently accessible (e.g. not mountable).

# lvscan -a

OR

# lvscan --all

Sample Output:

lvscan command to display internal logical volumes

 

lvs, lvdisplay, and lvscan are three commands that you can use to display properties of LVM logical volumes.

lvdisplay shows the attributes of a logical volume like size, read/write status, allocation policy, mapping etc.

lvs provides the formatted output, displaying one line per logical volume.

We have written a detailed article on the lvdisplay command which you can find in the below link:

5+ lvdisplay command examples in Linux [Cheat Sheet]

 

3. Display logical volume scan status in detail

We can increase the verbosity level by using -v from 1 to 4 times to increase the detail of messages sent to stdout or stderr

# lvscan -d -vv
      devices/global_filter not found in config: defaulting to global_filter = [ "a|.*/|" ]
      global/lvmetad_update_wait_time not found in config: defaulting to 10
      devices/filter not found in config: defaulting to filter = [ "a|.*/|" ]
      devices/cache not found in config: defaulting to /etc/lvm/cache/.cache
      metadata/record_lvs_history not found in config: defaulting to 0
      File-based locking selected.
      report/output_format not found in config: defaulting to basic
      log/report_command_log not found in config: defaulting to 0
      Obtaining the complete list of VGs before processing their LVs
      Processing VG system DBJ0Tw-ezEz-GqmH-ceQX-RgEi-OpDi-8diILw
      Locking /run/lock/lvm/V_system RB
      Reading VG system DBJ0Tw-ezEz-GqmH-ceQX-RgEi-OpDi-8diILw
      /dev/md2: size is 1710655488 sectors
      Adding system/var-opt to the list of LVs to be processed.
      Adding system/home to the list of LVs to be processed.
      Adding system/export to the list of LVs to be processed.
      Adding system/DEMO to the list of LVs to be processed.
      Adding system/opt to the list of LVs to be processed.
      Adding system/opt-test to the list of LVs to be processed.
      Adding system/tmp to the list of LVs to be processed.
      Adding system/var to the list of LVs to be processed.
      Processing LV var-opt in VG system.
  ACTIVE            '/dev/system/var-opt' [25.00 GiB] inherit
      Processing LV home in VG system.
  ACTIVE            '/dev/system/home' [4.00 GiB] inherit
      Processing LV export in VG system.
  ACTIVE            '/dev/system/export' [30.00 GiB] inherit
      Processing LV DEMO in VG system.
  ACTIVE            '/dev/system/DEMO' [<695.69 GiB] inherit
      Processing LV opt in VG system.
  ACTIVE            '/dev/system/opt' [10.00 GiB] inherit
      Processing LV opt-test in VG system.
  ACTIVE            '/dev/system/opt-test' [5.00 GiB] inherit
      Processing LV tmp in VG system.
  ACTIVE            '/dev/system/tmp' [20.00 GiB] inherit
      Processing LV var in VG system.
  ACTIVE            '/dev/system/var' [8.00 GiB] inherit
      Unlocking /run/lock/lvm/V_system
      Processing VG os tBt2kl-tYGx-1iI9-e51W-2qd3-ArCX-5bgpBF
      Locking /run/lock/lvm/V_os RB
      Reading VG os tBt2kl-tYGx-1iI9-e51W-2qd3-ArCX-5bgpBF
      /dev/md1: size is 37715968 sectors
      Adding os/root to the list of LVs to be processed.
      Processing LV root in VG os.
  ACTIVE            '/dev/os/root' [8.00 GiB] inherit
      Unlocking /run/lock/lvm/V_os

 

4. Disable device-mapper driver while perform the scan

By default device-mapper driver is used to scan the available logical volumes. This can be disabled using --driverloaded y|n as shown below:

# lvscan --driverloaded n
  WARNING: Activation disabled. No device-mapper interaction will be attempted.
  inactive          '/dev/system/var-opt' [25.00 GiB] inherit
  inactive          '/dev/system/home' [4.00 GiB] inherit
  inactive          '/dev/system/export' [30.00 GiB] inherit
  inactive          '/dev/system/DEMO' [<695.69 GiB] inherit
  inactive          '/dev/system/opt' [10.00 GiB] inherit
  inactive          '/dev/system/opt-test' [5.00 GiB] inherit
  inactive          '/dev/system/tmp' [20.00 GiB] inherit
  inactive          '/dev/system/var' [8.00 GiB] inherit
  inactive          '/dev/os/root' [8.00 GiB] inherit

 

5. Perform lvscan in test mode without updating metadata

Every time you perform a scan of logical volumes, the metadata file gets updated. This can be disabled by using the test mode with -t or --test as shown below:

# lvscan -t
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
  ACTIVE            '/dev/system/var-opt' [25.00 GiB] inherit
  ACTIVE            '/dev/system/home' [4.00 GiB] inherit
  ACTIVE            '/dev/system/export' [30.00 GiB] inherit
  ACTIVE            '/dev/system/DEMO' [<695.69 GiB] inherit
  ACTIVE            '/dev/system/opt' [10.00 GiB] inherit
  ACTIVE            '/dev/system/opt-test' [5.00 GiB] inherit
  ACTIVE            '/dev/system/tmp' [20.00 GiB] inherit
  ACTIVE            '/dev/system/var' [8.00 GiB] inherit
  ACTIVE            '/dev/os/root' [8.00 GiB] inherit

 

6. Perform a logical volume scan in read only mode

Every time you execute lvscan command, it will lock the metadata for write purpose. So we can run the command in special read only mpde which will read on disk metadata without acquiring any locks. This can be used to peek inside metadata used by a virtual machine image while the virtual machine is running. It can also be used to peek inside the metadata of clustered VGs when clustered locking is not configured or running.

# lvscan --readonly
  inactive          '/dev/system/var-opt' [25.00 GiB] inherit
  inactive          '/dev/system/home' [4.00 GiB] inherit
  inactive          '/dev/system/export' [30.00 GiB] inherit
  inactive          '/dev/system/DEMO' [<695.69 GiB] inherit
  inactive          '/dev/system/opt' [10.00 GiB] inherit
  inactive          '/dev/system/opt-test' [5.00 GiB] inherit
  inactive          '/dev/system/tmp' [20.00 GiB] inherit
  inactive          '/dev/system/var' [8.00 GiB] inherit
  inactive          '/dev/os/root' [8.00 GiB] inherit

 

Conclusion

We hope this article helps you to understand the use of the lvscan command in Linux. If you have any confusion, please let us know in the comment section below.

 

What's Next

How to PROPERLY use lvextend to increase LV size
Using lvreduce to PROPERLY shrink Logical Volume [Cheat Sheet]

 

Further Reading

man page for lvscan command

 

Views: 79

Rohan Timalsina

He is proficient in a wide range of skills, including Page Builder Plugins such as Elementor, Beaver Builder, Visual Composer, and Divi Builder. His expertise extends to Front End Development with HTML5/CSS3, JavaScript, Bootstrap, and React.js. You can reach out to him on LinkedIn or check his projects on GitHub page.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment

GoLinuxCloud Logo


We try to offer easy-to-follow guides and tips on various topics such as Linux, Cloud Computing, Programming Languages, Ethical Hacking and much more.

Programming Languages

JavaScript

Python

Golang

Node.js

Java

Laravel