pvchange Command in Linux



The pvchange command in Linux changes the attributes of physical volumes (PV). It modifies properties such as availability, allocation, and metadata settings of a physical volume. It modifies physical volume attributes dynamically without requiring reconfiguration or data loss.

Table of Contents

Here is a comprehensive guide to the options available with the pvchange command −

Syntax of pvchange Command

The syntax of the pvchange command in Linux is as follows −

pvchange [options] [physical_volume]

The [options] field in the above syntax is used to specify various flags/options that define what changes are to be applied. The [physical_volume] field is used to specify the specific physical volume being modified.

pvchange Command Options

The options of the Linux pvchange command are listed below −

Flags Options Description
--addtag Tag Adds a tag to a PV, VG, or LV. It can be repeated to add multiple tags.
-a --all Change all visible PVs.
-x y|n --allocatable y|n Enable or disable allocation of physical extents on this PV.
-A y|n --autobackup y|n Enable or disable automatic metadata backup.
--commandprofile String Specify a command profile for configuration.
--config String Override lvm.conf settings with a custom configuration.
-d --debug ... Set debug level (1-6) for detailed logging.
--deltag Tag Deletes a tag from a PV, VG, or LV. It can be repeated.
--devices PV Specify devices the command can use (comma-separated list).
--devicesfile String Specify a file listing devices for LVM use.
--driverloaded y|n Disable device-mapper use (for debugging).
-f --force Override checks, confirmations, and protections (use with caution).
-h --help Display help text.
--journal String Record information in the systemd journal.
--lockopt String Pass options for lvmlockd.
--longhelp Display extended help text.
--metadataignore y|n Ignore metadata areas on the PV (prevents metadata storage).
--nohints Ignore the hints file when locating PVs.
--nolocking Disable locking.
--profile String Alias for --commandprofile or --metadataprofile.
-q --quiet ... Suppress output and log messages.
--reportformat basic|json Set output format for reports (basic or JSON).
-S String --select String Select objects for processing based on criteria.
-t --test Run in test mode (no metadata updates).
-u --uuid Generate a new UUID for the specified PVs.
-v --verbose ... Set verbosity level (1-4).
--version Display version information.
-y --yes Assume yes for all confirmations (use with caution).

Examples of pvchange Command in Linux

In this section, the usage of the pvchange command in Linux will be explored with examples.

  • Enabling Allocation of Physical Extents on a Physical Volume (PV)
  • Disabling Allocation of Physical Extents on a Physical Volume (PV)
  • Adding a Tag to a Physical Volume (PV)
  • Removing a Tag from a Physical Volume (PV)
  • Applying Changes on a Physical Volume (PV) by a Specific Criteria
  • Running the pvchange Command in Test Mode
  • Displaying Usage Help

Enabling Allocation of Physical Extents on a Physical Volume (PV)

To enable the allocation of physical extents on a physical volume (PV), use the pvchange command with the -x or --allocatable option −

sudo pvchange -x y /dev/vda3
pvchange Command in Linux1

Disabling Allocation of Physical Extents on a Physical Volume (PV)

To disable the allocation of physical extents on a physical volume (PV), use the -x or --allocatable option with n −

sudo pvchange -x n /dev/vda3
pvchange Command in Linux2

The above command prevents the allocation of physical extents on the free space of one or more physical volumes.

Adding a Tag to a Physical Volume (PV)

To add a tag to a physical volume (PV), use the --addtag option with the pvchange command −

sudo pvchange --addtag "mypv" /dev/vda3

To verify the tag change, run the following command −

sudo pvs -o pv_tags
pvchange Command in Linux3

Removing a Tag from a Physical Volume (PV)

To remove a tag to a physical volume (PV), use the --deltag option with the pvchange command −

sudo pvchange --deltag "mypv" /dev/vda3
pvchange Command in Linux4

Applying Changes on a Physical Volume (PV) by a Specific Criteria

To apply changes to a physical volume (PV) based on specific criteria, use the -S or --select option. For example, to enable allocation only for physical volumes that are less than 2GB, use the pvchange command in the following way −

sudo pvchange -x y -S 'pv_size < 2G' /dev/vda3

To list all the attributes that can be used as criteria, use the following command −

pvs -o help
pvchange Command in Linux5

Running the pvchange Command in Test Mode

To dry run the pvchange command, use the -t or --test option −

sudo pvchange -t -x n /dev/vda3

Displaying Usage Help

To display usage help of the pvchange command, use the -h or --help option −

pvchange -h

To display the detailed help, use the --longhelp option −

pvchange --longhelp

Conclusion

The pvchange command in Linux modifies the attributes of physical volumes, allowing changes to availability, allocation, and metadata settings without data loss. It provides various options to enable or disable allocation, manage metadata, add or remove tags, and perform test runs. Examples demonstrate practical usage, such as enabling or disabling allocation, tagging physical volumes, and applying changes based on specific criteria. The command also includes options for debugging, configuring profiles, and displaying help information.

Advertisements