Create and remove physical volumes

5. Configure Local Storage

📘Red Hat Certified System Administrator (RHCSA – EX200)


In Linux, when we manage storage using LVM (Logical Volume Manager), the physical volume (PV) is the starting point. A physical volume is essentially a hard disk, SSD, or partition that is prepared for use by LVM. Think of it as “raw storage space” that LVM can manage.


1. Understanding Physical Volumes

  • Physical Volume (PV): A disk or partition that has been initialized to work with LVM.
  • Why use PVs: LVM allows you to combine multiple disks or partitions into one flexible storage system. PVs are the first step in this process.
  • Commands to manage PVs: Linux provides commands like pvcreate, pvdisplay, pvremove to manage them.

Key point for the exam: You must know how to create, list, and remove PVs.


2. Creating a Physical Volume

To create a physical volume, you use the command:

sudo pvcreate /dev/sdX
  • /dev/sdX → Replace X with the actual disk or partition name.
  • Example:
sudo pvcreate /dev/sdb1

This initializes /dev/sdb1 as a PV for LVM use.

Notes:

  • The disk/partition must not contain any active data because pvcreate will overwrite the LVM metadata.
  • After creation, the disk is ready to be added to a Volume Group (VG).

Verify Physical Volume

After creating a PV, you can check it with:

pvdisplay

This shows details such as:

  • PV Name (disk/partition)
  • Volume Group (VG) it belongs to (if any)
  • Size of the PV
  • Free space

Or a simpler list with:

pvs

Example output of pvs:

PV         VG     Fmt  Attr PSize  PFree
/dev/sdb1 vg01 lvm2 a-- 50.00g 50.00g

This tells you that /dev/sdb1 is a PV in VG vg01 and it has 50 GB free.


3. Removing a Physical Volume

If you want to remove a PV from LVM, you need to make sure it’s not in use (not part of an active Volume Group or Logical Volume).

Steps to remove a PV:

  1. Check if it’s in use:
pvs
  1. Remove it from its Volume Group (if necessary):
vgreduce <VG_NAME> /dev/sdX
  • <VG_NAME> → The Volume Group name
  • /dev/sdX → The PV to remove
  1. Remove the PV metadata:
pvremove /dev/sdX

Example:

sudo pvremove /dev/sdb1

This wipes the LVM metadata from the disk, making it a normal unallocated disk again.


4. Important Exam Notes

  1. Commands you must know:
    • Create PV: pvcreate /dev/sdX
    • List PVs: pvdisplay or pvs
    • Remove PV: pvremove /dev/sdX
  2. Check usage before removal: Always verify that the PV is not part of any active VG or LV using pvs or vgdisplay.
  3. Permissions: Most PV commands require sudo because you are modifying disks.
  4. Disk requirements: The disk/partition must be empty or unmounted. LVM overwrites metadata, so never create PVs on disks with important data.

5. Quick Workflow Example

  1. Create a PV:
sudo pvcreate /dev/sdb1
  1. Verify PV:
pvs
  1. Add PV to Volume Group (for next step in LVM setup):
sudo vgcreate vg01 /dev/sdb1
  1. Later, remove PV from VG:
sudo vgreduce vg01 /dev/sdb1
  1. Remove PV completely:
sudo pvremove /dev/sdb1

Summary:

  • PV = raw storage for LVM
  • Use pvcreate to make it usable by LVM
  • Use pvs or pvdisplay to check PV status
  • Use pvremove to delete it after making sure it’s not in use
Buy Me a Coffee