A process crashes in production, the service comes back from a restart, and you have no idea why it died. If the kernel was writing core dumps, this would be a five-minute investigation — load the dump into gdb, read the backtrace, file the bug. On modern distros, systemd-coredump catches every crash, compresses the dump, journals the event, and gives you coredumpctl to pull it back later. The default behaviour is good but the retention and disk limits often need tuning, and the binary you need to debug isn’t always still on the host.
How to verify
Check who’s handling core dumps right now, see what’s been captured recently, and inspect one:
# Who owns core dumps?
cat /proc/sys/kernel/core_pattern
# Expected on modern systemd: |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h
# What's been captured?
coredumpctl list --since "7 days ago"
# Inspect a specific dump
coredumpctl info <pid-or-match>
# Disk usage
sudo du -sh /var/lib/systemd/coredump/
journalctl --disk-usage
If core_pattern is a literal path (/var/crash/core.%p) instead of a pipe to systemd-coredump, the host is using the legacy kernel-direct path — coredumpctl won’t see anything. Either install systemd-coredump (the package) or follow the legacy path’s own conventions.
What’s happening
When a process dies from a fatal signal (SIGSEGV, SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGQUIT, SIGSYS, SIGTRAP, SIGXCPU, SIGXFSZ), the kernel optionally writes its memory image to disk — a core dump. The destination is controlled by /proc/sys/kernel/core_pattern: a path means “write here directly”, a pipe (|/path/to/handler) means “feed the dump to this program’s stdin”.
systemd-coredump is that handler on every recent systemd-based distro. It compresses the dump (zstd by default), writes it to /var/lib/systemd/coredump/, and records metadata (PID, executable, signal, backtrace summary, environment) in the journal under the MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1 key. coredumpctl queries that journal index.
The advantages over kernel-direct dumps: automatic compression saves disk, retention policy bounds growth, the journal correlates crashes with logs from the same boot, and coredumpctl gdb resolves debug info automatically. The disadvantages: a kernel that can’t reach the handler (e.g. early-boot crash) silently loses the dump, and very large processes (multi-GB heaps) take noticeable time to write before the next process can start.
The procedure
- Make sure systemd-coredump is the active handler. On Debian/Ubuntu the
systemd-coredumppackage wires upcore_patternvia a sysctl drop-in:
sudo apt install systemd-coredump
sysctl kernel.core_pattern
# kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h
On Red Hat / Fedora derivatives the package is systemd-udev/systemd-coredump. Check /usr/lib/sysctl.d/50-coredump.conf for the pipe definition.
- Configure retention and per-dump limits. The defaults are reasonable but production hosts often want to keep more history. Edit
/etc/systemd/coredump.conf:
[Coredump]
Storage=external
Compress=yes
ProcessSizeMax=8G
ExternalSizeMax=8G
MaxUse=20G
KeepFree=1G
Storage=external— write dumps to/var/lib/systemd/coredump/(as opposed tojournal, which encodes them into the journal itself and is rarely what you want).ProcessSizeMax— the largest process for which a dump will be attempted. Above this, the kernel still kills but no dump is written.ExternalSizeMax— cap on individual dump file size.MaxUse— total disk usage the coredump tree may consume before older dumps are evicted.KeepFree— minimum free space to leave on the filesystem; eviction kicks in before this is breached.
Apply the change — no service restart needed; the handler reads the config on each invocation:
sudo systemctl restart systemd-tmpfiles-setup
ls -lah /var/lib/systemd/coredump/
- Ensure the process is allowed to dump in the first place. systemd services often have dump limits disabled by default. Check and override per service:
# Per-service inspection
systemctl show --property=LimitCORE myservice.service
# inf = allowed, 0 = blocked
# Override
sudo systemctl edit myservice.service
# add:
[Service]
LimitCORE=infinity
sudo systemctl daemon-reload
sudo systemctl restart myservice.service
For setuid binaries and processes that have changed UID, the kernel suppresses dumps by default for security. Override globally only with awareness — dumps can contain secrets:
sysctl -w fs.suid_dumpable=2 # dumps for suid binaries, owned by root, mode 0600
- Trigger a controlled crash to validate the pipeline before you need it for real:
sleep 600 &
PID=$!
kill -SEGV $PID
coredumpctl list --since "1 minute ago"
coredumpctl info $PID
A fresh entry confirms the handler is wired, the journal index works, and /var/lib/systemd/coredump/ is writable.
- Pull a backtrace from a captured dump. coredumpctl will start gdb against the original binary (which must still be on the host or in debuginfo paths):
coredumpctl gdb <pid>
# in gdb:
(gdb) bt
(gdb) bt full
(gdb) thread apply all bt
(gdb) info registers
If the binary or its libraries have been upgraded since the crash, gdb may emit “symbol not found” — install matching -dbg/-debuginfo packages, or dnf debuginfo-install <pkg> on RHEL family.
- Extract a dump for offline analysis on another host (the only way to debug crashes from a host you can no longer SSH into):
coredumpctl dump <pid> --output=/tmp/dump.bin
# copy the dump and the executable + any required .so files
scp /tmp/dump.bin you@analysis:/tmp/
cp /usr/bin/myapp /tmp/
ldd /usr/bin/myapp # capture the library paths
# on the analysis host
gdb /tmp/myapp /tmp/dump.bin
- Prune old dumps when storage is tight. systemd handles eviction by
MaxUseautomatically; manual cleanup looks like:
sudo journalctl --rotate
sudo journalctl --vacuum-time=7d
sudo find /var/lib/systemd/coredump/ -mtime +30 -delete
Common pitfalls
- Containers — by default the container’s PID namespace is hidden from the host’s coredump handler, and the dump (if written) lands inside the container. Either configure the container with
--ulimit core=-1and bind-mount a host directory at the container’score_patternlocation, or run with--initand rely on systemd-coredump on the host (works only if the host’score_patternis a pipe — pipes are read by host-namespace). - A
core_patternset to a literal path (/var/crash/core.%p) bypasses systemd-coredump entirely. Container runtimes (Docker, K8s) sometimes override this — check inside the container if the host setting is the pipe but no dumps appear. LimitCORE=0in a service unit silently drops every dump. Always confirm withsystemctl show --property=LimitCORE.- Dumps for a long-running process can be huge (RSS-sized). Capping
ProcessSizeMaxprevents a single dump from filling a small/var. - Stripped binaries produce backtraces without symbols. Production builds with
-gand split debug info (objcopy --only-keep-debug) give you the best of both worlds: small binary, accurate stack traces when needed.
We turn systemd-coredump on with sane caps as part of base build for every Linux host we run, and we collect dumps centrally for incident review the same way logs flow into the SIEM. The five minutes spent configuring it once means a “what killed it?” question that would otherwise be unanswerable becomes a routine triage in the managed operations queue.