Where a boot stops when it fails
Video 068 of 140 in Virtualization Foundations, in the unit “The boot sequence, end to end”. 4:29, with English and Hindi audio.
When a Linux server will not come up, the first question is where the boot stopped. The boot is a chain of stages, and each stage starts only when the one before it has finished. So one failure stops every stage after it. The last message on the screen points back to the stage that broke. This article gives you a map of the five stages, the typical failure at each one, and the commands that show the clues.
What you will learn
- A boot is a chain, so one failed stage stops every stage after it.
- The five stages are firmware, the boot loader, the kernel and initramfs, the other disks, and the services.
- Read the last message on the screen first, since it usually names the stage that failed.
- Name the stage first, then check the logs and settings for that stage only.
- The systemctl, journalctl and dmesg commands show the clues after a failed boot.
A chain breaks at one link
Each stage of the boot hands over to the next. A stage can start only when the one before it has finished its job.
So when one stage fails, the stages after it never run. The boot stops there, or drops into a small shell. The message on the last screen, or the place where the output stops, shows which stage failed. That is your first clue.
The five stages, in order
- Firmware finds a boot device. If it finds none, Linux never starts.
- The boot loader reads GRUB's settings and loads the kernel. If it cannot read them, you may see GRUB's own prompt instead of the menu.
- The kernel and initramfs find and mount the root disk. If a driver or the disk's name is wrong, they wait, then give up.
- systemd mounts the other disks listed in the fstab file. One wrong line there can stop the boot.
- systemd starts the services. A service that fails does not always stop the boot.
Finding the stage that broke
Start with the screen. Read the last message first, because it usually names the stage that failed.
Next, read the journal. It is systemd's log, and it can keep the messages of each boot when it is stored on disk.
Then name the stage first, and check the logs and settings for that stage only. Guessing across all the stages wastes time.
Reading the clues after a boot
Once the machine is up again, these commands show what went wrong. The first lists the failed units. The second shows the error messages from this boot. The third shows the same for the previous boot. The last shows the kernel's own recent errors and warnings.
Note: The previous boot is only available if the journal kept its messages.
Try it yourself
You need a shell on the Linux server after a failed boot. These four commands only read information, and they show the clues the boot left behind.
List the units that failed during this boot.
systemctl --failedWhat you should see: The units that failed during this boot. An empty list means none failed.
Show only the error messages from this boot.
journalctl -b -p errWhat you should see: Only the error messages from this boot.
Show the error messages from the previous boot, if the journal kept them.
journalctl -b -1 -p errWhat you should see: The same messages for the previous boot, if the journal kept it.
Show the last kernel errors and warnings.
dmesg --level=err,warn | tail -5What you should see: The last kernel errors and warnings, so you can see whether the disk driver complained.
Terms
- Root disk
- The disk that holds the system's files. The kernel must find it to finish the boot.
- fstab
- The file that lists the disks and folders that systemd attaches at boot.
- Journal
- systemd's log of messages. It can keep the messages of each boot when it is stored on disk.
Check yourself
Why do the stages after a failed one never run?
Each stage starts only when the one before it has finished, so a failed stage stops the chain there.
Where should you look first after a failed boot?
At the last message on the screen, which usually names the stage that failed. Then check the logs for that stage.
What does journalctl -b -p err show?
Only the error messages from this boot.
Previous: What systemd does at boot. Next: Process and thread: what is the difference?.