Headless Ubuntu server machine sometimes stuck at GRUB menu
I have Ubuntu 10.10 Server installed on a single-board machine in a semi-embedded environment; no keyboard or screen, just SSH access to it.
So it's really frustrating when it occasionally boots up and gets stuck on the GRUB menu, waiting for a keystroke to select the first option.
How do I configure GRUB to under no circumstances wait for a keystroke?
Update #1: There is no menu.lst, since this is GRUB 2. But I do have an /etc/default/grub which is like so:
GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=2
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX=""
Update #2: I figured it out. On boots which follow unsuccessful boots, GRUB disables its own timeout. Since showing the menu makes a boot unsuccessful, this is an inescapable loop. This behaviour may be disabled by editing the /etc/grub.d/00_header file, and changing the make_timeout function:
make_timeout ()
{
echo "set timeout=0"
}
Now exit and re-run the grub configuration updater script:
sudo update-grub2
It makes no sense to me that this behaviour would be the default for Ubuntu Server, a product intended for machines accessed by console.
Solution 1:
For Ubuntu 12.04 LTS there is a specific option that can be set in /etc/default/grub
.
For example, if you want to have a 2 seconds timeout (thus avoiding hangs for unattended reboots) just add the following line in /etc/default/grub
:
GRUB_RECORDFAIL_TIMEOUT=2
Remember to run update-grub
after that...
Solution 2:
Here are instructions for Ubuntu 10.10, which are slightly different from prior versions. In file /etc/grub.d/00_header comment out the stupid check for a prior boot failure:
##if [ \${recordfail} = 1 ]; then
## set timeout=-1
##else
set timeout=${2}
##fi
Then update:
sudo update-grub
Be aware that if there is a second drive with Linux attached, grub2 will find it, and ask you at boot which one you want. Remove all extra drives before running "update-grub".
See also https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/797544
Solution 3:
I came across this deeply unpleasant design oversight with Ubuntu Server 9.10. Your fix has helped me enormously. I just wanted to point out that the fix needed for 9.10 is different as there is no "make_timeout ()" function in the same file.
For Ubuntu 9.10, go to the end of the same file (00_header) and change the following:
if [ \${recordfail} = 1 ]; then set timeout=-1 else set timeout=${GRUB_TIMEOUT} fi EOF
to
if [ \${recordfail} = 1 ]; then set timeout=${GRUB_TIMEOUT} else set timeout=${GRUB_TIMEOUT} fi EOF
As before, then run:
sudo update-grub2