Enable Kernel Crash Dump on Ubuntu Linux

In this tutorial, we want to teach you to Enable Kernel Crash Dump on Ubuntu Linux. An Ubuntu Linux Kernel Crash Dump service lets you configure your system to dump whatever is in RAM (memory) to disk. This will happen when the execution of the Linux kernel is halted or crashed.

You can follow the steps below to install, enable, and configure the Linux kernel crash dump on Ubuntu versions 20.04, and 22.04.

Learn To Enable Kernel Crash Dump on Ubuntu Linux

To complete this guide, you must have access to your server as a non-root user with sudo privileges. For this purpose, you can visit the Ubuntu initial guides:

Initial server setup with Ubuntu 20.04

Initial Server Setup with Ubuntu 22.04

Now follow the steps below to complete this guide.

Step 1 – Install Kernel Crash Dump Packages on Ubuntu

First, you must run the system update by using the following command:

sudo apt update

Then, use the following command to install kernel crash dump packages:

sudo apt install kdump-tools crash kexec-tools makedumpfile -y

During the kdump-tools installation, you will be asked if kdump-tools should handle the reboots. You must enter Yes and continue.

Then, you must enable it by choosing Yes.

When you are done, Verify your configurations by running the following commands:

sudo grep USE_KDUMP /etc/default/kdump-tools
Output
# USE_KDUMP - controls kdump will be configured
USE_KDUMP=1

As shown above, USE_KDUMP must be set to value 1.

sudo grep LOAD_KEXEC /etc/default/kexec
Output
LOAD_KEXEC=true

And your LOAD_KEXEC must be shown the true value.

Step 2 – Check the Current Crash Kernel Status on Ubuntu

At this point, you must run the following command to check the kdump status to see whether the crash dump is enabled or not:

sudo kdump-config show
Output
 * no crashkernel= parameter in the kernel cmdline
DUMP_MODE:              kdump
USE_KDUMP:              1
KDUMP_COREDIR:          /var/crash
crashkernel addr:
   /var/lib/kdump/vmlinuz
kdump initrd:
   /var/lib/kdump/initrd.img
current state:    Not ready to kdump

kexec command:
  no kexec command recorded

As you can see from the output, the dump crash service is not enabled.

Step 3 – How Do I Enable Crash Dump in Ubuntu?

To enable the crash kernel dump, you must reboot your server after making the above configuration. To do this, run the command below:

sudo systemctl reboot

Then, log in back to your Ubuntu server and check the kdump status again with the following command:

sudo kdump-config show

In your output, you should see:

Output
DUMP_MODE:              kdump
USE_KDUMP:              1
KDUMP_COREDIR:          /var/crash
crashkernel addr: 0xb3000000
   /var/lib/kdump/vmlinuz: symbolic link to /boot/vmlinuz-5.15.0-46-generic
kdump initrd:
   /var/lib/kdump/initrd.img: symbolic link to /var/lib/kdump/initrd.img-5.15.0-46-generic
current state:    ready to kdump

kexec command:
  /sbin/kexec -p --command-line="BOOT_IMAGE=/boot/vmlinuz-5.15.0-46-generic root=UUID=4d1266d2-c1f9-4087-af92-2d60c8c153e4 ro net.ifnames=0 biosdevname=0 netcfg/do_not_use_netplan=true reset_devices systemd.unit=kdump-tools-dump.service nr_cpus=1 irqpoll nousb" --initrd=/var/lib/kdump/initrd.img /var/lib/kdump/vmlinuz

As you can see, the system is ready to kdump. Your crash dump service is enabled on your Ubuntu server.

Also, you can find core dumps in the /var/crash directory.

Step 4 – How To Verify Crash Kernel is Configured on Ubuntu?

At this point, you can check for Crash Kernel Parameter on your server by running the following command:

sudo cat /proc/cmdline
Output
BOOT_IMAGE=/boot/vmlinuz-5.15.0-46-generic root=UUID=4d1266d2-c1f9-4087-af92-2d60c8c153e4 ro net.ifnames=0 biosdevname=0 netcfg/do_not_use_netplan=true crashkernel=512M-:192M

The highlighted line crashkernel=512M-:192M means:

  1. If the RAM size is smaller than 512M, then don’t reserve anything (this is the “rescue” case).
  2. And If the RAM size is between 512M and 2G (exclusive), then reserve 64M ram.
  3. If the RAM size is larger than 2G, then reserve 192M ram for dumps.

Also, you can use the following command to list the requested memory area for the kdump kernel on Ubuntu:

sudo dmesg | grep -i crash
Output
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.15.0-46-generic root=UUID=4d1266d2-c1f9-4087-af92-2d60c8c153e4 ro net.ifnames=0 biosdevname=0 netcfg/do_not_use_netplan=true crashkernel=512M-:192M
[    0.018869] Reserving 192MB of memory at 2864MB for crashkernel (System RAM: 4095MB)
[    0.115585] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-5.15.0-46-generic root=UUID=4d1266d2-c1f9-4087-af92-2d60c8c153e4 ro net.ifnames=0 biosdevname=0 netcfg/do_not_use_netplan=true crashkernel=512M-:192M

That’s it, you are done. For more information, you can visit Ubuntu Kernel Crash Dumps Docs.

Conclusion

At this point, you have learned to install kernel dumps packages and enable Kernel Crash Dump on Ubuntu Linux. Hope you enjoy it. You may be interested in these articles on the Orcacore Blog page:

Install MariaDB 10.11 on Ubuntu 20.04

Fix Exceeded LOCALRELAY limit* Error

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!