Linux Disk Management: Partitions, Filesystems, and LVM
Storage management is one of the most critical responsibilities of a Linux system administrator. From partitioning raw disks to managing logical volumes that can be resized on the fly, from choosing the right filesystem to ensuring mounts persist across reboots, disk management skills directly impact data integrity and system availability. This guide covers the essential tools and concepts.
Part of the Linux System Administration guide. See also: File Permissions | Boot Process
Viewing Disk Information
Before making any changes, always survey your current disk layout.
lsblk: Block Device Listing
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 500G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 499G 0 part
│ ├─vg_root-lv_root 253:0 0 100G 0 lvm /
│ ├─vg_root-lv_swap 253:1 0 16G 0 lvm [SWAP]
│ └─vg_root-lv_data 253:2 0 383G 0 lvm /data
sdb 8:16 0 1T 0 disk
└─sdb1 8:17 0 1T 0 part /backup
lsblk shows the hierarchy of disks, partitions, and logical volumes with their sizes and mount points. Add -f to see filesystem types and UUIDs.
df and du: Space Usage
# Show filesystem disk space usage (human-readable)
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_root-lv_root 100G 45G 55G 45% /
/dev/sda1 1.0G 250M 750M 25% /boot
/dev/mapper/vg_root-lv_data 383G 210G 173G 55% /data
# Show directory sizes
du -sh /var/log/*
du -sh /home/* | sort -rh | head -10
# Find the largest directories consuming space
du -h --max-depth=2 /var | sort -rh | head -20
Partitioning Disks
fdisk: MBR Partitioning
fdisk is the traditional partitioning tool, best suited for MBR (Master Boot Record) partition tables. MBR supports disks up to 2 TB and a maximum of four primary partitions.
# List partitions on a disk
fdisk -l /dev/sdb
# Interactive partitioning
fdisk /dev/sdb
# Common commands within fdisk:
# n - create new partition
# d - delete a partition
# p - print partition table
# t - change partition type
# w - write changes and exit
# q - quit without saving
parted: GPT Partitioning
parted supports both MBR and GPT (GUID Partition Table). GPT is required for disks larger than 2 TB and supports up to 128 partitions by default. Use parted for modern systems, especially those with UEFI firmware.
# Create a GPT partition table and a single partition
parted /dev/sdc mklabel gpt
parted /dev/sdc mkpart primary ext4 0% 100%
# Interactive mode
parted /dev/sdc
(parted) print
(parted) mkpart primary xfs 0% 50%
(parted) mkpart primary ext4 50% 100%
(parted) quit
Logical Volume Management (LVM)
LVM adds a layer of abstraction between physical disks and filesystems, enabling dynamic resizing, snapshots, and spanning volumes across multiple disks. LVM uses three layers: Physical Volumes (PV), Volume Groups (VG), and Logical Volumes (LV).
Creating LVM Volumes
# Step 1: Create physical volumes on partitions or whole disks
pvcreate /dev/sdc1
pvcreate /dev/sdd1
# Step 2: Create a volume group from one or more PVs
vgcreate vg_data /dev/sdc1 /dev/sdd1
# Step 3: Create logical volumes within the VG
lvcreate -n lv_databases -L 200G vg_data
lvcreate -n lv_logs -L 100G vg_data
lvcreate -n lv_backups -l 100%FREE vg_data
# Step 4: Create filesystems on the logical volumes
mkfs.xfs /dev/vg_data/lv_databases
mkfs.ext4 /dev/vg_data/lv_logs
Extending LVM Volumes
One of LVM's greatest strengths is the ability to resize volumes without downtime (for filesystems that support online resizing):
# Extend a logical volume by 50G
lvextend -L +50G /dev/vg_data/lv_databases
# Resize the filesystem to use the new space
# For XFS (online resize only, cannot shrink):
xfs_growfs /dev/vg_data/lv_databases
# For ext4 (online resize supported):
resize2fs /dev/vg_data/lv_logs
# Or combine both steps:
lvextend -L +50G --resizefs /dev/vg_data/lv_databases
# Add a new disk to an existing volume group
pvcreate /dev/sde1
vgextend vg_data /dev/sde1
LVM Inspection Commands
# Show physical volumes
pvs
pvdisplay
# Show volume groups
vgs
vgdisplay
# Show logical volumes
lvs
lvdisplay
Filesystems: ext4 vs XFS vs Btrfs
Choosing the right filesystem depends on your workload and requirements.
ext4
The default filesystem on many distributions. Mature, stable, and well-understood. Supports volumes up to 1 EB and files up to 16 TB. Supports both online and offline resizing (including shrinking). Good general-purpose choice.
mkfs.ext4 /dev/vg_data/lv_general
# Tune parameters
tune2fs -m 1 /dev/vg_data/lv_general # Reserve 1% for root instead of 5%
XFS
The default on RHEL/CentOS systems. Excellent performance for large files and parallel I/O workloads. Supports online growth but cannot be shrunk. Well-suited for databases, media storage, and high-throughput applications.
mkfs.xfs /dev/vg_data/lv_databases
# Defragment an XFS filesystem
xfs_fsr /dev/vg_data/lv_databases
Btrfs
A modern copy-on-write filesystem with built-in features like snapshots, compression, checksumming, and RAID. Growing in adoption (default on openSUSE and Fedora Workstation) but not yet considered as battle-tested as ext4 or XFS for all production workloads.
mkfs.btrfs /dev/sdc1
# Create a subvolume
btrfs subvolume create /mnt/data/snapshots
# Take a snapshot
btrfs subvolume snapshot /mnt/data /mnt/data/snapshots/2024-03-15
# Enable compression
mount -o compress=zstd /dev/sdc1 /mnt/data
Mounting Filesystems
Temporary Mounts
# Mount a partition
mount /dev/vg_data/lv_databases /srv/databases
# Mount with specific options
mount -o noatime,nodiratime /dev/vg_data/lv_logs /var/log
# Mount by UUID (more reliable than device names)
mount UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890 /mnt/data
# Unmount
umount /srv/databases
Persistent Mounts with /etc/fstab
For mounts to survive reboots, add entries to /etc/fstab:
# /etc/fstab format:
# <device> <mountpoint> <type> <options> <dump> <fsck>
UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890 /srv/databases xfs defaults,noatime 0 2
/dev/vg_data/lv_logs /var/log ext4 defaults 0 2
/dev/vg_data/lv_backups /backup ext4 defaults,nosuid,noexec 0 2
Always use UUIDs in fstab instead of device names like /dev/sdb1, because device names can change across reboots when disks are added or removed. Find UUIDs with blkid.
After editing fstab, validate it before rebooting:
# Test all fstab entries without actually mounting
mount -a
# If this succeeds without errors, fstab is valid
Filesystem Checks with fsck
fsck checks and repairs filesystem inconsistencies. It must be run on unmounted filesystems (or read-only mounted, in the case of the root filesystem during boot).
# Check an ext4 filesystem
fsck.ext4 /dev/vg_data/lv_logs
# Force check even if the filesystem appears clean
fsck.ext4 -f /dev/vg_data/lv_logs
# Automatically repair (use with caution)
fsck.ext4 -y /dev/vg_data/lv_logs
# For XFS, use xfs_repair
xfs_repair /dev/vg_data/lv_databases
Warning: Never run fsck on a mounted filesystem. It can cause data corruption. If you need to check the root filesystem, boot into rescue mode or use a live USB.
Practical Guidelines
- Always use LVM for server deployments; the flexibility to resize volumes without downtime is invaluable
- Use XFS for large data volumes and database storage; use ext4 for general purpose
- Set
noatimemount option on busy filesystems to reduce unnecessary write I/O - Monitor disk usage with automated alerts at 80% and 90% thresholds
- Use
nosuidandnoexecmount options on partitions that store user uploads or temporary files - Test
/etc/fstabchanges withmount -abefore rebooting; a bad fstab entry can prevent the system from booting - Keep the
/bootpartition on a simple partition (not LVM) for bootloader compatibility