Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 5System · Linux

How to check disk space and find what fills the disk

"No space left on device" stops databases, logs, builds and updates. This how-to shows how much space is left, then finds what fills the disk in a few commands, and gives the safe clean-ups for the usual suspects: logs, Docker, package caches and files that were deleted but are still open.

  • 5 Lessen
  • 14 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

5.1

The quick answer

df -h
du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -15
find / -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/null

df = how full each file system is; du = which folder uses the space; find = the biggest files.

5.2

Step by step

  1. Which file system is full?
df -hT
Filesystem            Type  Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs    20G   19G  1.0G  95% /
/dev/sda1             xfs   960M  310M  651M  33% /boot
df -i

df -i shows inodes (number of files). A disk can be "full" with free space when millions of tiny files used all inodes.

  1. Walk down to the big folder — -x stays on this file system:
du -xh --max-depth=1 / | sort -h | tail
du -xh --max-depth=1 /var | sort -h | tail
du -xh --max-depth=1 /var/log | sort -h | tail

(ncdu is an interactive version: dnf install ncdu from EPEL / apt install ncdu.)

  1. Clean the usual suspects (check before you delete):
WhatCheckSafe clean-up
systemd journaljournalctl --disk-usagejournalctl --vacuum-size=500M
Old rotated logsls -lh /var/log/*.gzlet logrotate handle it; delete old .gz files
Docker images, containers, build cachedocker system dfdocker system prune (add -a for unused images)
Package cachedu -sh /var/cache/dnf /var/cache/aptdnf clean all / apt-get clean
Old kernels (RHEL)rpm -q kerneldnf remove --oldinstallonly
Core dumpscoredumpctl listremove old ones in /var/lib/systemd/coredump
  1. Deleted but still open files — space that du does not see but df does:
lsof +L1 2>/dev/null | head
COMMAND  PID USER  FD  TYPE DEVICE  SIZE/OFF NLINK NODE NAME
java    2241 app   1w  REG  253,0 8.2G      0 1310 /var/log/app/app.log (deleted)
systemctl restart app

The process still writes into the deleted file; restarting it (or truncating via /proc/PID/fd/N) frees the space.

  1. Fix the cause, not only the symptom: log rotation and size limits (SystemMaxUse= in journald, Docker log max-size), retention for backups, and a monitoring alert (for example at 85 %).

5.3

Check that it worked

df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root  20G   11G  9.0G  55% /

Commando's in deze les

5.4

Common problems

ProblemCauseFix
df says full, du finds much lessDeleted files still open.lsof +L1; restart that process.
Free space but "No space left on device"Inodes are full.df -i; delete many small files (caches, sessions, mail queues).
Root can not free space even after deletingThe deleted file is still open, or a snapshot keeps it.lsof +L1; check LVM/VM/file-system snapshots.
/boot is fullToo many old kernels.dnf remove --oldinstallonly / apt autoremove.
The disk fills again quicklyA runaway log or a job.Find the growing folder (du twice, 10 minutes apart); fix rotation/limits.
Need more space permanentlyThe disk is too small.Grow the disk and the LVM volume ("Extend an LVM volume").

5.5

Go further

1df shows 100 % but du only finds half of it. What is the most likely cause?

Deleted files still held open by a process — find them with lsof +L1 and restart the process.

2What does df -i show?

The inode use — how many files the file system can still hold.

Alle commando's in dit hoofdstuk