Vivian Voss

dumpon Needs No Second Kernel

like for like freebsd dumpon kernel

Near the end of a FreeBSD installation there is a screen with a list of services, and most people press Enter on it without reading. sshd is ticked, moused is not, and at the very bottom sits a line that is ticked already: "Enable kernel crash dumps to /var/crash". On FreeBSD 15.1 the installer reads that box with ${dumpdev:-on}, so unless someone has said otherwise the answer is yes, and it writes a single line into /etc/rc.conf:

dumpdev="AUTO"

That line is the whole arrangement. Should the kernel ever panic, the machine will have recorded what it was doing, and the record will be waiting in a directory after the reboot, with nothing else installed and nothing held in reserve for it.

What the tick box sets in motion

AUTO means the first swap partition in /etc/fstab. The start script /etc/rc.d/dumpon looks it up and hands it to the kernel early in the boot, and the comment above that step gives the reason: "Enable it early so a crash early in the boot process can be caught." If the swap is encrypted with GELI, the script points at the raw partition underneath and says out loud what that means: "Kernel dumps will be written to the swap partition without encryption." (There is a remedy for that, and it comes further down.)

Swap is the right place for a reason the manual of dumpon(8) puts in one sentence: "Because the file system layer is already dead by the time a crash dump is taken, it is not possible to send crash dumps directly to a file." So the kernel writes to the device itself. In kern_shutdown.c it walks its list of configured dump devices, TAILQ_FOREACH(di, &dumper_configs, di_next), and stops at the first one that takes the dump. Each disk driver carries a small routine for exactly this moment; the one for SATA disks is called adadump(), and it sends plain write commands to the disk without asking the filesystem or the scheduler for anything. What it writes is a minidump, which "hold only memory pages in use by the kernel", so a server with 256 GiB of RAM, most of it full of application data, writes the part a kernel developer will actually read.

The next boot does the filing. Once the filesystems are mounted, /etc/rc.d/savecore checks the device and copies the dump to /var/crash/vmcore.0, with a summary in info.0. Then crashinfo runs, which rc.conf enables by default, and writes core.txt.0: the backtrace, the process list, the kernel's memory statistics, the message buffer, open files and network state, all in plain text, ready for the morning. For the backtrace it asks for one thing from the package collection (pkg install gdb), and without it crashinfo says so and stops ("Unable to find a kernel debugger."), which is about as polite as a crash report gets.

One line in rc.conf, and the dump files itself Installer box ticked dumpdev="AUTO" Boot rc.d/dumpon first swap, set early Panic walks its dump list driver writes minidump Reboot rc.d/savecore vmcore.0 and info.0 Report crashinfo core.txt.0 No memory reserved, no second kernel loaded; the backtrace in core.txt uses gdb from packages

The spare kernel

The Linux habit trusts a panicked kernel with nothing at all. Its state, by definition, is something nobody can vouch for, so kdump does not ask it to write anything. "Kdump uses kexec to quickly boot to a dump-capture kernel", in the words of the kernel's own documentation, and "The system kernel's memory image is preserved across the reboot and is accessible to the dump-capture kernel." The fresh kernel then copies the old memory out at leisure, filtered by makedumpfile, which with -d 31 "will only write out kernel data", much as a minidump does.

The fresh kernel has to live somewhere, and it has to be loaded before anything goes wrong. "When the system kernel boots, it reserves a small section of memory for the dump-capture kernel," so that "ongoing Direct Memory Access (DMA) from the system kernel does not corrupt the dump-capture kernel." The size of that small section is set on the kernel command line, and the distributions set it on a sliding scale. Ubuntu's documentation prints its default:

crashkernel=2G-4G:320M,4G-32G:512M,32G-64G:1024M,64G-128G:2048M,128G-:4096M

"if the RAM size is larger than 128G, then reserve 4096M". The RHEL family reserves 256 MiB from 2 GiB upwards and 512 MiB from 64 GiB (2G-64G:256M,64G-:512M in kdump-lib.sh of kdump-utils), and Debian's kdump-tools asks for crashkernel=512M-:192M, so every Linux server with kdump begins its day a few hundred megabytes short. On a 256 GiB Ubuntu host, then, four gibibytes sit idle from the first second of uptime, which is a modest virtual machine's worth of memory kept on standby for an event the administrator hopes never comes.

