TrumanWong

pvcreate

Initialize physical hard disk partition into physical volume

Supplementary instructions

pvcreate command is used to initialize the physical hard disk partition into a physical volume for use by LVM.

grammar

pvcreate(options)(parameters)

Options

-f: Forces the creation of physical volumes without user confirmation;
-u: UUID of the specified device;
-y: Answer "yes" to all questions;
-Z: Whether to use the first 4 sectors.

Parameters

Physical volume: Specify the device file name corresponding to the physical volume to be created.

Example

View disk information:

[root@localhost ~]# fdisk -l
Disk /dev/hda: 41.1 GB, 41174138880 bytes
255 heads, 63 sectors/track, 5005 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 1288 10241437+ 83 Linux
/dev/hda3 1289 1925 5116702+ 83 Linux
/dev/hda4 1926 5005 24740100 5 Extended
/dev/hda5 1926 2052 1020096 82 Linux swap / Solaris
/dev/hda6 2053 2235 1469916 8e Linux LVM
/dev/hda7 2236 2418 1469916 8e Linux LVM
/dev/hda8 2419 2601 1469916 8e Linux LVM
/dev/hda9 2602 2784 1469916 8e Linux LVM

Check if there are PVs on the system, then create /dev/hda6 to /dev/hda9 into PV format

[root@localhost ~]# pvscan
No matching physical volumes found #No PV found!

Convert partitions 6-9 to pv, pay attention to the use of curly brackets:

[root@localhost ~]# pvcreate /dev/hda{6,7,8,9}
   Physical volume "/dev/hda6" successfully created
   Physical volume "/dev/hda7" successfully created
   Physical volume "/dev/hda8" successfully created
   Physical volume "/dev/hda9" successfully created

This represents the information of each PV and the information of all PVs in the system respectively:

[root@localhost ~]# pvscan
   PV /dev/hda6 lvm2 [1.40 GB]
   PV /dev/hda7 lvm2 [1.40 GB]
   PV /dev/hda8 lvm2 [1.40 GB]
   PV /dev/hda9 lvm2 [1.40 GB]
   Total: 4 [5.61 GB] / in use: 0 [0 ] / in no VG: 4 [5.61 GB]

A more detailed list shows each PV information on the system:

[root@localhost ~]# pvdisplay
   "/dev/hda6" is a new physical volume of "1.40 GB"
   --- NEW Physical volume ---
   PV Name /dev/hda6 #Actual partition partition name
   VG Name #Because it has not been assigned yet, it is blank!
   PV Size 1.40 GB # is the capacity description
   Allocatable NO #Whether it has been allocated, the result is NO
   PE Size (KByte) 0 #PE size in this PV
   Total PE 0 #Several PEs are divided in total
   free PE 0 #PE not used by LV
   Allocated PE 0 #The number of PEs that can still be allocated
   PV UUID Z13Jk5-RCls-UJ8B-HzDa-Gesn-atku-rf2biN
....(omitted below)....

Delete a physical volume:

[root@localhost ~]# pvremove /dev/sdb2
Labels on physical volume "/dev/sdb2" successfully wiped

Modify physical volume attributes:

[root@localhost ~]# pvchange -x n /dev/sdb1 #Prohibit allocation of PE on the specified physical volume
Physical volume "/dev/sdb1" changed
1 physical volume changed / 0 physical volume not changed