Click on each book below to review & buy on Amazon.
As an Amazon Associate, I earn from qualifying purchases.
RHCSA - Configure Local Storage: Assign Physical Volumes to Volume Groups
Volume groups are a fundamental concept used to manage storage space efficiently. A volume group is a collection of physical volumes, which are typically individual hard drives or partitions, combined together to form a unified pool of storage. Once these physical volumes are added to a volume group, they can be divided into logical volumes, which are analogous to partitions but offer greater flexibility.
Lesson Setup
To actively participate in the exercises, make sure to attach an additional empty disk to your system. While the exercises assume that the additional disk is 1G in size, feel free to use whatever disk size is available to you.
Do not use a disk with data on as following the exercises will mean that data will be deleted.
Once the disk is attached, you should be able to see it by running the lsblk
command, which in this example shows as the sdb
device:
After rebooting, the disk may not retain the same device name, making it essential to always run lsblk
to verify that you are working with the correct disk.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 600M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 17G 0 part
├─os_vg-root 253:0 0 15G 0 lvm /
└─os_vg-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
You will now need to create four partitions on the /dev/sdb
device so that you can practice assigning and removing physical volumes from volume groups.
Wipe the /dev/sdb
disk clean if it has been used in previous lesson:
sudo wipefs --all /dev/sdb*
sudo sed -i '/\/dev\/sdb/d' /etc/lvm/devices/system.devices
Create four 100MB partition on disks /dev/sdb
:
sudo parted -s /dev/sdb mklabel gpt mkpart ext4 0MB 100MB
sudo parted -s /dev/sdb mkpart ext4 100MB 200MB
sudo parted -s /dev/sdb mkpart ext4 200MB 300MB
sudo parted -s /dev/sdb mkpart ext4 300MB 400MB
Confirm the partitions exist:
lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 0 1G 0 disk
├─sdb1 8:17 0 95.4M 0 part
├─sdb2 8:18 0 95.4M 0 part
├─sdb3 8:19 0 95M 0 part
└─sdb4 8:20 0 95M 0 part
Assigning Physical Volumes to Volume Group
In the previous lesson you learned how to create a physical volume using the pvcreate
command, however you can skip this step as when you add partitions or disks to a volume group, that command gets run in the background anyway. The exercises below will show this happening.
The vgcreate
and vgextend
commands are used to add physical volumes to volume groups.
A volume group must have at least one physical volume present, therefore when creating a volume group with vgcreate
, at least one physical volume is specified.
Create a new volume group call redhat_vg
, with one partition added (/dev/sdb1
):
sudo vgcreate redhat_vg /dev/sdb1
Note the output confirms the physical volume was created:
Physical volume "/dev/sdb1" successfully created.
Volume group "redhat_vg" successfully created
Confirm the volume group was created as expected using vgs
:
sudo vgs
The 1
in the PV
column indicates the volume group only has 1 physical volume within it:
VG #PV #LV #SN Attr VSize VFree
redhat_vg 1 0 0 wz--n- 92.00m 92.00m
Create a new volume group call linux_vg
, with two partitions added (/dev/sdb2
& /dev/sdb3
):
sudo vgcreate linux_vg /dev/sdb2 /dev/sdb3
Physical volume "/dev/sdb2" successfully created.
Physical volume "/dev/sdb3" successfully created.
Volume group "linux_vg" successfully created
Confirm the volume group was created as expected using pvs
:
sudo pvs
Using the pvs
command is useful in determining which physical volumes are assigned to a volume group. In our case it confirms linux_vg
was created with the two physical volumes we specified:
PV VG Fmt Attr PSize PFree
/dev/sdb1 redhat_vg lvm2 a-- 92.00m 92.00m
/dev/sdb2 linux_vg lvm2 a-- 92.00m 92.00m
/dev/sdb3 linux_vg lvm2 a-- 92.00m 92.00m
Add physical volume /dev/sdb4
to the exiting volume group redhat_vg
:
sudo vgextend redhat_vg /dev/sdb4
Physical volume "/dev/sdb4" successfully created.
Volume group "redhat_vg" successfully extended
Confirm that volume group redhat_vg
now has two physical volumes present:
sudo vgdisplay -C -o pv_name,vg_name redhat_vg
Removing Physical Volumes From Volume Groups
vgremove
and vgreduce
are the commands used to remove physical volumes from volume groups. vgreduce
is used when you want to detach a physical volume from a volume group, and in doing so the volume group will not be left empty. vgremove
is used to delete a volume group, leaving any physical volumes it once contained now unassigned to a volume group.
Remove /dev/sdb4
from volume group redhat_vg
:
sudo vgreduce redhat_vg /dev/sdb4
Removed "/dev/sdb4" from volume group "redhat_vg"
Confirm volume group no longer contains physical volume /dev/sdb4
:
sudo pvs /dev/sdb4
VG column shows as empty, meaning it is not assigned to a volume group:
PV VG Fmt Attr PSize PFree
/dev/sdb4 lvm2 --- 95.00m 95.00m
Delete volume group linux_vg
which will free up physical volumes /dev/sdb2
& /dev/sdb3
. Also delete redhat_vg
which will free up /dev/sdb1
:
sudo vgremove linux_vg
Volume group "linux_vg" successfully removed
sudo vgremove redhat_vg
Volume group "redhat_vg" successfully removed
Confirm physical volumes /dev/sdb
, /dev/sdb2
and /dev/sdb3
are unassigned to a volume group:
sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 95.35m 95.35m
/dev/sdb2 lvm2 --- <95.37m <95.37m
/dev/sdb3 lvm2 --- 95.00m 95.00m
/dev/sdb4 lvm2 --- 95.00m 95.00m
Support DTV Linux
Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.
NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.