Stuck on boot-menu after restart on Ubuntu 12.04.3 LTS / GRUB 1.99-21ubuntu3.10


The problem:

In some cases when you restart / reboot your ubuntu server it is not boot up again. When you check it on your cloud or physically with display, you can see that it stuck on boot-menu (GRUB). The state is the same like when you interrupt automatic boot by pressing one key. It is an unwanted behavior uncommonly when your host is a physical server, which could generate outage & very bad customer feedback. In here you can find discussion about the same problem.



The reason:

On this GRUB-version (and earlier versions, I don’t know exactly, maybe newer versions are also affected) if last boot was failed, GRUB prevent to boot automatically on next time (in failure case, it will be waiting infinitely, defined by “-1” on GRUB configuration file). So manual task required (hit ENTER) to boot.

In my case somebody restarted the ubuntu VM, and force-restart it again as the boot-time was too long. But what he didn’t know is meantime fsck checked file-system. So this scenario generated unsuccessfully boot, which on next boot stucked GRUB on os-choose menu with infinity loop.

Check that you system is affected:

For me the simplest way to re-produce was a fresh-installed Ubuntu 12.04.3 LTS on my VirtualBox. After that I leaved everything in default state. First, I checked the normal-behavior (I leaved it to boot up automatically) then I generated with VirtualBox an unexpected restart (“machine” tab -> “Reset”). After that I stucked on GRUB-menu infinity loop.

Fix of it:

More possibilities are available, now I will explain one tested, working solution for it:

Make backup from “/etc/grub.d/00_header”

mkdir -p /root/backup_GRUB; cd /root/backup_GRUB; cp -a /etc/grub.d/00_header ./; pwd; ll

Edit “/etc/grub.d/00_header”‘s this part:

if [ "\${recordfail}" = 1 ]; then
  set timeout=${GRUB_RECORDFAIL_TIMEOUT:--1}
  set timeout=${2}

If “recordfail” was detected (so last boot was unsuccessfully or system was shut down incorrectly), timeout value will be equal with “GRUB_RECORDFAIL_TIMEOUT” value, which is declared as infinity loop “:–1”


if [ "\${recordfail}" = 1 ]; then
  set timeout=${GRUB_RECORDFAIL_TIMEOUT:-2}
  set timeout=${2}

You can change it to an another variable or any other positive number. With this value you will set timeout to two seconds.

IMPORTANT STEP: you must to apply new settings with the following command.


Additional information:

It is not recommended that edit manually files under “/etc/grub.d/”, as these files are managed by GRUB! But because this problem is a GRUB-bug, this way is necessary. Also true if you update / upgrade GRUB version, your edited file will be overwritten, but theoretically this problem was fixed on further GRUB versions.

Keep in mind that when you run the last step (update-grub), please be sure that no any bootable device connected to your host as GRUB will add it while scanning & applying configurations.

Leave a Reply