pvcreate – Initialize a physical hard disk partition as a physical volume

The pvcreate command is used in Linux to initialize a physical hard disk partition as a physical volume for use with LVM (Logical Volume Manager). This command creates a new physical volume on a hard disk partition or a whole disk. Once a physical volume is created, it can be used to create logical volumes, which can then be formatted with a file system and mounted.

Overview

The basic syntax for the pvcreate command is:

pvcreate [options] device

Where device is the name of the partition or whole disk to initialize as a physical volume.

For example, to initialize the partition /dev/sdb1 as a physical volume, run the following command:

sudo pvcreate /dev/sdb1

This will create a new physical volume on the partition /dev/sdb1.

Specific use cases

  • Creating a new physical volume on a partition or whole disk.
  • Adding a new physical volume to an existing volume group.
  • Reinitializing an existing physical volume.

Examples

  1. Initialize a whole disk as a physical volume:
sudo pvcreate /dev/sdb
  1. Initialize a partition as a physical volume and specify the metadata area size:
sudo pvcreate --metadatasize 64M /dev/sdb1
  1. Initialize a partition as a physical volume and specify the physical extent size:
sudo pvcreate --extentsize 16M /dev/sdb1
  1. Initialize a partition as a physical volume and specify the volume group name:
sudo pvcreate --vgname myvg /dev/sdb1

Options

Here are the available options for the pvcreate command:

Option Description
-h, --help Display help message and exit.
-v, --verbose Display verbose output.
-f, --force Force initialization of the physical volume.
-y, --yes Answer yes to all questions.
-M, --major Set the device’s major number.
-m, --metadatacopies Set the number of metadata copies.
-s, --metadatasize Set the size of the metadata area.
-e, --extentsize Set the size of physical extents.
-n, --name Set the name of the physical volume.
-u, --uuid Set the UUID of the physical volume.
-y, --yes Answer yes to all questions.
-v, --verbose Display verbose output.
-Z, --zero Fill the first few kilobytes with zeros.
-y, --yes Answer yes to all questions.

Troubleshooting tips

  • If the pvcreate command fails with an error message indicating that the device is in use, make sure that the device is not currently mounted or being used by another application.
  • If the pvcreate command fails with an error message indicating that the device is read-only, make sure that the device is not write-protected or damaged.

Notes

  • The pvcreate command must be run with root privileges or using the sudo command.
  • Once a physical volume is created, it can be added to an existing volume group using the vgextend command.
  • To remove a physical volume, use the pvremove command.