Skip to content

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.


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.

After SSHing into a server, run the following commands to identify disk space usage:

  1. Initial Diagnostic

    Terminal window
    df -h

    Be cautious if the Use% column shows over 90% for any partitions.

  2. 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).

  • Check APT Cache Size: Ubuntu keeps a cache of downloaded updates, which can grow over time.
    Terminal window
    du -sh /var/cache/apt/archives
  • 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.

  1. 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
  1. Clean the APT Cache

    Terminal window
    sudo apt-get clean
  2. Remove Old Kernels

    Terminal window
    sudo apt-get autoremove --purge
  3. Uninstall Unused Apps

    Terminal window
    sudo apt-get remove package-name1 package-name2
    sudo apt-get autoremove
  4. Use System Cleaner (BleachBit)

    • Install BleachBit from the Ubuntu Software Center.
    • Run the app as root and choose files/directories to clean.
  5. Keep the System Updated

    Terminal window
    sudo apt-get update && sudo apt-get upgrade
  1. Login to the AWS Management Console.
  2. Identify the EC2 instance(s) you need to extend.
  3. Click on the EBS ID (vol-xxxx) to modify the EBS volume and set a new size.
  1. SSH into the EC2 instance.
  2. Determine the block name and partition:
    Terminal window
    lsblk
  3. Check existing disk space:
    Terminal window
    df -h
  4. Run the resize commands:
    Terminal window
    growpart /dev/xvda 1
    resize2fs /dev/xvda1
  5. Confirm that disk space has increased:
    Terminal window
    df -h
  • If the issue persists, consider increasing the server size.
  • Keep monitoring disk usage to avoid future space issues.