How to increase dmesg log size to capture more verbose booting logs in CentOS/RHEL 7

Question: How do we capture debugging information from systemd during early boot issues?

To avoid losing boot messages, the kernel log buffer must be a large enough size to contain all the boot messages up until the point the system is able to write the log to permanent storage. This is especially true if additional logging is enabled; for example by removing quiet from the boot line or setting log_level=debug - or you have a large number of storage devices.

If the kernel log buffer is not large enough, the oldest messages during boot will be lost, overwritten by the latest messages. Follow the steps outlined below to increase the dmesg log size during booting.

1. Increase the verbosity of the boot process by appending the following to the kernel boot parameter line:

systemd.log_level=debug systemd.log_target=kmsg log_buf_len=15M

2. Once the issue has been reproduced, via booting into single user mode, or using a dracut boot breakpoint (See man dracut.cmdline for more details), the additional systemd debug output can be retrieved via the dmesg command.

$ dmesg > /tmp/$HOSTNAME.dmesg.out

Making the change persistently

1. Append the above to the end of the GRUB_CMDLINE_LINUX entry within the /etc/sysconfig/grub configuration file:

# cat /etc/sysconfig/grub
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --speed=115200"
GRUB_CMDLINE_LINUX="console=tty0 crashkernel=auto console=ttyS0,115200 systemd.log_level=debug systemd.log_target=kmsg log_buf_len=15M"

2. Update the GRUB configuration using the grub2-mkconfig utility:

# grub2-mkconfig -o /boot/grub2/grub.cfg

Alternatively, on UEFI systems, run the following:

# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg