Skip to main content
Back to Category

Disk Management: Partitioning and Expansion Guide

Linux disk management: analyze usage with df/du, partition with fdisk/parted, manage volumes with LVM, extend partitions, and configure persistent mounts.

Read time: 14 min Server Management
diskfdiskpartedlvmpartitioninglinuxstoragemount

Table of Contents

Disk Management: Partitioning and Expansion Guide

Disk management is critical for server health and performance. This guide covers monitoring disk usage, partitioning tools, LVM (Logical Volume Manager) basics, partition expansion, and mounting.

Disk operations can be irreversible. Back up important data before proceeding.

Monitoring Disk Usage

df — Filesystem Usage

hljs bash
# Show all filesystems
df -h

# Show filesystem for a specific directory
df -h /var

# Show inode usage
df -i

# Include filesystem type
df -hT

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   20G   28G  42% /
/dev/sdb1       100G   45G   50G  47% /data
tmpfs           2.0G     0  2.0G   0% /dev/shm

du — Directory Usage

hljs bash
# Show directory size
du -sh /var/log

# Show subdirectories
du -h --max-depth=1 /var

# Find the largest directories
du -h /var | sort -rh | head -20

# Find files larger than 100 MB
find / -size +100M -type f 2>/dev/null

Viewing Disk and Partition Information

hljs bash
# List all block devices
lsblk

# With detailed info
lsblk -f

# Show disk information
sudo fdisk -l

# For a specific disk
sudo fdisk -l /dev/sda

# Show disk UUIDs
blkid

Partitioning with fdisk

fdisk is an interactive tool for MBR (Master Boot Record) disk partitioning.

hljs bash
# Start fdisk
sudo fdisk /dev/sdb

Commands inside fdisk:

m  — Help menu
p  — Print partition table
n  — New partition
d  — Delete partition
t  — Change partition type
w  — Write changes and exit
q  — Quit without saving

Creating a New Partition (fdisk)

hljs bash
sudo fdisk /dev/sdb
# n → new partition
# p → primary partition
# 1 → partition number
# Enter → default start sector
# +50G → 50 GB size
# w → write

# Format the partition
sudo mkfs.ext4 /dev/sdb1

# Create mount point
sudo mkdir /mnt/data

# Mount it
sudo mount /dev/sdb1 /mnt/data

Partitioning with parted

parted works with both MBR and GPT disks. GPT is required for disks larger than 2 TB.

hljs bash
# Start parted
sudo parted /dev/sdb

# Create GPT partition table
(parted) mklabel gpt

# Create partition
(parted) mkpart primary ext4 0% 100%

# Show partition table
(parted) print

# Exit
(parted) quit

# Format
sudo mkfs.ext4 /dev/sdb1

One-liner parted Usage

hljs bash
# Create GPT table and use entire disk as one partition
sudo parted -s /dev/sdb mklabel gpt mkpart primary ext4 0% 100%

# Format
sudo mkfs.ext4 /dev/sdb1

LVM Basics

LVM (Logical Volume Manager) abstracts physical disks for flexible storage management. You can resize volumes online and combine multiple disks.

LVM Concepts

ConceptAbbreviationDescription
Physical VolumePVPhysical disk or partition
Volume GroupVGPool created from PVs
Logical VolumeLVLogical partition allocated from VG

Setting Up LVM

hljs bash
# Install LVM tools
sudo apt install lvm2 -y

# Create physical volume
sudo pvcreate /dev/sdb

# Create volume group
sudo vgcreate vg_data /dev/sdb

# Create logical volume (50 GB)
sudo lvcreate -L 50G -n lv_data vg_data

# Format
sudo mkfs.ext4 /dev/vg_data/lv_data

# Mount
sudo mkdir /mnt/data
sudo mount /dev/vg_data/lv_data /mnt/data

Viewing LVM Information

hljs bash
# Physical volume info
sudo pvs
sudo pvdisplay

# Volume group info
sudo vgs
sudo vgdisplay

# Logical volume info
sudo lvs
sudo lvdisplay

Extending a Partition with LVM

hljs bash
# Add new disk and create PV
sudo pvcreate /dev/sdc

# Add to VG
sudo vgextend vg_data /dev/sdc

# Extend LV (use all free space)
sudo lvextend -l +100%FREE /dev/vg_data/lv_data

# Resize filesystem (ext4)
sudo resize2fs /dev/vg_data/lv_data

# For xfs
sudo xfs_growfs /mnt/data

Persistent Mount Settings (/etc/fstab)

Edit /etc/fstab to automatically mount disks on reboot:

hljs bash
# Get UUID
blkid /dev/sdb1

# Edit /etc/fstab
sudo nano /etc/fstab
# /etc/fstab format:
# UUID=xxxx  /mount/point  filesystem  options  dump  pass
UUID=a1b2c3d4-...  /mnt/data  ext4  defaults  0  2
hljs bash
# Test fstab (shows errors)
sudo mount -a

# Show all mounts
mount | grep /mnt

A mistake in /etc/fstab can prevent the system from booting. Back up first: sudo cp /etc/fstab /etc/fstab.bak

Disk Health Check

hljs bash
# Check SMART status
sudo apt install smartmontools -y
sudo smartctl -a /dev/sda

# Run a short test
sudo smartctl -t short /dev/sda

# Check filesystem for errors (unmounted disk)
sudo fsck -n /dev/sdb1

Conclusion

Disk management is a core component of server maintenance. Regular usage monitoring with df/du, flexible volume management with LVM, and proactive disk health monitoring with SMART tools will keep your server's storage infrastructure healthy.