QUICK START:HTMLCSSJavaScriptTypeScriptPythonSQLReactNext.jsNode.jsLinux & UbuntuKotlinSwiftC# / .NETJavaGoRustC++DSASystem DesignDevOpsCybersecurityAI / ML
Intermediate 22 min readModule: Module 8: Storage, Partitioning, LVM & Filesystems

Block Devices, Filesystems & Logical Volume Manager (LVM)

Understand block devices (lsblk), partitioning with GPT, creating Ext4/XFS filesystems, persistent mounts via /etc/fstab, and dynamically scaling storage with LVM.

What You Will Learn in This Lesson

  • Inspecting block devices, NVMe/SATA drives, and partitions using lsblk and blkid
  • Formatting partitions with Ext4 and XFS filesystems using mkfs
  • Configuring persistent filesystem mounts with UUIDs in /etc/fstab
  • Managing Logical Volume Manager (LVM): Physical Volumes (PV), Volume Groups (VG), Logical Volumes (LV)

Introduction & Core Concept

Linux interacts with raw storage drives (NVMe, SSDs, virtual cloud disks) as Block Devices (/dev/nvme0n1, /dev/sda). To store files, block devices are partitioned (GPT/MBR), formatted with a Filesystem (Ext4, XFS), and mounted into the directory tree. Logical Volume Manager (LVM) introduces a virtualization layer that allows disks to be pooled and resized on the fly without unmounting filesystems.
WHY DOES THIS MATTER IN THE REAL WORLD?

In production cloud environments, database volumes and log partitions frequently run out of space. Understanding persistent UUID mounts in /etc/fstab and dynamic online volume expansion with LVM (lvextend, resize2fs) prevents system downtime.

Syntax & Structure

bash
lsblk -f
mkfs.ext4 /dev/sdb1
mount /dev/sdb1 /mnt/data
pvcreate /dev/sdb
vgcreate data_vg /dev/sdb
lvcreate -n data_lv -L 50G data_vg

Dynamic Storage Expansion with Logical Volume Manager (LVM)

bash
bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
# LVM (Logical Volume Manager) Administration Commands
echo "=== 1. Inspecting Block Storage Hierarchy ==="
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT
echo -e "
=== 2. Creating LVM Structure ==="
# Step 1: Initialize Physical Volume (PV)
# sudo pvcreate /dev/sdb
# Step 2: Create Volume Group (VG)
# sudo vgcreate app_vg /dev/sdb
# Step 3: Create Logical Volume (LV)
# sudo lvcreate -n data_lv -L 20G app_vg
# Step 4: Format with Ext4 filesystem
# sudo mkfs.ext4 /dev/app_vg/data_lv
# Step 5: Mount to directory
# sudo mkdir -p /var/data
# sudo mount /dev/app_vg/data_lv /var/data
echo -e "
=== 3. Online Storage Expansion (Zero Downtime) ==="
# Extend Logical Volume by +10GB and grow Ext4 filesystem simultaneously
# sudo lvextend -L +10G /dev/app_vg/data_lv -r
echo "LVM allows online volume extension without unmounting active filesystems."

Line-by-Line Technical Breakdown

1/etc/fstab Rules: Every entry in /etc/fstab consists of 6 fields: `<file system (UUID)> <mount point> <type> <options> <dump> <pass>`. Always mount by persistent UUID (e.g. `UUID=...`) rather than device names (`/dev/sda1`) because device letters can change during reboot.

Try It Yourself (Interactive Editor)

Modify the code in real-time and click Run to test live browser output and console logs.

Intelligent Code Runner & Live Sandbox[BASH]
BASH SOURCE EDITOR
Interactive Live Code

Common Mistakes & How to Avoid Them

#1: Using device names like /dev/sdb1 in /etc/fstab instead of unique UUIDs.

Device names like /dev/sdb1 can change order if drives are attached or detached in cloud providers, causing boot failures.

Incorrect / Antipattern
/dev/sdb1 /mnt/data ext4 defaults 0 2
Correct / Professional Solution
UUID=3a7f8e12-4c5b-4890-8812-789a4b2c1234 /mnt/data ext4 defaults 0 2

Industry Best Practices & Professional Standards

  • Always use `blkid` to find partition UUIDs and mount with UUID in /etc/fstab.
  • Use LVM for database and container storage partitions to allow zero-downtime volume resizing.
  • Run `sudo mount -a` after editing /etc/fstab to verify syntax before rebooting.

Lesson Summary & Core Takeaways

  • Storage workflow: Block Device → Partition → Filesystem → Mount Point.
  • LVM introduces PVs, VGs, and LVs for dynamic on-the-fly volume resizing.
  • Always use persistent filesystem UUIDs in /etc/fstab.