Infrastructure
Linux: diagnose a full filesystem after deleting logs
A production runbook for separating block and inode exhaustion from deleted open files, then recovering space without a blind restart.
An application can no longer write under /var. An operator deletes a large log, but the capacity alert stays active and a broad restart is proposed. Before deleting more files or expanding the disk, identify the exhausted resource and the process holding it.
This runbook follows a Linux VM whose export service writes to /var/log/exporter. Names and paths are fictional. Run the read-only checks with appropriate permissions and in the relevant mount namespace; they do not replace the local incident procedure.
Establish the scope before cleanup
Record the UTC time, exact error, affected service and mount, capacity trend and recent changes. Check service availability, possible log loss and the space needed for recovery. If the filesystem threatens availability, limit nonessential writes under the emergency procedure without disabling critical evidence collection.
findmnt -T /var/log/exporter
df -hT /var/log/exporter
df -i /var/log/exporter
sudo du -xhd1 /var 2>/dev/null findmnt identifies the filesystem containing the path; df reports filesystem space and df -i reports inodes. du -x totals accessible files without crossing other filesystems, but a large scan can take time and this example suppresses errors. Check permissions and mount boundaries before drawing conclusions. A container or overlay mount may see a different filesystem from the host.
| Observation | Hypothesis to test | Next evidence |
|---|---|---|
| Blocks full, inodes available | Large files or retained space | Compare du, mounts and deleted open files |
| Inodes full | Very large file count | Find the producing directory and retention policy |
df much higher than du | Deleted open file, hidden mount or other filesystem accounting | Check processes, namespaces, snapshots and applicable reservations |
| Space available but writes fail | Quota, permissions, read-only mount or application error | Capture the exact error and inspect the service context |
A gap between df and du alone does not prove a deleted open file. Snapshots, reserved space, files hidden beneath a mount and filesystem-specific accounting can also explain a difference.
Find deleted files still held open
On the host or in the appropriate namespace, list open unlinked files and compare their device with the affected mount:
sudo lsof -nP +L1
ps -p <PID> -o pid,ppid,user,lstart,args
sudo ls -l /proc/<PID>/fd/<FD> Replace the angle-bracket placeholders after inspecting the first command; do not enter the brackets in the shell. Record PID, start time, descriptor, device, inode and size, then identify the service and owner. One file can appear more than once, so do not sum the displayed sizes blindly. Apparent size need not equal allocated blocks. Limited permissions or namespace visibility can hide processes.
When the last name of a file is removed while processes still hold it open, the space is not released until the last references close. The unlink manual describes this behavior; lsof documents the +L1 filter.
Make a bounded change
In this example, the deleted file belongs to the export service. First check whether its documented procedure can reopen logs: a correctly configured rotation or reopen command may close the old descriptor without interrupting work. Do not assume a particular signal means the same thing to every service.
If reopening is unavailable or fails, prepare a targeted restart with the owner: check other instances’ capacity, in-flight jobs, any drain procedure, dependencies, configuration backup and stop criteria. Do not kill an unidentified process or truncate /proc/<PID>/fd/<FD> as an emergency shortcut: either can destroy data or disrupt the application. Deleting more logs can remove evidence without freeing space when files remain open.
A volume expansion may buy time when authorized and validated end to end, but it does not close the descriptor or fix growth. For inode exhaustion, address the small-file producer and its retention; adding blocks does not guarantee additional inodes.
Verify and decide
After reopening or the targeted restart, verify that no process still holds the old inode, then compare df -hT and df -i on the same path. Confirm that the service writes to the new log, work resumes, and collection and alerts function. Observe the growth rate for an agreed window.
VALIDATE
Free space and headroom acceptable; old file closed
New log writes and collection confirmed
Service and jobs checked; growth monitored
HOLD AND ESCALATE
Process or mount uncertain; free space still falling
Reopen failed; suspected data or evidence loss
Inodes, quota or another cause remains unresolved
ROLL BACK
Restore known configuration if the rotation change fails
Return to the previous service only if its state is healthy
Do not claim a deleted file is recoverable without a backup
Recheck writes, capacity and collection after rollback Record the cause and correct rotation, retention or alerting for the identified producer. Close only when space remains available and useful logs continue to arrive; otherwise keep the protective measures in place and escalate.