4

I know I can run dmesg to look at boot errors. However, my system is failing to boot right now. It hangs indefinitely while trying to initialize hard drives. However, I can boot up into safe mode.

When I boot up in safe mode and look at dmesg it does not contain old boot messages. It just contains the boot messages from the current boot-up into safe mode.

How do I save the dmesg log (or any log for that matter) during the failed boot process so that I can view it when I log in to diagnose via save mode?

2 Answers 2

1

I'm not at a Ubuntu pc right now, but I'm trying to help out.

If I'm not mistaken boot logging is disabled by default.

In /etc/default/bootlogd set

BOOTLOGD_ENABLE=Yes

Now, each boot entries in /var/log/boot will be created in a file that's readable by root (so sudo is needed). If I'm not mistaken this log is rotated so you'll have older versions.

If that won't work or you're not in /etc/sudoers, you can also try to boot with a bootable usbdrive and check the bootlog after a failed boot or boot into safe mode and redirect dmesg into a file using the output redirection operator:

dmesg > bootmessages$(date +%Y%m%d).bak
1

You can use journalctl to look at previous boot logs, thusly:

journalctl -b -1 -e

will look at the previous boot. By varying the number, you can see earlier boot logs. Also journalctl --list-boots is handy to show when boot #N took place.

You can also ask journalctl about the disk's log messages:

jounalctl /dev/sda
2
  • From the man page: "-0 is the last boot, -1 the boot before last". Apr 24, 2021 at 18:09
  • This shows the previous SUCCESSFUL boot, not a failed one.
    – akaspick
    Mar 12 at 1:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .