Table of Contents
Introduction to pvcreate command
pvcreate command initializes a disk or partition as a physical volume. The physical volumes are used to create a volume group and the LVM logical volumes are created on the volume groups.
Are you new to LVM and still learning how it works?
We have written detailed articles covering different areas of managing logical volumes, which you can follow using the below links:
Manage Logical Volume in Linux - One STOP Solution
Understand LVM Architecture
Create LVM during installation RHEL/CentOS 7/8
How to use LVM Snapshot for Backup and Restore
Create Mirrored Logical Volume
Create Striped Logical Volume
Different examples to use pvcreate command
pvcreate initializes a physical volume on a device. A physical volume can be created using a whole device or partition. An LVM disk label is written to the device, and LVM metadata areas are initialized.
1. pvcreate command to initialize a block device
The following command initializes
/dev/sdc as a physical volume for later use by LVM logical volumes. Initialization is similar to formatting a file system.
# pvcreate /dev/sdc
root@ubuntu-PC:~# pvcreate /dev/sdc Physical volume "/dev/sdb" successfully created.
2. pvcreate command to initialize the partition
You can run the pvcreate command on the partition to initialize partitions rather than whole disks.
The following command initializes the partition
/dev/sdb1 as LVM physical volumes.
# pvcreate /dev/sda1 /dev/sdb1
root@ubuntu-PC:~# pvcreate /dev/sda1 /dev/sdb1 Physical volume "/dev/sda1" successfully created. Physical volume "/dev/sdb1" successfully created.
3. Display physical volumes in the system
There are three commands you can use to display properties of physical volumes:
pvs produces formatted output about physical volumes.
pvdisplay command displays attributes of physical volumes like name, size, physical extent size, space used for the volume group, and so on.
pvscan scan all LVM supported disks for physical volumes and shows them.
You can use
vgcreate command to create a new volume group on one or more physical volumes.
We have written a detailed article on vgcreate command examples in Linux [Cheat Sheet].
4. Force the creation of physical volumes
--force options force the creation of the physical volume without any confirmation.
Normally, you cannot reinitialize the physical volumes belonging to an existing volume group. But with option
-ff, you can override this behaviour and recreate the physical volume.
# pvcreate -ff /dev/sdb1
If you want to remove the physical volume, you can use
root@ubuntu-PC:~# pvremove /dev/sdb1 Labels on physical volume "/dev/sdb1" successfully wiped.
5. Set physical volume size
pvcreate automatically detects the size for the physical volume. You can use
--setphysicalvolumesize option to set your own custom size for the physical volume.
# pvcreate --setphysicalvolumesize SIZE /dev/sdb1
The default unit is megabytes. You can use K for kilobytes, M for megabytes, G for gigabytes, T for terabytes, P for petabytes or E for exabytes.
This tutorial teaches you to create physical volumes and display their properties in the Linux system. If you have any confusion, please let us know in the comment section below.
10+ lvcreate command examples in Linux [Cheat Sheet]
How to PROPERLY use lvextend to increase LV size