Introduction
Linux core dumps capture a process's memory state at the moment of a crash, providing essential debugging information. The kernel.core_pattern sysctl controls where core dumps are written. When it is configured to pipe to an external handler (like |/usr/lib/systemd/systemd-coredump), core dumps may not appear in the expected location, or may not be generated at all if the pipe handler fails, the disk is full, or the storage limit is reached.
Symptoms
- Application crashes but no core file appears in the working directory
ulimit -c unlimitedis set but no core dump is producedsysctl kernel.core_patternshows a pipe:|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %ecoredumpctl listshows no entries despite known crashesdmesgshowscore dump handler returned 1orfailed to create core file
Common Causes
core_patternpipes tosystemd-coredumpbut the journal storage is limited- Disk partition for core dumps is full
Storage=noneincoredump.confdisabling core dump collectionProcessSizeMaxlimit in coredump.conf too small for the crashing process- Application runs in a container where core_pattern pipe target does not exist
Step-by-Step Fix
- 1.Check current core pattern:
- 2.```bash
- 3.sysctl kernel.core_pattern
- 4.# Pipe to external program: |/path/to/handler
- 5.# Direct file write: /path/to/core.%e.%p
- 6.
` - 7.Check systemd-coredump configuration:
- 8.```bash
- 9.cat /etc/systemd/coredump.conf
- 10.# Check for Storage= and ProcessSizeMax= settings
- 11.coredumpctl list
- 12.coredumpctl info <pid>
- 13.
` - 14.Configure systemd-coredump to store cores:
- 15.```bash
- 16.sudo nano /etc/systemd/coredump.conf
- 17.
` - 18.Add or modify:
- 19.```ini
- 20.[Coredump]
- 21.Storage=external
- 22.Compress=yes
- 23.ProcessSizeMax=2G
- 24.ExternalSizeMax=2G
- 25.
` - 26.Then reload:
- 27.```bash
- 28.sudo systemctl restart systemd-coredump.socket
- 29.
` - 30.Alternatively, configure direct core file writing:
- 31.```bash
- 32.sudo mkdir -p /var/cores
- 33.sudo chmod 777 /var/cores
- 34.echo "/var/cores/core.%e.%p.%t" | sudo tee /proc/sys/kernel/core_pattern
- 35.echo "kernel.core_pattern=/var/cores/core.%e.%p.%t" | sudo tee -a /etc/sysctl.conf
- 36.
` - 37.Ensure ulimit allows core dumps:
- 38.```bash
- 39.ulimit -c
- 40.# If 0, enable unlimited:
- 41.ulimit -c unlimited
- 42.# For systemd services, add to unit file:
- 43.# [Service]
- 44.# LimitCORE=infinity
- 45.
` - 46.Extract a coredump from systemd-coredump for analysis:
- 47.```bash
- 48.# List available coredumps
- 49.coredumpctl list
# Get the latest coredump for a specific executable coredumpctl dump /usr/bin/myapp -o /tmp/myapp.core
# Analyze with gdb gdb /usr/bin/myapp /tmp/myapp.core (gdb) bt ```
Prevention
- Configure
Storage=externalin coredump.conf to always save core dumps - Set adequate
ExternalSizeMaxandProcessSizeMaxlimits (at least 1GB) - Monitor
/var/lib/systemd/coredump/directory size and implement rotation - Include core dump configuration validation in server provisioning scripts
- For containers, mount the host's core_pattern pipe handler or configure direct file writing