Understanding Memory Reservation for kdump on Red Hat Enterprise Linux

Today we’re going to talk about something that might seem like a boring topic at first glance memory reservation for kdump on Red Hat Enterprise Linux (RHEL). But trust us, it’s actually pretty cool and can save you from some serious headaches in case of system crashes.

So what is kdump? It’s a feature that allows RHEL to perform kernel crash dump analysis without requiring physical access to the server. This means you can diagnose issues remotely and get back up and running faster than ever before! But in order for this magic to happen, we need to reserve some memory for kdump during system boot.

Now, how to do that on RHEL 9 (or newer). To begin with open your favorite text editor or terminal and navigate to the GRUB configuration file: /etc/default/grub.x86_64. This is where we’ll add our custom crashkernel= value.

If you don’t have a custom value yet, let’s start with something simple reserving 192 MB of memory for kdump. Add the following line to your GRUB configuration file:

# This script is used to add a custom crashkernel value to the GRUB configuration file.

# First, we need to navigate to the GRUB configuration file, which is located at /etc/default/grub.x86_64.
# We will use the cd command to change our current directory to /etc/default and then use the nano command to open the grub.x86_64 file for editing.

cd /etc/default
nano grub.x86_64

# Now, we will add our custom crashkernel value to the GRUB_CMDLINE_LINUX variable.
# The original script only had the value, but we need to add the variable name as well.

GRUB_CMDLINE_LINUX="crashkernel=192M"

# This line reserves 192 MB of memory for kdump, which is used for debugging kernel crashes.
# It is important to have a custom crashkernel value to ensure enough memory is reserved for kdump to function properly.

# Finally, we will save the changes and exit the editor.
# In nano, we can do this by pressing Ctrl+X, then Y to confirm the changes, and Enter to save the file with the same name.

# The script is now complete and the custom crashkernel value has been added to the GRUB configuration file.

Save and close the file, then run this command to update grub:

# This script updates the grub configuration with a custom value for the crashkernel parameter.

# Use sudo to run the grubby command with root privileges.
sudo grubby --update-kernel ALL --args "crashkernel=<custom-value>"

# The --update-kernel flag specifies that the kernel configuration should be updated for all kernels.
# The ALL keyword indicates that the update should be applied to all kernels.
# The --args flag specifies the arguments to be added to the kernel configuration.
# The "crashkernel=<custom-value>" argument sets the value for the crashkernel parameter to the specified custom value.

Replace with your desired memory reservation. For example, if you want to reserve 1 GB of memory for kdump and have at least 4 GB of total system memory:

# This script sets the GRUB_CMDLINE_LINUX variable to reserve a specific amount of memory for kdump.

# The variable is set to "crashkernel=1G-4G", which reserves 1 GB of memory for kdump and requires at least 4 GB of total system memory.

GRUB_CMDLINE_LINUX="crashkernel=1G-4G" # Sets the variable to reserve 1 GB of memory for kdump and requires at least 4 GB of total system memory.

Or if you want to reserve 256 MB of memory for kdump when the total system memory is greater than or equal to 2 GB and less than or equal to 64 GB:


# Set the variable GRUB_CMDLINE_LINUX to include the crashkernel option
# This option reserves 256 MB of memory for kdump
# The value for crashkernel is set to 2G-64G, meaning it will only be enabled if the total system memory is between 2 GB and 64 GB
# The value for memory is set to 256M, meaning 256 MB will be reserved for kdump
GRUB_CMDLINE_LINUX="crashkernel=2G-64G:256M"

That’s it! Now, how to estimate the kdump size. This is important if you want to know how much space your crash dump file will require. To do this, execute the following command in a terminal:

# This script uses the makedumpfile command to estimate the size of a kdump file.
# It is important to know the size in order to allocate enough space for the crash dump.
# The command takes the memory usage from the /proc/kcore file as input.

# Execute the command in a terminal to get the estimated size.
makedumpfile --mem-usage /proc/kcore

This generates a memory usage report that helps you determine which pages are safe to exclude and what level of detail is required for your crash dump analysis. Pretty cool, right?

It might seem like a small thing at first glance, but trust us, it can save you from some serious headaches in case of system crashes.

SICORPS