#server-performance

How to Optimize Storage Space on Linux

15 min read - May 22, 2026

hero section cover
Table of contents
  • How to Optimize Storage Space on Linux
  • Finding What's Using Your Disk
  • Clearing Package Caches, Logs, and Duplicates
  • Filesystem-Level Optimization
  • Automating Storage Maintenance
  • Making Every Gigabyte Count
Share

Practical techniques to reclaim and optimize disk space on Linux servers, from package cache cleanup to filesystem tuning and automated maintenance.

How to Optimize Storage Space on Linux

For years, the default answer to a full disk was simple: add more storage. Storage was cheap. That's no longer the case. NAND flash prices have surged since late 2025, driven by AI infrastructure demand consuming global production capacity. Enterprise SSD contract prices rose 85-90% in Q1 2026 alone, consumer NVMe drives have roughly doubled in street price, and new NAND production capacity isn't expected to come online until 2027.

The result: every gigabyte on your server costs more than it did a year ago, and that makes optimizing what you already have a much better investment than buying your way out. This post covers how to find what's eating your disk space, clean it up, and configure your filesystem to use storage more efficiently.


 

Finding What's Using Your Disk

Start with df -h to get a snapshot of every mounted filesystem, including total size, used space, and usage percentage. Any partition above 90% needs attention. Check specific partitions individually if needed:

df -h /
df -h /boot

Don't overlook inodes. A filesystem can have free space but no available inodes, which causes the same failures. Check with df -i.

If df shows 100% usage but the numbers don't add up, you likely have ghost files. These are files that were deleted but are still held open by a running process. The space won't be reclaimed until the process releases the file handle. Find them with:

sudo lsof / | grep deleted

Once you know which filesystems are under pressure, drill into directories with du or ncdu. For quick checks or scripting, du is the right tool:

du -h --max-depth=1 /var

Add -x when scanning from root to stay on a single filesystem and skip virtual mounts like /proc. For interactive exploration on a remote server, ncdu gives you a navigable text interface where you can sort by size and delete files directly.

Featureduncdu
InterfaceStatic command-line outputInteractive TUI with arrow-key navigation
Best forScripting and quick checksManual exploration on remote servers
SortingRequires piping to sortBuilt-in (by size, name, etc.)
File deletionSeparate rm commandBuilt-in (press d)

Clearing Package Caches, Logs, and Duplicates

Three areas consistently account for the most reclaimable space: package caches, log files, and large or duplicate files.

Package Caches and Orphaned Dependencies

Every install or update leaves cached package files behind. Over time, these pile up silently. Clean them based on your distro:

TaskDebian/Ubuntu (APT)Fedora/RHEL (DNF)Arch (Pacman)
Clear cachesudo apt cleansudo dnf clean allsudo paccache -r
Remove orphanssudo apt autoremovesudo dnf autoremovepacman -Rs $(pacman -Qdtq)
Purge leftover configssudo apt autoremove --purgeHandled by autoremoveN/A

Preview changes first with sudo apt autoremove --dry-run. Old kernels can eat 1.5GB or more on Ubuntu systems. Always keep the running kernel and one backup before removing older versions.

If you use Snap or Flatpak, these accumulate revisions and runtimes too:

sudo snap set system refresh.retain=2
flatpak uninstall --unused

Log Files in /var/log

Logs are the most common silent disk hog. Find oversized logs first:

du -xhd1 /var/log | sort -h
find /var/log -type f -size +100M

For systemd journals, use the built-in vacuum tool rather than deleting files manually:

sudo journalctl --vacuum-size=500M

To set a permanent cap, edit /etc/systemd/journald.conf:

SystemMaxUse=500M
MaxRetentionSec=14day

For active log files still held open by a service, don't use rm. The space won't be freed while the process holds the file descriptor. Truncate instead:

sudo truncate -s 0 /var/log/syslog

Large and Duplicate Files

Find files over 500MB across the entire system:

sudo find / -type f -size +500M -exec ls -lh {} +

For duplicates, rmlint uses hash-based comparisons to detect duplicate files, empty directories, and broken symlinks. Review its output carefully before removing anything, particularly on servers where identical files may serve different roles.

Filesystem-Level Optimization

