GICT knowledge base
The Essential Guide to Ubuntu Server Storage Optimization and Maintenance
Published
Anyone who’s ever managed an Ubuntu server knows that storage isn’t just about having “enough space.” It’s about organization, efficiency, reliability, and planning for growth and failure. Ignore your server’s storage and you’ll get burned: slow performance, mysterious service failures, corruption, or even catastrophic data loss. Dedicate a little time to storage optimization and regular maintenance, however, and you’ll enjoy a stable, speedy, and resilient system for years to come.
This guide is here to take you from “just making it work” to actively mastering your server’s storage. We’ll cover how to monitor your disks, clean up wasted space, optimize performance, automate maintenance, and plan for disaster recovery step by step, with real-world explanations and command-line examples.
1. Know Your Storage: Mapping Disks, Partitions, and Mount Points
Before you do anything else, you need to understand your server’s current storage layout. Think of this as a map of your “territory” if you don’t know what’s out there, you can’t manage it properly.
a) Listing Disks and Partitions
Start with lsblk this shows all disk devices, partitions, and mount points in a clear, tree-like format:
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,LABEL
You’ll see results like:
NAME SIZE FSTYPE MOUNTPOINT
sda 100G
├─sda1 96G ext4 /
├─sda2 1G swap [SWAP]
sdb 500G
└─sdb1 500G ext4 /data
Now you know where your root (/) is, where swap is, and if you have a separate partition for /data, /var, etc.
b) Checking Disk Usage
Run:
df -h
This shows space used and free on each mounted filesystem. Focus on /, /var, /home, and any data partitions. If any are above 80% full, it’s time to investigate.
c) Reviewing Mount Points and Boot-Time Configuration
Your /etc/fstab file lists what gets mounted and where at boot. Open it with:
cat /etc/fstab
This is important for understanding persistent mount points, especially for additional disks, RAID arrays, or network shares.
2. Disk Health: Monitoring and Early Warning
Storage optimization isn’t just about saving space it’s about preventing failure. Hard drives and SSDs fail, often without warning, unless you’re monitoring them.
a) SMART Monitoring
Almost all modern drives support SMART (Self-Monitoring, Analysis and Reporting Technology). Install the tools:
sudo apt update
sudo apt install smartmontools
Check drive health:
sudo smartctl -a /dev/sda
Look for lines like “ReallocatedSectorCt” or “SMART overall-health self-assessment test result.” Schedule regular SMART tests and set up email alerts with scripts or monitoring tools.
b) Regular Monitoring Tools
For enterprise solutions: Zabbix, Prometheus, Icinga2, or Nagios can track disk space and health.
For DIY: Write a cron job to run df -h and email you if any partition is above a threshold (say, 90%). Example script:
#!/bin/bash
df -h | awk '$5+0 > 90 {print $0}' | mail -s "Disk space warning" [email protected]
3. Cleaning House: Freeing Up Disk Space
Even the biggest disks fill up if neglected. Here’s how to reclaim space safely.
a) Find the Space Hogs
To see what’s using the most space:
sudo du -xh --max-depth=1 /
Or, for something more visual, install ncdu:
sudo apt install ncdu
sudo ncdu /
Navigate with arrow keys and see where gigabytes are hiding.
b) Clean the APT Cache
Ubuntu keeps package files after installing or upgrading. Clean them out:
sudo apt clean
sudo apt autoclean
sudo apt autoremove
This can reclaim hundreds of megabytes or more, especially after big upgrades.
c) Manage Log Files
Logs in /var/log can grow unchecked. Ubuntu uses logrotate to compress and delete old logs, but sometimes you need to step in.
Force log rotation:
sudo logrotate -f /etc/logrotate.conf
Manually remove old logs (be careful):
sudo rm -rf /var/log/*.gz /var/log/*.[0-9]
d) Remove Old Kernels
After repeated upgrades, you may have several unused kernels taking up space.
List installed kernels:
dpkg --list | grep linux-image
Remove all but the current and previous one:
sudo apt autoremove --purge
e) Delete Orphaned Packages and Leftovers
Get rid of unneeded packages:
sudo apt autoremoveUbuntu Server Storage Optimization
Check /tmp and /var/tmp for temp files that can be safely deleted.
4. Filesystem Optimization and Performance
a) Filesystem Choices: ext4, XFS, ZFS, Btrfs
ext4 is the default: fast, simple, and reliable for most workloads. XFS is great for very large files (media servers, databases). ZFS and Btrfs offer advanced features like snapshots and built-in RAID. For most general-purpose Ubuntu servers, ext4 is the way to go.
b) Run Filesystem Checks
For ext4, use fsck to check and repair corruption (best done from a live USB or in recovery mode):
sudo umount /dev/sda1
sudo fsck -f /dev/sda1
c) Enable TRIM for SSDs
SSDs need TRIM to stay fast and healthy. Ubuntu supports TRIM out of the box, but make sure it’s active:
sudo systemctl status fstrim.timer
Enable and start it if necessary:
sudo systemctl enable fstrim.timer
sudo systemctl start fstrim.timer
5. Advanced Storage Techniques
a) LVM (Logical Volume Manager)
LVM lets you resize filesystems, add disks, and create snapshots often without downtime. For example, to grow your root volume by 10GB:
sudo lvextend -L +10G /dev/ubuntu-vg/root
sudo resize2fs /dev/ubuntu-vg/root
LVM snapshots are great for backups or system upgrades.
b) RAID for Redundancy or Speed
Ubuntu supports software RAID (mdadm):
- RAID 1: Mirroring (redundancy)
- RAID 0: Striping (speed, no redundancy)
- RAID 5/6/10: Advanced setups for larger servers
Check RAID status:
cat /proc/mdstat
Configure with mdadm (see the Ubuntu Server Guide for details).
c) Backups: Your Lifeline
No amount of optimization saves you if your disk dies and you have no backup. Use:
- rsync: for simple, fast file backups.
- borgbackup or restic: for encrypted, deduplicated, incremental backups.
- Cloud solutions, external drives: or remote servers for redundancy.
Automate backups with cron and regularly test your restore process don’t wait until disaster strikes.
6. Maintenance Plans: Establishing Routines
Set up a schedule for regular maintenance, and stick to it. Here’s an example:
Weekly
- Run
df -hand check for space issues. - Use
ncduto spot growing directories. - Clean package caches and temp files.
- Check for failed SMART tests (
smartctl).
Monthly
- Review
/etc/fstabfor mount issues. - Rotate and review logs.
- Audit and prune old backups.
Quarterly
- Run
fsckin maintenance mode. - Test restoring from backups.
- Review user and group disk usage with
duorfind.
Annually
- Revisit your partitioning and storage strategy.
- Consider hardware replacements for aging disks.
Automate what you can, but always log maintenance actions and review results.
7. Troubleshooting: Common Storage Problems and Solutions
a) Disk Full? Server Misbehaving?
Find the culprit with df -h and du -sh * inside big directories. Clean up logs, cache, and temp files.
If /var or / is full, services may fail or the server won’t boot. Free up space ASAP.
b) Filesystem Corruption
Look for errors in dmesg and /var/log/syslog. Unmount and run fsck if needed. If severe, restore from backup.
c) Slow Disks
Use iostat or iotop to monitor I/O bottlenecks. Check SMART status for failing drives. For SSDs, ensure TRIM is active.
d) RAID Degraded
Check status with cat /proc/mdstat. Replace failed disks promptly. Rebuild arrays only when backups are up to date.
8. Best Practices and Pro Tips
- Keep /, /var, and /home on separate partitions if possible. This prevents runaway logs or user data from crashing the whole system.
- Never let / fill up reserve 5–10% as a buffer.
- Monitor disk health and usage with alerts, not just manual checks.
- Document your storage layout and maintenance plan future you will thank you!
- Always test restores backups mean nothing if you can’t get your data back.
- Don’t forget about old snapshots and backup archives they can quietly fill even the biggest disks.
Conclusion
Managing storage on Ubuntu servers is about more than just making space it’s about keeping your systems running smoothly, preventing failures, and being ready for the unexpected. With a little regular attention, a set of trusted tools, and a solid maintenance plan, you can avoid almost all of the “disk disasters” that plague unprepared admins.
By mapping your storage, monitoring usage and health, cleaning up regularly, and backing up religiously, you’ll sleep better and your servers will thank you for it. Remember: storage problems don’t happen all at once they creep up, and a well-maintained server is a happy, reliable server.
Related guides
How to Set Up zram on a Small VPS
Configure zram on Ubuntu with kernel and swap checks. Understand compressed memory limits, monitor real use and avoid unsafe swap-file changes.
LinuxHow to Find Services That Need a Restart After Updates with needrestart
Find services using outdated libraries with needrestart on Ubuntu. Read restart reports, review automatic restart policy and plan maintenance safely.
LinuxHow to Limit a Linux Service’s Memory with systemd
Limit a Linux service with systemd MemoryHigh, MemoryMax and swap controls. Check cgroup support, diagnose pressure and remove only your own policy.
LinuxHow to Protect SSH with CrowdSec on Ubuntu
Protect SSH with CrowdSec on Ubuntu. Connect log detection to firewall enforcement and test temporary blocking without losing administrator access.
