How to use the command vgscan (with examples)

How to use the command vgscan (with examples)

The vgscan command is part of the Logical Volume Manager (LVM) system in Linux. It is used to scan for volume groups on all supported LVM block devices. This command can be useful for detecting and managing volume groups, which are collections of physical volumes that can be used to create logical volumes.

Use case 1: Scan for volume groups and print information about each group found

Code:

sudo vgscan

Motivation: The motivation for using this command is to quickly identify and gather information about the volume groups available on the system. By running vgscan, you can get a list of volume groups along with their attributes such as UUID, size, physical volume(s), etc.

Explanation: The sudo command is used to run vgscan with administrative privileges. This is necessary as the command accesses low-level system information. vgscan scans for volume groups on all supported LVM block devices.

Example output:

  Reading volume groups from cache.
  Found volume group "vg1" using metadata type lvm2
  Found volume group "vg2" using metadata type lvm2

Use case 2: 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

Code:

sudo vgscan --mknodes

Motivation: The motivation for using this example is to ensure that the necessary special files for accessing logical volumes are created in /dev. When a system is booted, these files are usually automatically created, but in some cases, they may be missing. Running vgscan with the --mknodes option creates any missing special files.

Explanation: Like in the previous use case, the sudo command is used to run vgscan with administrative privileges. The --mknodes option is provided to instruct vgscan to add the special files in /dev needed to access the logical volumes found during the scan.

Example output (when special files needed to be created):

  Reading volume groups from cache.
  Found volume group "vg1" using metadata type lvm2
  Found volume group "vg2" using metadata type lvm2
  Creating directory "/dev/vg1" with mode 0744.
  Creating directory "/dev/vg2" with mode 0744.
  Creating device node "/dev/vg1/lv1" with major:minor 254:0 and mode 0660.
  Creating device node "/dev/vg2/lv1" with major:minor 254:1 and mode 0660.

Example output (when no special files needed to be created):

  Reading volume groups from cache.
  Found volume group "vg1" using metadata type lvm2
  Found volume group "vg2" using metadata type lvm2
  No changes to device/filesystem for vg1.
  No changes to device/filesystem for vg2.

Conclusion:

The vgscan command is a powerful tool for scanning and managing volume groups in a Linux system. By using vgscan, you can easily gather information about available volume groups and ensure that the necessary special files for accessing logical volumes are created. Whether you need to troubleshoot or manage your system’s LVM configuration, vgscan can be a valuable asset.

Related Posts

How to use the command `zbarimg` (with examples)

How to use the command `zbarimg` (with examples)

The zbarimg command is a tool that allows you to scan and decode barcodes from image files.

Read More
Changing the remote for pulling and pushing (with examples)

Changing the remote for pulling and pushing (with examples)

Use case 1: Change the upstream remote to origin git rename-remote upstream origin Motivation In this use case, we want to change the remote repository used for pulling and pushing to the new “origin” repository.

Read More
How to use the command ppmtoxpm (with examples)

How to use the command ppmtoxpm (with examples)

ppmtoxpm is a command-line tool that allows users to convert a PPM (Portable Pixmap) image to an X11 version 3 pixmap image.

Read More