LVM Physical Volumes
A physical volume (pv) is any block device (a disk, a partition, a RAID device, an iSCSI device, etc.). All these devices can become a member of a volume group.
The commands used to manage a physical volume start with pv:
pvchange pvck pvcreate pvresize pvs pvscan pvdisplay pvmove pvremove
pvcreate command to add devices to lvm. This example shows how to add a disk to lvm.
# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created
This example shows how to add a partition to lvm.
# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created
You can also add multiple disks or partitions as target to
pvcreate. This example adds three disks to lvm:
# pvcreate /dev/sde /dev/sdf /dev/sdg Physical volume "/dev/sde" successfully created Physical volume "/dev/sdf" successfully created Physical volume "/dev/sdg" successfully created
pvremove command to remove physical volumes from lvm. The devices may not be in use.
# pvremove /dev/sdc Labels on physical volume "/dev/sdc" successfully wiped
You can also remove multiple disks using the
pvremove command. This example removes three disks from lvm:
# pvremove /dev/sde /dev/sdf /dev/sdg Labels on physical volume "/dev/sde" successfully wiped Labels on physical volume "/dev/sdf" successfully wiped Labels on physical volume "/dev/sdg" successfully wiped
When you used
fdisk to resize a partition on a disk, then you must use
pvresize to make lvm recognize the new size of the physical volume that represents this partition:
# pvresize /dev/sdc1 Physical volume "/dev/sdc1" changed 1 physical volume(s) resized / 0 physical volume(s) not resized
pvchange you can prevent the allocation of a Physical Volume in a new Volume Group or Logical Volume. This can be useful if you plan to remove a Physical Volume:
# pvchange -xn /dev/sde Physical volume "/dev/sde" changed 1 physical volume changed / 0 physical volumes not changed
To revert your previous decision, this example shows you how te re-enable the Physical Volume to allow allocation:
# pvchange -xy /dev/sde Physical volume "/dev/sde" changed 1 physical volume changed / 0 physical volumes not changed
pvmove you can move Logical Volumes from within a Volume Group to another Physical Volume. This must be done before removing a Physical Volume.
# pvmove /dev/sdg Moved: 21.4% Moved: 54.8% Moved: 70.1% Moved: 100.0%
The easiest way to verify whether devices are known to lvm is with the
# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vg30 lvm2 a- 15.88G 0 /dev/sdb lvm2 -- 409.60M 409.60M /dev/sdc vg33 lvm2 a- 408.00M 408.00M /dev/sdd vg33 lvm2 a- 408.00M 408.00M
The above example shows that only /dev/sda2 is currently known for use with LVM. It shows that /dev/sda2 is part of vg30 and is almost 16GB in size. It also shows /dev/sdc and / dev/sdd as part of vg33. The device /dev/sdb is known to lvm, but not linked to any Volume Group.
pvscan command will scan all disks for existing Physical Volumes. The information is similar to
pvs, plus you get a line with total sizes.
# pvscan PV /dev/sdc VG vg33 lvm2 [408.00 MB / 408.00 MB free] PV /dev/sdd VG vg33 lvm2 [408.00 MB / 408.00 MB free] PV /dev/sda2 VG vg30 lvm2 [15.88 GB / 0 free] PV /dev/sdb lvm2 [409.60 MB] Total: 4 [17.07 GB] / in use: 3 [16.67 GB] / in no VG: 1 [409.60 MB]
pvdisplay to get more information about physical volumes:
# pvdisplay /dev/sda2 --- Physical volume --- PV Name /dev/sda2 VG Name vg30 PV Size 15.90 GB / not usable 20.79 MB Allocatable yes (but full) PE Size (KByte) 32768 Total PE 508 Free PE 0 Allocated PE 508 PV UUID 2bb9351c-d23e-479d-9818-eb2771cc10ce
You can also use
pvdisplay without an argument to display information about all physical (lvm) volumes.