Assign physical volumes to volume groups

5. Configure Local Storage

πŸ“˜Red Hat Certified System Administrator (RHCSA – EX200)


In Linux, when you work with storage, Logical Volume Management (LVM) lets you manage disk storage more flexibly. There are three key layers:

  1. Physical Volume (PV) – A real storage device or partition.
  2. Volume Group (VG) – A pool of storage made by combining one or more PVs.
  3. Logical Volume (LV) – The storage you actually use, carved out from VGs.

In this section, we focus on how to assign physical volumes to volume groups.


Step 1: Understand the components

  1. Physical Volume (PV)
    • A PV is a disk or partition you prepare for LVM.
    • You β€œinitialize” a disk as a PV using the pvcreate command.
    • Example: sudo pvcreate /dev/sdb
      sudo pvcreate /dev/sdc
  2. Volume Group (VG)
    • A VG is a collection of PVs. Think of it as a storage pool.
    • You create a VG using the vgcreate command and assign PVs to it.

Step 2: Create a Volume Group (VG) with PVs

When you assign PVs to a VG, you combine the storage space of multiple disks. This makes management easier and more flexible.

Command syntax:

sudo vgcreate <VG_NAME> <PV1> <PV2> ...

Example:
You have two PVs /dev/sdb and /dev/sdc. You want to create a VG called data_vg.

sudo vgcreate data_vg /dev/sdb /dev/sdc
  • data_vg is the volume group name.
  • /dev/sdb and /dev/sdc are the PVs being added.
  • After this, the VG will show total space as the sum of the PVs.

Check the result:

sudo vgdisplay data_vg

This shows:

  • Total physical volumes in the VG
  • Total space available
  • Free space

Step 3: Add more PVs to an existing VG

Sometimes, you need more storage. You can assign additional PVs to an existing VG using vgextend.

Command syntax:

sudo vgextend <VG_NAME> <NEW_PV>

Example:

sudo vgextend data_vg /dev/sdd
  • /dev/sdd is a new physical volume added to the data_vg volume group.
  • The total storage in the VG now increases.

Check updated VG:

sudo vgdisplay data_vg

You’ll see the new total space.


Step 4: Removing PVs from a VG (Optional but Exam Relevant)

If a PV is no longer needed in a VG, you can remove it using vgreduce.

Example:

sudo vgreduce data_vg /dev/sdc
  • This removes /dev/sdc from data_vg.
  • Important: The PV must not contain data in logical volumes; otherwise, the system will prevent removal.

Check:

sudo vgdisplay data_vg

Step 5: Key Exam Notes

  1. Commands to remember:
    • pvcreate – Initialize a physical volume.
    • vgcreate – Create a volume group with PVs.
    • vgextend – Add PVs to an existing VG.
    • vgreduce – Remove PVs from a VG.
    • vgdisplay – Show details of the volume group.
  2. VG concept:
    • A VG combines multiple PVs into a single storage pool.
    • Storage from a VG can later be divided into Logical Volumes (LVs) for actual use.
  3. Why it’s important for the exam:
    • The exam may ask you to create a VG with specific PVs, or add/remove PVs from a VG.
    • You should understand how PVs combine into VGs and how to check space.

Step 6: Visual Representation (Simplified)

PV: /dev/sdb  ----\
PV: /dev/sdc -----> VG: data_vg ---> Logical Volumes (LVs)
PV: /dev/sdd ----/
  • PVs are the raw storage.
  • VG pools them.
  • LVs are slices you actually use.

Step 7: Quick Example Scenario

  • You have 3 new disks: /dev/sdb, /dev/sdc, /dev/sdd.
  • Exam task: Create a VG called project_vg using /dev/sdb and /dev/sdc. Then add /dev/sdd to the VG.

Commands:

sudo pvcreate /dev/sdb /dev/sdc /dev/sdd
sudo vgcreate project_vg /dev/sdb /dev/sdc
sudo vgextend project_vg /dev/sdd
sudo vgdisplay project_vg

βœ… That’s everything you need for assigning PVs to VGs for the exam. The key is to know the commands and their purpose, and understand that VGs are pools of PVs.

Buy Me a Coffee