pvck Command in Linux



The pvck command in Linux checks and repairs the metadata on physical volumes (PVs). It helps diagnose and fix issues related to LVM metadata corruption. This is a low-level tool meant for debugging and repair. It should be used cautiously because it can modify metadata and should be done only when needed.

Table of Contents

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

Note − The pvck command should only be used when standard LVM commands such as pvdisplay fail to diagnose metadata corruption.

Syntax of pvck Command

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

pvck [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 one or more device names (example: /dev/sdX) whose metadata is required to repair or display.

pvck Command Options

The repair options of the Linux pvck command are listed below −

Options Description
--repair Uses a metadata file from --dump or a backup. Can repair from another PV in the same VG.
--settings "pv_uuid=<UUID>" Needed if the device name has changed, ensuring correct UUID assignment.
--settings "mda_offset=0 mda_size=0" If pv_header is damaged and no metadata areas exist.
--repairtype pv_header Fixes the sector containing pv_header and label_header.
--repairtype metadata Restores mda_header and metadata text. Requires valid headers.
--repairtype label_header Fixes label_header but leaves pv_header unchanged.

Arguments used with the --dump option are given below −

Options Description
headers Print LVM on-disk headers and structures.
metadata Print or save the latest VG metadata.
metadata_all List all VG metadata versions.
metadata_search List all VG metadata versions by searching common locations.
metadata_area Save the entire text metadata area to a file.

Other common options are given below −

Flags Options Description
--commandprofile String Specifies the command profile for configuration.
--config String Overrides lvm.conf settings using the same format or section/field syntax.
-d --debug Sets debug level (1 to 6 for increasing detail).
--devices PV Limits the command to specified devices (comma-separated list allowed).
--devicesfile String Specifies a file listing devices LVM should use.
--driverloaded y|n Prevents the use of device-mapper if set to n (for testing/debugging).
-f String --file String Specifies a metadata file for reading or writing.
-h --help Displays help text.
--journal String Records command information in the systemd journal.
--labelsector Number Specifies a different sector for LVM2 label (0-3).
--lockopt String Passes special options to lvmlockd.
--longhelp Displays extended help text.
--nohints Disables use of hint files for locating PVs.
--nolocking Disables LVM locking mechanisms.
--profile String Alias for --commandprofile or --metadataprofile.
--pvmetadatacopies 0|1|2 Sets number of VG metadata copies stored on a PV (0 to disable).
-q --quiet Suppresses output and logs; repeated use suppresses prompts.
--repair Repairs PV headers and metadata.
--settings String Defines command-specific settings in Key = Value format.
-t --test Runs in test mode without updating metadata.
-v --verbose Increases verbosity level (1 to 4).
--version Displays version information.

Examples of pvck Command in Linux

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

  • Checking the Integrity of a Physical Volume (PV)
  • Getting Verbose Output
  • Dumping Data
  • Repairing a PV with a Specific Metadata File
  • Running the pvck Command in Test Mode
  • Recording Information to the Journal
  • Displaying Usage Help

Checking the Integrity of a Physical Volume (PV)

To check the integrity of a physical volume (PV) and its associated metadata, use the pvck command with the PV name −

sudo pvck /dev/vda3
pvck Command in Linux1

The pvck command requires sudo privileges.

Getting Verbose Output

To get the verbose output, use the -v or --verbose option with the pvck command. To increase the verbosity level, use the -vv −

sudo pvck -vv /dev/vda3
pvck Command in Linux2

Dumping Data

To dump headers, metadata, and metadata_search of a PV, use the --dump option. For example, to dump the metadata, use the pvck command in the following way −

sudo pvck --dump metadata /dev/vda3
pvck Command in Linux3

The above command displays the data to the standard output. To save the dumped data to a file use the redirection operator (>).

sudo pvck --dump metadata /dev/vda3 > metadata.dump

Similarly, headers, metadata_all, and metadata_search can be dumped.

Repairing a PV with a Specific Metadata File

To repair the physical volume (PV) with a specific metadata file, use the pvck command in the following way −

sudo pvck --repair --file /home/user/metadata.dump /dev/vda3
pvck Command in Linux4

The above command repairs the /dev/vda3 PV using metadata.dump file. The dump file can be generated using the dump options. Press n or y to continue the process.

Warning: The repair option should be used with caution, as it can modify critical metadata on the physical volume and may result in data loss if not handled properly. Always back up metadata before running this command.

Similarly, the metadata types can also be specified, such as metadata, pv_header, or label_header, using the --repairtype option −

sudo pvck --repairtype pv_header --file /home/user/metadata.dump /dev/vda3

Running the pvck Command in Test Mode

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

sudo pvck -t /dev/vda3

Recording Information to the Journal

To record information about the command in the systemd journal, use the --journal option with the pvck command. For example, to journal debug details, use the following command −

sudo pvck --journal debug /dev/vda3

Other logging levels that can be recorded can be defined using the following flags −

  • command - Records information about the commands being executed.
  • output - Records the output generated by the command.

Displaying Usage Help

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

pvck -h

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

pvck --longhelp

Conclusion

The pvck command in Linux is a powerful tool used to check and repair metadata on physical volumes (PVs). It is a handy tool for diagnosing and fixing LVM metadata issues but should be used carefully due to its ability to modify critical data. The command provides various options for repairing, dumping, and modifying metadata, as well as for debugging and test operations. It is vital to ensure backups are taken before using repair options, as they can alter the PV’s structure.

Advertisements