The first step in creating an LVM is to take existing physical devices and convert them into physical volumes (PVs). This is accomplished by executing the pvcreate command. For example, if you have a hard drive partition /dev/sdb2 and you want to make it a PV, you can execute the following command:
# pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created
After creating it, you can use pvdisplay /dev/sdb2 to show the properties of the physical volume that you’ve just created.
# pvdisplay /dev/sdb2 --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 7.06 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID MH3Nlh-TR27-tPmk-5lWi-jZrH-NKwb-rBN3WY
The pvdisplay command shows information about the different properties of the physical volume:
- PV Name: The name of the physical volume.
- VG Name: The name of the volume group, if any, that is already using this physical volume.
- PV Size: The size of the physical volume.
- Allocatable: Indicator of whether this physical volume is usable or not.
- PE Size: The size of the physical extents. Physical extents are the building blocks of physical volumes, as blocks are the building blocks on a computer hard drive.
- Total PE: The total number of physical extents that is available.
- Free PE: The number of physical extents that is still unused.
- Allocated PE: The number of physical extents that is already in use.
- PV UUID: A random generated unique ID for the physical volume.
pvcreate Command Examples
1. To create a physical volume out of partition or drive:
# pvcreate /dev/sda
2. To forcefully create the physical volume:
# pvcreate -f /dev/sda1 # pvcreate --force /dev/sda1
3. To Specify the uuid for the device:
# pvcreate -u e24b38c3-d57e-4903-b6dd-d002c5a8fd0f # pvcreate --uuid e24b38c3-d57e-4903-b6dd-d002c5a8fd0f
4. To answer yes to all questions:
# pvcreate -y /dev/sda1
5. To specify if the first 4 sectors of device should be wiped or not:
# pvcreate -Z y # pvcreate --zero y
6. To specify the amount space to be set aside for metadata:
# pvcreate --metadatasize
7. To Align the start of the data to a multiple of this number:
# pvcreate --dataalignment 4
8. To specify the number of metadata areas to set aside on each PV:
# pvcreate --[pv]metadatacopies 2
9. To ignore or un-ignore metadata areas on this physical volume:
# pvcreate --metadataignore y
10. To extracts the location and size of the data on the PV from the file:
# pvcreate --restorefile file
11. To allows a uuid to be specified without also requiring that a backup of the metadata be provided:
# pvcreate --norestorefile
12. To different sector near the start of the disk to label the PV:
# pvcreate --labelsector sector
13. To overrides the automatically-detected size of the PV:
# pvcreate --setphysicalvolumesize size