pvresize
Resize a physical volume (PV)
SYNOPSIS
pvresize [options] physical_volume_path...
Examples:
pvresize /dev/sda1
pvresize --setphysicalvolumesize 500G /dev/sdb
PARAMETERS
physical_volume_path...
The path to the physical volume(s) to be resized (e.g., /dev/sda1, /dev/mapper/mpatha). This argument is mandatory.
-h, --help
Displays a help message and exits.
-v, --verbose
Increases the verbosity of the command's output, showing more details about the operation.
-t, --test
Enables test mode. The command will perform all operations as if it were making changes, but it will not actually write anything to disk.
--setphysicalvolumesize size
Explicitly sets the physical volume size to the specified size. This can be used for both expanding and (dangerously) shrinking a PV. Size can include units like 'G' for Gigabytes or 'T' for Terabytes.
-y, --yes
Assumes 'yes' to all questions, allowing for non-interactive execution. Use with caution.
--zero n|y
Controls whether newly allocated space on the physical volume should be zeroed out. 'y' will zero the space, 'n' will not. Default is typically 'y' for safety.
DESCRIPTION
pvresize is a crucial LVM (Logical Volume Manager) command used to update the size of a physical volume (PV) to reflect changes in its underlying block device. When a disk partition or entire disk, which is used as an LVM physical volume, is resized (typically expanded, e.g., in a virtual machine), the LVM system needs to be informed of this new size. pvresize performs this update, allowing the additional space to be recognized by the volume group (VG) and subsequently used by logical volumes (LVs) built upon it. It is imperative to resize the underlying block device using tools like fdisk, parted, or cloud provider utilities before running pvresize. While primarily used for expansion, it can also shrink a PV, though this is extremely risky and should only be attempted with extreme caution after ensuring no data occupies the space to be removed, as it can lead to data loss.
CAVEATS
1. Resize Underlying Device First: pvresize only updates LVM metadata; it does not resize the actual disk partition or block device. You must expand the underlying device using tools like fdisk, parted, or a cloud provider's disk expansion feature before running pvresize.
2. Shrinking a PV is Risky: Shrinking a physical volume is extremely dangerous and can lead to immediate data loss if logical volumes or any data reside in the space being removed. Always back up your data and ensure the space is truly unused before attempting to shrink a PV. pvresize does not relocate or check for data on its own.
3. LVM Metadata Only: This command modifies LVM metadata on the PV. It does not affect the file system residing on any logical volumes built on top of this PV. Further steps (like resizing the logical volume and then the file system) are usually required to make the space usable.
FULL LVM RESIZING WORKFLOW (EXPANSION)
To fully expand a file system that resides on a logical volume, the typical sequence of operations is:
1. Expand the underlying disk or partition (e.g., using a virtualization platform, fdisk, or parted).
2. Run pvresize on the physical volume(s) to recognize the new size.
3. Extend the logical volume using lvextend to utilize the newly available space from the PV/VG.
4. Expand the file system on the logical volume (e.g., resize2fs for ext2/3/4, or xfs_growfs for XFS) to make the space accessible to applications.
ONLINE OPERATION
pvresize can generally be run on a physical volume even if logical volumes residing on it are active and file systems are mounted. This is because it only modifies LVM metadata and does not directly interact with or unmount file systems. However, other steps in the full resizing workflow (like resize2fs) may require careful consideration depending on the file system type and version.
HISTORY
pvresize is an integral component of the Linux Logical Volume Manager (LVM) suite, which has been a cornerstone of flexible storage management on Linux systems since its inception. It was developed to provide the dynamic resizing capabilities essential for modern server and virtualized environments, where storage requirements frequently change without the luxury of system downtime. Its core functionality—updating PV metadata to reflect underlying block device size changes—has remained a stable and critical feature within LVM's evolution.