Master Linux Disk Management: Hands-On Guide to fdisk, df, and Essential Commands

Master Linux Disk Management: Hands-On Guide to fdisk, df, and Essential Commands

Get hands-on with Linux disk management in this practical guide—learn fdisk, df, partitioning concepts, and workflows you can apply on VPS and cloud servers. Avoid downtime and improve performance by provisioning, resizing, and recovering storage the right way.

Disk management is a foundational skill for anyone running Linux servers, from personal projects to production VPS instances. Whether you’re provisioning storage, troubleshooting a full disk, or preparing partitions for containers and databases, understanding the tools and the underlying concepts reduces downtime and improves performance. This hands-on guide covers the essentials: how fdisk and df work, when to use complementary utilities, and practical workflows you can apply on a VPS.

Why disk management matters on VPS and cloud servers

On virtual private servers, storage characteristics (thin provisioning, underlying hypervisor snapshots, virtual block devices) can differ from physical hardware. Misconfiguration leads to wasted space, boot failures, or degraded I/O. Proper disk management enables you to:

  • Provision storage correctly for OS, logs, databases, or application data.
  • Scale storage safely by resizing partitions or moving data between volumes.
  • Recover from disk-related failures by understanding partition tables and file systems.
  • Optimize performance by choosing appropriate file system options and aligning partitions.

Core concepts: partitions, file systems, UUIDs, and mount points

Before running commands, make sure you understand these terms:

  • Partition table — A data structure (MBR or GPT) on a block device (/dev/sda) describing partitions.
  • Partition — A contiguous range of blocks defined on a device, represented as /dev/sda1, /dev/nvme0n1p1, etc.
  • File system — Formats such as ext4, xfs, btrfs that map files to disk blocks. Created with mkfs.ext4, mkfs.xfs, etc.
  • UUID — Universally unique identifier assigned to a file system; reliable for fstab entries versus device names.
  • Mount point — Directory where a file system is attached to the Linux tree (e.g., /var, /data).

fdisk: partition table editor for block devices

fdisk is a classic terminal utility to create, delete, or modify partitions on MBR and GPT devices. It works at the block device level and updates the partition table; it does not create file systems.

Typical fdisk workflow

1) Inspect device: run fdisk -l /dev/sda to list partitions and sizes. 2) Start interactive session: fdisk /dev/sda. 3) Use commands: p (print), n (new partition), d (delete), t (change type), w (write), q (quit without writing). 4) After writing, run partprobe or reboot to force kernel to re-read partition table if necessary.

Example: create a new partition occupying remaining space by starting fdisk /dev/sda, then type n, choose partition number, accept defaults for start and end, then w to write.

Key fdisk considerations

  • Take a backup of partition tables with sfdisk -d /dev/sda > sda.partitions before making changes.
  • Be careful with LVM or RAID metadata. Removing or overwriting partitions used by LVM will cause data loss.
  • After changing the partition table, the kernel may keep the old table active; partprobe or kpartx can help re-read partitions without rebooting.

df and related commands: monitoring usage

df reports file system disk space usage. It’s indispensable for spotting full mounts and verifying available space.

Useful df options and interpretation

Use df -h to see human-readable sizes. df -i shows inode usage which explains “no space left on device” when inodes are exhausted. For a specific mount, df -h /var will show only that file system.

