Fixing Disk Space Issues
Running out of disk space is a common issue that can lead to several problems like performance degradation, inability to write new data, and service outages. This guide provides a set of guidelines to help you diagnose and resolve disk space issues on Ubuntu and AWS EC2 servers.
Preliminaries
Section titled “Preliminaries”Before proceeding, make sure you have:
- SSH access to the server facing disk space issues.
- Necessary permissions to delete or modify files and directories.
- Backups of critical data, just in case.
Diagnostics
Section titled “Diagnostics”For Any Server
Section titled “For Any Server”After SSHing into a server, run the following commands to identify disk space usage:
-
Initial Diagnostic
Terminal window df -hBe cautious if the
Use%column shows over 90% for any partitions. -
Detailed Directory Info
Terminal window ls -lh /path/to/directory
This command provides detailed information about a directory’s child files and folders, formatted in a more human-readable way (-h).
For Ubuntu Specific
Section titled “For Ubuntu Specific”- Check APT Cache Size: Ubuntu keeps a cache of downloaded updates, which can grow over time.
Terminal window du -sh /var/cache/apt/archives
For AWS EC2 Instances
Section titled “For AWS EC2 Instances”- Check EBS Volume Details: Login to the AWS Management Console, identify the EC2 instance, and look for the details of the Root and block devices.
Remediation Steps
Section titled “Remediation Steps”For Any Server
Section titled “For Any Server”-
Remove Unnecessary Files/Directories: Based on the diagnostic info, try to remove any large or unnecessary files.
Terminal window rm -r /path/to/unnecessary/files_or_directories
For Ubuntu Specific
Section titled “For Ubuntu Specific”-
Clean the APT Cache
Terminal window sudo apt-get clean -
Remove Old Kernels
Terminal window sudo apt-get autoremove --purge -
Uninstall Unused Apps
Terminal window sudo apt-get remove package-name1 package-name2sudo apt-get autoremove -
Use System Cleaner (BleachBit)
- Install BleachBit from the Ubuntu Software Center.
- Run the app as root and choose files/directories to clean.
-
Keep the System Updated
Terminal window sudo apt-get update && sudo apt-get upgrade
For AWS EC2 Instances
Section titled “For AWS EC2 Instances”Phase 1: Prepare EBS Blocks
Section titled “Phase 1: Prepare EBS Blocks”- Login to the AWS Management Console.
- Identify the EC2 instance(s) you need to extend.
- Click on the EBS ID (
vol-xxxx) to modify the EBS volume and set a new size.
Phase 2: Update Linux Servers
Section titled “Phase 2: Update Linux Servers”- SSH into the EC2 instance.
- Determine the block name and partition:
Terminal window lsblk - Check existing disk space:
Terminal window df -h - Run the resize commands:
Terminal window growpart /dev/xvda 1resize2fs /dev/xvda1 - Confirm that disk space has increased:
Terminal window df -h
Next Steps
Section titled “Next Steps”- If the issue persists, consider increasing the server size.
- Keep monitoring disk usage to avoid future space issues.