LinuxCommandLibrary

vgscan

Scan for volume groups

TLDR

Scan for volume groups and print information about each group found

$ sudo vgscan
copy

Scan for volume groups and add the special files in /dev, if they don't already exist, needed to access the logical volumes in the found groups
$ sudo vgscan --mknodes
copy

SYNOPSIS

vgscan [OPTIONS] [DEVICES...]

Common options include:
vgscan --mknodes
vgscan --cache
vgscan --refresh
vgscan --verbose
vgscan --debug

PARAMETERS

--mknodes, -e
    Create LVM device nodes in /dev for discovered logical volumes.

--cache
    Update the LVM metadata cache file (/etc/lvm/cache/.cache).

--refresh
    Refresh the kernel device cache and update the LVM cache. This implies --cache.

--verbose, -v
    Provide more detailed output during execution.

--debug, -d
    Provide extensive debug output.

--partial, -P
    Allow processing of volume groups that are only partially available or configured.

--ignorelockingfailure, -K
    Continue execution even if LVM locking failures occur.

--noudevsync
    Do not wait for udev synchronisation. Potentially faster but less robust.

--reportformat {basic|json}
    Specify the output format for reports. Can be basic (default) or json.

--json
    Output report data in JSON format.

--columns
    Display report in a column format (for basic report format).

--devices
    Restrict scanning to specific physical volumes, volume groups, or logical volumes.

--devicesfile
    Restrict scanning to devices listed in the specified file.

--ignore-suspended-devices
    Skip devices that are currently in a suspended state.

--shared
    Report on LVM devices that are identified as shared (e.g., in a clustered environment).

--foreign
    Report on LVM devices that are detected but do not belong to the local system ID.

--readonly, -r
    Run the command in a read-only mode, preventing any metadata changes.

--setautoactivation {y|n}
    Set or clear the autoactivation flag on volume groups during the scan.

--commandprofile
    Use a specified command profile for configuration.

--config
    Use a specific LVM configuration file instead of the default.

--driverloaded {y|n}
    Indicate whether the LVM kernel driver is loaded (used by LVM scripts).

--longnames
    Display full, long names for LVM components.

--lockopt
    Pass specific options to the locking module.

--systemid
    Specify the system ID for filtering or processing volume groups.

--version
    Display the LVM version information.

--select
    Select objects for processing based on specific criteria.

DESCRIPTION

vgscan is an essential LVM (Logical Volume Manager) command used to scan all block devices on a system for LVM physical volumes and volume groups. Upon finding LVM metadata, it rebuilds and updates the LVM cache file, typically located at /etc/lvm/cache/.cache. This cache is crucial for other LVM commands to quickly identify and manage LVM components without rescanning every device. It also populates the /dev directory with the necessary device nodes for LVM components if they are not already present or if the --mknodes option is used (though often handled by udev).

This command is frequently executed during system boot to discover LVM volumes, after adding new disks, or during recovery operations when LVM metadata might be inconsistent or lost. It helps ensure that the LVM infrastructure is correctly recognized and ready for further operations like activating volume groups with vgchange or listing logical volumes with lvscan.

CAVEATS

vgscan requires root privileges to scan system block devices and update LVM metadata.

While it scans for LVM components, it does not activate volume groups; this task is performed by the vgchange command.

On systems with a large number of disks or complex LVM setups, vgscan can take a significant amount of time to complete.

In modern Linux distributions, device node creation is typically handled by udev; however, the --mknodes option can be used to force creation if needed, particularly in environments without a fully functional udev.

METADATA CACHE AND BACKUP

vgscan primarily updates the LVM metadata cache, usually at /etc/lvm/cache/.cache, which speeds up subsequent LVM operations. It also implicitly interacts with metadata backups stored in /etc/lvm/backup and /etc/lvm/archive directories for recovery purposes.

UDEV INTEGRATION

In modern Linux systems, vgscan works closely with udev. Udev automatically creates and manages device nodes in /dev based on kernel events and LVM's udev rules, often making the explicit use of --mknodes unnecessary. vgscan ensures LVM's view of devices aligns with the kernel's and udev's.

HISTORY

LVM (Logical Volume Manager) was originally developed for Linux by Heinz Mauelshagen, with LVM1 first released in 1999. vgscan has been a core component since its inception, essential for discovering and managing LVM structures. The more robust LVM2, released in 2002, brought significant improvements in scalability, performance, and metadata handling, where vgscan continued its critical role in scanning and rebuilding the LVM metadata cache. Its functionality has remained largely consistent, adapting to modern kernel and udev integrations to ensure reliable device discovery.

SEE ALSO

pvscan(8), vgchange(8), lvscan(8), pvs(8), vgs(8), lvs(8), lvm(8)

Copied to clipboard