6. Create and Configure File Systems
πRed Hat Certified System Administrator (RHCSA β EX200)
In Linux, Logical Volumes (LVs) are flexible storage units that sit on top of Volume Groups (VGs), which in turn sit on Physical Volumes (PVs). Sometimes, a logical volume may run out of space. Instead of creating a new disk or partition, Linux allows you to extend the size of an existing logical volume dynamically.
This is a common task in IT environments, for example:
- Expanding storage for a database that is running out of space.
- Increasing disk space for virtual machines in a virtualization environment.
- Adding space to a home directory on a server.
1. Check Current Logical Volume Status
Before extending an LV, you need to know:
- The name of the logical volume.
- Its size.
- The free space available in the Volume Group.
Commands to use:
# List all logical volumes
sudo lvdisplay# Check free space in the volume group
sudo vgdisplay
Key points to note:
LV Nameβ the name of the logical volume you want to extend.VG Nameβ the volume group that contains the LV.Free PE / Sizeβ how much free space is available in the volume group. You cannot extend beyond this.
2. Extend the Logical Volume
You can extend an LV using either absolute size or by adding a certain amount of space.
Option A: Extend by Size
To add a specific size (for example, 10 GB):
sudo lvextend -L +10G /dev/<VG_Name>/<LV_Name>
-L +10Gβ adds 10 GB to the existing size./dev/<VG_Name>/<LV_Name>β the path to the logical volume.
Option B: Extend to Maximum Available Space
To use all free space in the volume group:
sudo lvextend -l +100%FREE /dev/<VG_Name>/<LV_Name>
-l +100%FREEβ adds all remaining free extents in the volume group to the LV.
3. Resize the Filesystem
After extending the LV, the filesystem on it must also be resized so the OS can use the new space.
The command depends on the filesystem type:
A. Ext4 Filesystem
sudo resize2fs /dev/<VG_Name>/<LV_Name>
B. XFS Filesystem
sudo xfs_growfs /mount/point
- For XFS, you specify the mount point, not the device path.
- You can extend mounted filesystems online without unmounting, which is useful for servers.
4. Verify the Extension
After extending the LV and filesystem, confirm that the new size is reflected:
# Check LV size
sudo lvdisplay /dev/<VG_Name>/<LV_Name># Check filesystem size
df -h
Example Output:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg1-lv1 30G 15G 15G 50% /data
5. Important Exam Points
- Command Options:
lvextend -L +sizeβ add specific size.lvextend -l +100%FREEβ use all free space.resize2fsβ for ext4.xfs_growfsβ for XFS.
- Order of Operations:
- Check LV and VG sizes.
- Extend the LV.
- Resize the filesystem.
- Verify changes.
- You can extend mounted filesystems, especially XFS, which is common in modern Linux servers.
- Cannot exceed the free space in the volume group.
- Always check disk space and free extents before extending.
6. IT Environment Examples
- Database Server: A MySQL database is filling up
/var/lib/mysql. Admin extends the LV to prevent downtime. - VM Storage: A virtual machineβs logical disk grows in VMware or KVM. LV is extended so the VM can store more data.
- Shared Network Storage: Fileserver
/dataLV extended when team project files grow.
7. Quick Summary Table
| Step | Command Example | Notes |
|---|---|---|
| Check LV | lvdisplay | See LV size |
| Check VG free space | vgdisplay | See available space |
| Extend LV by 10GB | lvextend -L +10G /dev/vg1/lv1 | Add specific size |
| Extend LV to all free space | lvextend -l +100%FREE /dev/vg1/lv1 | Use max space |
| Resize ext4 FS | resize2fs /dev/vg1/lv1 | Must do after LV extension |
| Resize XFS FS | xfs_growfs /data | Specify mount point |
| Verify | df -h | Confirm new space |
β
Exam Tip:
The exam may ask you to extend a logical volume and its filesystem. Remember, extending the LV alone does not automatically give you more usable spaceβyou must also resize the filesystem.
