5. Configure Local Storage
πRed Hat Certified System Administrator (RHCSA β EX200)
In Linux, Logical Volumes (LVs) are part of the LVM (Logical Volume Manager) system. LVM lets you manage storage more flexibly than traditional partitions. Think of it like creating storage units that can grow, shrink, or move without touching the physical hard drives directly.
Key Terms
- Physical Volume (PV) β This is a physical storage device, like a hard disk or SSD, that LVM can use.
- Volume Group (VG) β Combines one or more PVs into a single storage pool.
- Logical Volume (LV) β A βvirtual partitionβ created from the VG storage pool. Applications use LVs like normal disks.
For this section, you need to create and delete logical volumes.
Step 1: Check Existing Volume Groups
Before creating a logical volume, know what VGs exist and how much space is available.
- Command:
vgs
- Shows all volume groups and their free space.
VG #PV #LV #SN Attr VSize VFree
vg_data 1 2 0 wz--n- 50G 20G
VFreeis the free space in the VG that can be used for new LVs.
Step 2: Create a Logical Volume
The lvcreate command is used to create LVs.
Basic syntax:
lvcreate -L <size> -n <LV_name> <VG_name>
-L= size of the LV (e.g., 10G for 10 GB)-n= logical volume name<VG_name>= the VG where you want to create the LV
Example:
Create a 10 GB LV called lv_app in vg_data:
lvcreate -L 10G -n lv_app vg_data
Verify creation:
lvs
LV VG Attr LSize
lv_app vg_data -wi- 10.00G
- You can also create thin-provisioned LVs, but for the exam, standard LVs are usually enough.
Step 3: Format the Logical Volume
Before using the LV, it must have a filesystem.
- Example (ext4):
mkfs.ext4 /dev/vg_data/lv_app
/dev/<VG_name>/<LV_name>is how LVs are referenced in Linux.
Step 4: Mount the Logical Volume
Once formatted, mount it to use:
mkdir /mnt/app_data
mount /dev/vg_data/lv_app /mnt/app_data
- Now applications or services can store files on
/mnt/app_data. - Optional: Add to
/etc/fstabfor automatic mounting on reboot:
/dev/vg_data/lv_app /mnt/app_data ext4 defaults 0 0
Step 5: Resize a Logical Volume (Extra Exam Tip)
Sometimes you need to grow or shrink LVs.
- Grow LV:
lvextend -L +5G /dev/vg_data/lv_app
resize2fs /dev/vg_data/lv_app
- Shrink LV:
Shrinking is riskier; you must first shrink the filesystem, then the LV:
umount /mnt/app_data
e2fsck -f /dev/vg_data/lv_app
resize2fs /dev/vg_data/lv_app 5G
lvreduce -L 5G /dev/vg_data/lv_app
mount /dev/vg_data/lv_app /mnt/app_data
Step 6: Delete a Logical Volume
If you no longer need an LV, delete it to free space in the VG.
- Unmount the LV first:
umount /mnt/app_data
- Delete LV:
lvremove /dev/vg_data/lv_app
- Confirm deletion when prompted.
- Check using
lvsto make sure itβs gone.
Real IT Environment Use
- Application Storage: An application like a database can use an LV for its data files.
- Temporary Expansion: If a VM needs more disk space, you can grow its LV without changing the underlying physical disk.
- Snapshots: LVs can be snapshotted for backups before applying changes to production applications.
Quick Reference Commands for Exam
| Task | Command |
|---|---|
| List VGs | vgs |
| List LVs | lvs |
| Create LV | lvcreate -L <size> -n <LV_name> <VG_name> |
| Format LV | mkfs.ext4 /dev/<VG>/<LV> |
| Mount LV | mount /dev/<VG>/<LV> <mount_point> |
| Add to fstab | Edit /etc/fstab |
| Extend LV | lvextend -L +<size> /dev/<VG>/<LV> + resize2fs |
| Reduce LV | lvreduce -L <size> /dev/<VG>/<LV> (after resizing filesystem) |
| Delete LV | lvremove /dev/<VG>/<LV> |
β Exam Tips
- Always check free space in VG before creating LVs.
- Remember to format LVs before mounting.
- Deleting an LV is destructive; ensure itβs unmounted first.
- Know how to read output of
lvsandvgs.
