pvresize Command in Linux



The pvresize command in Linux resizes the physical volumes (PVs). It allows adjusting the size of a PV after resizing the underlying block device. A PV (Physical Volume) is the lowest layer in LVM (Logical Volume Manager), representing a storage device initialized for use with LVM.

Table of Contents

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

Note − The pvresize command can only expand the PV after increasing the underlying block device.

Syntax of pvresize Command

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

pvresize [options] [physical_volume]

In the above syntax, the [options] field is used to specify the options to modify the command’s output. The [physical_volume] field is used to specify PV that needs to be resized.

pvresize Command Options

The options of the Linux pvresize command are listed below −

Flags Options Description
--commandprofile String Specifies command profile for configuration.
--devices PV Specifies devices for the command, and accepts list or multiple entries.
--devicesfile String Specifies a file listing LVM devices (managed by lvmdevices).
--driverloaded y|n Disables device-mapper use when set to 'n' (for testing).
-h --help Displays help text.
--journal String Logs command information to systemd journal.
--lockopt String Passes special options to lvmlockd.
--longhelp Displays extended help text.
--nohints Disables hints file usage for locating PVs.
--nolocking Disables LVM locking mechanism.
--profile String Alias for --commandprofile or --metadataprofile.
-q --quiet Suppresses output/log messages. Repeat to suppress prompts.
--reportformat basic|json Sets output format (basic table or JSON).
--setphysicalvolumesize Size[m|UNIT] Manually sets PV size, overriding auto-detection.
-t --test Runs in test mode, preventing metadata updates.
-v --verbose Sets verbosity for detailed messages.
--version Displays version information.
-y --yes Automatically confirms prompts with yes (use with caution).

Examples of pvresize Command in Linux

This section explores the usage of the pvresize command in Linux with examples −

Note − Resizing physical volumes can affect logical volumes. Use caution, especially when shrinking PVs with allocated data.

  • Expanding a Physical Volume (PV) After Increasing Disk Size
  • Getting Verbose Output
  • Shrinking a Physical Volume (PV) to a Specific Size
  • Running pvresize Command in Test Mode
  • Suppressing Output and Log Messages
  • Displaying Usage Help

Expanding a Physical Volume (PV) After Increasing Disk Size

When a disk or partition size is increased, pvresize allows LVM to use the additional space. To resize the PV to match the new disk size, use the pvresize command in the following way −

sudo pvresize /dev/vda3
pvresize Command in Linux1

The output indicates that the physical volume at /dev/vda3 was successfully resized to match the new disk size, using the full available space. The operation was successful with one PV updated and no errors or skipped volumes.

To confirm the new PV size, use the following command −

sudo pvdisplay /dev/vda3

Getting Verbose Output

To get verbose output, use the -v or --verbose option with the pvresize command.

sudo pvresize -v /dev/vda3
pvresize Command in Linux2

Shrinking a Physical Volume (PV) to a Specific Size

To shrink the physical volume to a specific size, use the --setphysicalvolumesize option with the pvresize command. For example, to resize PV to 5GB, use the following command −

sudo pvresize --setphysicalvolumesize 5G /dev/vda3

Warning − Note that Shrinking a PV with allocated extents may result in data loss.

Running pvresize Command in Test Mode

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

sudo pvresize -t /dev/vda3
pvresize Command in Linux3

Suppressing Output and Log Messages

To suppress the output and the log messages, use the -q or --quiet option −

sudo pvresize -qq /dev/vda3
pvresize Command in Linux4

The PV /dev/vda3 will be resized to match the underlying device size or any manual size specified without any output or prompts being shown. This is useful in automated scripts or scenarios where confirmation or verbosity is unnecessary.

Displaying Usage Help

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

pvresize -h

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

pvresize --longhelp

Conclusion

The pvresize command in Linux is used to resize physical volumes (PVs) within the Logical Volume Manager (LVM) after resizing the underlying block device. It supports various options, such as setting the size manually, running in test mode, and suppressing output.

This command is useful for expanding or shrinking PVs, ensuring that they match the size of the underlying storage device. Caution should be taken when shrinking PVs, as data loss may occur if extents are allocated. Moreover, it allows for verbose output and provides helpful options for automation and debugging.

Advertisements