How to set GRUB timeout to 0 on Ubuntu 18.04

In /boot/grub/grub.cfg file there is a condition, almost at the end of the file, that sets the timeout to 10 if the timeout is set to 0. In other words, if you set the timeout to 0 in your /etc/default/grub and then update grub, the condition above reset it to 10 seconds.

if [ "${timeout}" = 0 ]; then
     set timeout=10
fi

However, /boot/grub/grub.cfg is a read-only file and I cannot remove that condition. I made some tests with different values of the timeout in /etc/default/grub. I tried with 1ms (0.001), 0.1s and 1s and I found out that values below 1 (like 0.1 and 0.001) work in the same way and almost like timeout set to 0.


In my case, the problem was that my system didn't support "recordfail" which caused a separate block to get added to the grub.cfg which defaults to a timeout of 30 seconds. The relevant code in /etc/grub.d/00_header:

if [ "$recordfail_broken" = 1 ]; then
  cat << EOF
if lsefi; then
  set timeout=${GRUB_RECORDFAIL_TIMEOUT:-30}
  if [ x\$feature_timeout_style = xy ] ; then
    set timeout_style=menu
  fi
fi
EOF

The fix is simply to add a value for GRUB_RECORDFAIL_TIMEOUT in /etc/default/grub and run update-grub again. For example:

GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""

# Adjusted timeout for system which doesn't support recordfail
GRUB_RECORDFAIL_TIMEOUT=2

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

You can set GRUB_TIMEOUT to 0.

The part overwriting timeout value is written in ajust_timeout function in the top of /etc/grub.d/30_os-prober.

ajust_timeout () {
...
if [ "\${timeout}" = 0]; then
  set timeout=10
fi
...
}

So, you can set the value by editing the file and comment out if-block.


Like the other answers say, uncomment GRUB_HIDDEN_TIMEOUT and run update-grub. Then comment out the

if [ "${timeout}" = 0 ]; then
  set timeout=10
fi

section in /boot/grub/grub.cfg. In vim you can just override the read-only property with an exclamation point :x!. Or you can run

sudo chmod +w /boot/grub/grub.cfg
sudo vim /boot/grub/grub.cfg
sudo chmod -w /boot/grub/grub.cfg

to temporarily have write permission while editing the file.


You can set GRUB_TIMEOUT to -1.

Ex:GRUB_TIMEOUT="-1"