📌 Introduction
In Day 5 of our Linux Administration series, we focus on one of the most important responsibilities of a system administrator — Disk Management.
We will cover:
File system types
Essential disk commands
Traditional partitioning using
fdiskModern disk management using LVM
Creating, extending & removing LVM
Migrating data using
pvmoveResizing disk in AWS Cloud
Let’s begin 🚀
📂 1️⃣ Types of File Systems in Linux
Common file systems used in enterprise environments:
| File System | Usage |
|---|---|
| ext4 | Default in many Linux systems |
| xfs | Default in RHEL / Rocky |
| vfat | USB drives |
| nfs | Network storage |
| cifs | Windows share |
Check filesystem type:
lsblk -f
📊 2️⃣ Essential Disk Management Commands
🔹 Check Disk Space
df -h
🔹 Check Directory Size
du -h
🔹 Identify Large Directories
du -h --max-depth=1 | sort -hr
🔹 Check Inode Usage
df -i
🔹 List Block Devices
lsblk
🧱 3️⃣ Traditional Partitioning – fdisk
Before LVM, Linux used fdisk for partition management.
Create a Partition:
fdisk /dev/sdb
Steps:
Press
n→ new partitionPress
p→ primaryAccept defaults
Press
w→ write changes
Create filesystem:
mkfs.ext4 /dev/sdb1
Mount:
mount /dev/sdb1 /mnt
⚠ Limitation: Cannot easily resize partitions.
🚀 4️⃣ What is LVM?
LVM (Logical Volume Manager) provides:
✔ Flexible disk management
✔ Easy resizing
✔ Storage pooling
✔ Snapshot support
✔ Data migration
LVM Architecture
Physical Volume (PV)
↓
Volume Group (VG)
↓
Logical Volume (LV)
↓
Filesystem
↓
Mount Point
🛠 5️⃣ Create LVM Step-by-Step
🔹 Step 1: Create Physical Volume
pvcreate /dev/sdb
pvdisplay
🔹 Step 2: Create Volume Group
vgcreate vg01 /dev/sdb
vgdisplay vg01
🔹 Step 3: Create Logical Volumes
lvcreate -L 1G -n lv_ext4 vg01
lvcreate -L 1G -n lv_xfs vg01
Check:
lvdisplay
🔹 Step 4: Create File System
mkfs.ext4 /dev/vg01/lv_ext4
mkfs.xfs /dev/vg01/lv_xfs
🔹 Step 5: Mount Logical Volumes
mkdir /lvm_ext4
mkdir /lvm_xfs
mount /dev/vg01/lv_ext4 /lvm_ext4
mount /dev/vg01/lv_xfs /lvm_xfs
Verify:
df -h
🔹 Step 6: Make Persistent (fstab)
Edit:
vi /etc/fstab
Add:
/dev/vg01/lv_ext4 /lvm_ext4 ext4 defaults 0 0
/dev/vg01/lv_xfs /lvm_xfs xfs defaults 0 0
Test:
mount -a
📈 6️⃣ Extend LVM Volume
Add New Disk
pvcreate /dev/sdc
vgextend vg01 /dev/sdc
Extend Logical Volume
lvextend -L +1G /dev/vg01/lv_ext4
Resize Filesystem
For ext4:
resize2fs /dev/vg01/lv_ext4
For XFS:
xfs_growfs /lvm_xfs
Check:
df -h
🔄 7️⃣ Migrate Data Using pvmove
Used when replacing old disk.
pvcreate /dev/sdd
vgextend vg01 /dev/sdd
pvmove /dev/sdc /dev/sdd
vgreduce vg01 /dev/sdc
pvremove /dev/sdc
Monitor migration:
lvs -a -o +devices
🗑 8️⃣ Decommission LVM
umount /lvm_ext4
lvremove /dev/vg01/lv_ext4
vgremove vg01
pvremove /dev/sdb
☁ 9️⃣ Resize Disk in AWS
Steps:
Increase EBS volume from AWS console
Check disk:
lsblk
Extend partition:
growpart /dev/xvda 1
Resize filesystem:
For ext4:
resize2fs /dev/xvda1
For XFS:
xfs_growfs -d /
🔥 Troubleshooting Section
❌ Mount Fails
blkid
cat /etc/fstab
❌ LV Remove Fails (Device Busy)
lsof | grep mountpoint
❌ Filesystem Not Expanding
Check:
lsblk
lvdisplay
🎤 Interview Questions
Difference between fdisk and LVM?
Can XFS be reduced?
What is PE size?
What happens if PV disk fails?
How to check which disk LV uses?
📌 Conclusion
Today we learned:
✔ Disk management basics
✔ fdisk partitioning
✔ LVM architecture
✔ Create, extend & remove LVM
✔ Data migration
✔ Cloud disk resizing
LVM is the backbone of modern Linux storage management in enterprise environments.
No comments:
Post a Comment