Memory held back for the crash dump, by installed RAM 0 MiB 1024 MiB 2048 MiB 3072 MiB 4096 MiB 2 GiB 4 GiB 8 GiB 16 GiB 32 GiB 64 GiB 128 GiB 256 GiB installed RAM Ubuntu kdump, up to 4096 MiB RHEL family, up to 512 MiB Debian kdump-tools, 192 MiB FreeBSD dumpon, 0 MiB

Ubuntu has switched kdump on by default since 24.10, but only where the machine passes a test at installation time: "at least 6GB of RAM, and less than 2TB of RAM", at least four CPU threads, and free space in /var that "is more than 5 times the amount of RAM and swap space". Debian leaves it to whoever installs the package. Changing the reservation means editing a file under /etc/default/grub.d/, then "run sudo update-grub, reboot afterwards, and then test again", and the same page warns that a reservation sized too small can cause "the dump to fail due to an 'out of memory'" error. It works, mind, at the price of a second kernel and a slice of memory kept on standby all year, so that the first kernel never has to clear up after itself.

What comes with the line

On FreeBSD the extras arrive with the same tool, and the GENERIC kernel of 15.1 is built with every option they need (EKCD, ZSTDIO, GZIO, NETDUMP).

The dump can be encrypted. With dumpon -k public.pem, "A random, one-time symmetric key is automatically generated" each time, the dump is written with chacha20, and only the holder of the private key can read it; this is the remedy promised above for the encrypted swap. -Z compresses with zstd on the way out. The dump can leave the machine altogether: netdump(4), in the base system since FreeBSD 12.0, sends it to a server on the network and "eliminates the need to reserve space for crash dumps". Since 13.0 the devices form a list, and the kernel loop quoted above works through it in order, which lets netdump go first with the local swap behind it. And savecore -L takes a dump of the running system without a panic, should one wish to look before anything has gone wrong.

Every piece of that chain, from the installer's tick box through rc.d, the kernel, the disk driver and savecore to crashinfo, comes out of one source tree and is released together, so the line in rc.conf means the same thing on every machine of the same release.

The difference

Like for Like             Ubuntu, RHEL family, Debian         FreeBSD 15.1
                          kdump                               dumpon, savecore
Who writes the dump       a second kernel, via kexec          the panicked kernel, on a short
                                                              path of its own
Memory held back          192 MiB to 4 GiB, from boot on      none
Switched on               Ubuntu on qualifying machines,      installer box, ticked
                          RHEL with the kdump service,        by default
                          Debian by package
Changing it               update-grub, reboot, test           one line in rc.conf
Dump over the network     scp from the second kernel          netdump(4), in base
Encrypted dump            onto an encrypted volume,           dumpon -k, in base
                          x86_64 only (CRASH_DM_CRYPT)
Report after reboot       vmcore, crash tool for analysis     core.txt from crashinfo

Both sides end up with a dump in /var/crash, and the rows above show what each of them keeps ready for it beforehand.

The limit

A dump to disk needs a working disk driver. FreeBSD's dump runs in the kernel that panicked, along a short path that needs neither the filesystem nor the scheduler, only the driver. Should the disk driver itself have come a cropper and caused the panic, the dump to disk may be lost. FreeBSD covers that case with the fallback list: netdump first, so the dump leaves through the network card, and the disk second.

The swap has to hold the minidump. Its size follows what the kernel had in use at the time, and with compression switched on dumpon "cannot verify that the device has sufficient space for a dump". On a server with a small swap and a busy kernel, one glance at swapinfo settles the matter.

The backtrace wants gdb. crashinfo needs the package, and the manual says so plainly; savecore alone still saves the dump and its summary.

The encryption keeps secrets and proves nothing. The manual states that the scheme "does not provide integrity nor authentication", so an encrypted dump is private, though its recipient cannot prove where it came from.

A server that writes down its own last words needs nobody standing by to take dictation.