Sometimes not all log messages in /var/log/dmesg can be captured after Linux OS/kernel boots up because of too many block devices attached to the server. This post illustrates another way to record all bootup log messages besides configuring the serial console.
Basically kernel parameter “log_buf_len” can be configured to increase kernel log buffer size,
Name: log_buf_len, Set the size of the kernel log buffer.
Synopsis: log_buf_len= n [ KMG ]
Description: Set the size of the kernel’s internal log buffer. n must be a power of 2, if not, it will be rounded up to be a power of two. This value can also be changed by the CONFIG_LOG_BUF_SHIFT kernel configuration value.
For CentOS/RHEL 5,6
For CentOS/RHEL 5 and 6, “log_buf_len=8M” can be appended to kernel line for default boot kernel entry in /boot/grub/grub.conf.
For example, if the current kernel line is:
kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=/dev/mapper/vg_root-lv_root
Append the log_buf_len to this line to make it:
kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=/dev/mapper/vg_root-lv_root log_buf_len=8M
Reboot the system for the changes to take effect.
# shutdown -r now
Temporary Change
You may also change the log_buf_len value temporarily while booting the system. Follow the steps given below while booting the system:
1. Press e again to edit the kernel line.
2. Add log_buf_len=8M to the end of the kernel line, as shown in the examples above.
3. Press Enter to temporarily save the changes.
4. Press b to boot with the edited boot entry.
For CentOS/RHEL 7
For CentOS/RHEL 7, the same setting can be appended to “GRUB_CMDLINE_LINUX” line in /etc/default/grub:
# cat /etc/default/grub
GRUB_TIMEOUT=15
GRUB_HIDDEN_MENU_QUIET=false
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
GRUB_CMDLINE_LINUX="console=tty0 log_buf_len=8M"
GRUB_DISABLE_RECOVERY="true"
Then rebuild the grub.cfg which is used at boot using the below command:
# grub2-mkconfig -o /boot/grub2/grub.cfg
For EFI based systems, use the below command:
# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
Reboot the system
# shutdown -r now
Temporary Change
When booting the system, stop the boot process on the GRUB kernel selection screen by pressing an arrow key up or down.
1. Press e to edit the boot entry.
2. Use up and down arrows to select the kernel line with the vmlinuz file on it.
3. Press End to place the cursor on the end of that line.
4. Add log_buf_len=8M to the end of the kernel line, as shown in the examples above.
5. Press Ctrl+x to boot with the edited boot entry.