🚨 Disk Full Suddenly! Linux Emergency Troubleshooting Guide

While operating a server, you might suddenly encounter the dreaded “Disk full” warning. 😱 This can lead to serious issues like services stopping or the system slowing down.

Today, we’ll explore a 3-step emergency guide to calmly free up disk space in such critical situations!


STEP 1: 🩺 Check Disk Status: Verify Total Capacity

First, you need to identify which partition (disk space) is full. It’s like a doctor diagnosing a patient’s condition. The command used for this is df -h.

  • df: Short for disk free, it shows the disk space usage of file systems.
  • -h: Short for human-readable, it displays capacity in units that are easy for humans to read (GB, MB).
df -h

Executing the command will display a screen similar to the following.

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   49G  500M  98% /
udev             16G     0   16G   0% /dev
tmpfs           3.2G  1.2M  3.2G   1% /run
...

The parts to pay attention to here are the Use% and Mounted on columns.

  • Use%: Shows disk usage as a percentage. In the example, the /dev/sda1 file system is 98% used, indicating it’s almost full. 🚩
  • Mounted on: This is the directory path where the file system is mounted. In the example, it’s the root directory, /. We will focus on this path to resolve the issue.

STEP 2: πŸ•΅οΈβ€β™‚οΈ Identify the Culprit: Find the Largest File

Now that we know which partition has an issue, it’s time to find the ‘culprit’ occupying that space – the largest file.

The command below finds and outputs only the single largest file in the specified path (the Mounted on path).

# Please replace '/path/to/nearly-full-filesystem' with the 'Mounted on' path confirmed above.
# Example: find / -type f -printf '%s %p
' | sort -rn | head -n 1

find /path/to/nearly-full-filesystem -type f -printf '%s %p
' | sort -rn | head -n 1

This command might look a bit complex, but each part’s role is simple.

  • find /path: Starts searching from a specific path.
  • -type f: Finds only ‘files’, excluding directories.
  • -printf ‘%s %p

‘: Outputs the file size (in bytes) and file path together.

  • | (pipe): Passes the output of the left command as input to the right command.
  • sort -rn: Sorts the received list by numeric size (n) in reverse order (r). (Largest file at the top!)
  • head -n 1: Shows only the first line from the top of the sorted list.

Executing this command will display the size and full path of the largest file, as shown below.

15032385536 /var/log/some_huge_log_file.log

We finally found the culprit! πŸ•΅οΈβ€β™€οΈ


STEP 3: πŸ—‘οΈ Resolve the Issue: Delete the Large File

Now that we’ve found the culprit, it’s time to deal with it. You can delete the file using the rm command.

⚠️ Very Important! ⚠️ Before deleting, you must absolutely confirm that the file is truly unnecessary. Deleting files essential for system operation can lead to irreversible problems. Typically, old log files, unnecessary backup files, and temporary files are targets for deletion.

# Please replace '/path/to/largest_file' with the actual file path found in STEP 2.
# Example: rm /var/log/some_huge_log_file.log

rm /path/to/largest_file

Executing the command will delete the file, freeing up that amount of disk space.


βœ… Verify Results: Check if Space Has Been Freed!

Finally, run the df -h command again to confirm that space has been successfully freed.

df -h

Seeing the Use% significantly drop will bring you peace of mind. 😊

Now your server can operate smoothly again. Moving forward, it’s a good idea to develop the habit of regularly checking disk space to prevent such emergencies, right?



Comments

Leave a Reply

Your email address will not be published. Required fields are marked *