Interpreting df output:

  • Filesystem: the device or identifier. On modern systems you may see tmpfs, overlay, or /dev/mapper/* for LVM.
  • Size and Used: total and consumed space.
  • Use%: when close to 100% you must free space or expand the file system.

Complementary utilities: lsblk, blkid, parted, mount, resize tools

fdisk and df are core, but real-world workflows require other tools:

  • lsblk — Lists block devices and their hierarchy; helpful to see partitions and LVM mappings visually.
  • blkid — Shows UUIDs and file system types. Use blkid /dev/sda1 to get the UUID for fstab.
  • parted — More flexible than fdisk for GPT and scripting; supports unit parsing and resizing partitions.
  • mount — Mounts file systems. Use mount /dev/sdb1 /mnt/data or add an fstab entry for persistence.
  • resize2fs and xfs_growfs — Grow ext4 and xfs file systems respectively after resizing partitions or adding space.
  • pvcreate, vgextend, lvextend — LVM commands to manage physical volumes, volume groups, and logical volumes for flexible resizing.

Common scenarios and step-by-step approaches

Scenario 1: Extending a root partition on a VPS

Many VPS providers allow increasing disk size or swapping to a larger virtual disk. Typical steps:

  • Confirm new block device size with lsblk or fdisk -l.
  • If the partition must be expanded, use parted to resize the partition to fill free space (parted /dev/sda resizepart X 100%).
  • Inform kernel partitions changed: partprobe /dev/sda.
  • Resize the file system: for ext4, run resize2fs /dev/sda1 (online for ext4 supports grown while mounted); for xfs, run xfs_growfs / -d.
  • Verify with df -h and tune2fs -l to validate the new space.

Note: If LVM is used, extend the physical volume (pvresize /dev/sda2), then extend the logical volume (lvextend -L +10G /dev/mapper/vg-lv) and finally resize the file system.

Scenario 2: Adding a new data disk and mounting it

Steps:

  • Identify the new device (e.g., /dev/vdb) with lsblk.
  • Create a partition with fdisk /dev/vdb or use the whole device as an LVM PV.
  • Create a file system: mkfs.ext4 /dev/vdb1 (or mkfs.xfs …).
  • Find the UUID: blkid /dev/vdb1.
  • Create mount point: mkdir /data, and mount it: mount /dev/vdb1 /data.
  • Add an /etc/fstab entry using the UUID to ensure persistence: UUID=xxxxxxxx-xxxx-… /data ext4 defaults,noatime 0 2.
  • Test fstab with mount -a to detect errors before reboot.

Scenario 3: Troubleshooting “No space left” with df and inodes

When df -h shows free space but applications still error, check inodes with df -i. Many small files (email queues, logs) can exhaust inodes. Solutions:

  • Find directories with large file counts: find / -xdev -type f | cut -d/ -f2 | sort | uniq -c (adjust to your needs).
  • Prune logs, rotate or compress with logrotate, and consider moving high-churn directories to separate mounts.
  • Recreate file system with a higher inode ratio if necessary, or use xfs (which handles large numbers of small files differently).

Best practices and performance tips

  • Use UUIDs in /etc/fstab to avoid boot issues when device names change (e.g., /dev/sda -> /dev/sdb).
  • Align partitions to 1MiB boundaries to avoid performance penalties on SSDs and modern storage.
  • Prefer LVM or separate volumes for flexible resizing of databases, logs, and application storage without impacting root.
  • Monitor inode and block usage with df -i and df -h to detect growth trends early.
  • Test destructive operations on staging systems. Partition and file system operations can be irreversible.

Choosing storage on VPS providers

When selecting a VPS plan for specific workloads, consider:

  • I/O performance — Database-heavy workloads benefit from SSD-backed storage with guaranteed IOPS.
  • Flexibility — Plans offering easy disk resizing or additional volumes reduce maintenance windows.
  • Backup and snapshot options — Regular snapshots simplify recovery after partition errors.
  • OS and tooling support — Check if the provider supports live disk resizing or has guidance for using tools like fdisk and LVM on their platform.

For example, if you are hosting multiple sites or databases, choosing a VPS plan with scalable storage and robust snapshot capability can save hours during maintenance and disaster recovery.

Summary

Mastering Linux disk management combines knowledge of tools and disciplined workflows. Use fdisk (or parted) to manage partitions, df to monitor usage, and complementary utilities such as lsblk, blkid, and LVM commands for flexible storage management. Always back up partition tables and data before making changes, prefer UUIDs in fstab, and test resizing operations in non-production environments first.

If you’re building or scaling infrastructure, reliable VPS providers that offer flexible, high-performance storage and easy expandability can make these tasks much smoother. Learn more about VPS plans at VPS.DO, including US-based options here: USA VPS.

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!