After cleaning up files, you can squeeze more usable space out of the same hardware by tuning your filesystem.

Reducing ext4 Reserved Space

By default, ext4 reserves 5% of the filesystem for root. On a 2TB data partition, that's 100GB sitting idle. On a dedicated server where the data partition isn't the root filesystem, you can safely reduce this:

sudo tune2fs -m 1 /dev/sdXn

This sets the reservation to 1%, which is sufficient for most use cases. Verify the change with tune2fs -l /dev/sdXn.

Btrfs Transparent Compression

Btrfs supports transparent file compression, which ext4 and XFS don't offer. Mount with compress=zstd to compress data automatically on write. ZSTD provides a good balance of speed and ratio. For mixed-file workloads, compress-force=zstd can deliver an additional 10-20% savings by compressing files that the heuristic would normally skip.

To compress existing data on a Btrfs volume:

btrfs filesystem defragment -czstd /path/to/dir

Be careful with this on volumes that have snapshots or reflinks. Defragmenting breaks Copy-on-Write relationships, which can actually increase disk usage.

Both XFS and Btrfs support reflinks, which create file copies that share physical blocks until one copy is modified. This is useful for cloning VM disk images or container layers without doubling storage consumption:

cp --reflink=always source.img clone.img

LVM Thin Provisioning

LVM thin provisioning lets you allocate more logical space than you physically have, consuming real disk only as data is written. This is valuable when running multiple VMs or containers that each need their own logical volume but won't all fill them simultaneously.

To prevent thin pools from running dry, enable auto-extension in /etc/lvm/lvm.conf by setting thin_pool_autoextend_threshold and thin_pool_autoextend_percent.

Automating Storage Maintenance

Manual cleanups work once. Automated ones keep your disks healthy between now and the next time you log in. Use systemd timers over cron where possible. They log output to journalctl automatically, and Persistent=true catches up on missed runs after a reboot.

TaskToolFrequency
Log rotationlogrotateDaily or weekly
Journal vacuumingjournalctl --vacuum-timeWeekly
Package cache cleanupapt clean / dnf clean allMonthly
Temp file purgesystemd-tmpfilesDaily
Docker pruningdocker system pruneWeekly
Disk usage monitoringCustom script + systemd timerEvery 15-30 min

Docker deserves special attention. Container logs can grow without any visible warning. Limit log size globally by editing /etc/docker/daemon.json. Set max-size and max-file under the log-opts key to prevent individual containers from filling your disk.

For proactive monitoring, set up a two-tier alert system: a warning at 80% disk usage and a critical alert at 90%. Log disk usage hourly so you can track growth trends and predict when a partition will hit capacity:

0 * * * * df --output=source,size,used,pcent >> /var/log/disk_usage.csv

One more safeguard: mount /var, /tmp, and /home on separate partitions. This prevents runaway logs or user data from consuming the root filesystem and crashing the entire system.

Making Every Gigabyte Count

With storage prices climbing and no relief expected until new NAND production comes online in 2027, optimizing what you have isn't just good practice. It saves real money. The approach is straightforward:

  • Audit your disk usage with df, du, and ncdu before making any changes.
  • Clear package caches, rotate logs, and remove duplicates to reclaim space immediately.
  • Tune your filesystem. Reduce ext4 reserved blocks, enable Btrfs compression, or use LVM thin provisioning to get more from the same hardware.
  • Automate maintenance with systemd timers so your disks stay clean between audits.
  • Monitor usage trends and set alerts at 80% and 90% to catch problems early.

If you need dedicated server infrastructure with high-performance NVMe storage, FDC's dedicated servers are built for it.

Blog

Featured this week

More articles
Why it's important to have a powerful and unmetered VPS

Why it's important to have a powerful and unmetered VPS

Need reliable performance and unlimited traffic? A powerful unmetered VPS offers the speed, scalability, and bandwidth you need, without worrying about usage limits.

3 min read - May 9, 2025

#server-performance

How to Optimize Storage Space on Linux

15 min read - May 22, 2026

More articles
background image

Have questions or need a custom solution?

icon

Flexible options

icon

Global reach

icon

Instant deployment

icon

Flexible options

icon

Global reach

icon

Instant deployment