22

I tried to update my grub config file to timeout to 0 value, so OS starts quickly. I modified /etc/default/grub configuration file on my Ubuntu 18.04 and then ran:

sudo update-grub

and it didn't work. I also ran:

sudo grub-mkconfig
sudo update-grub

but they didn't work.

I searched a lot on the web to solve this issue, but all guides say to run the update-grub command to update grub by /etc/default/grub config file. I don't know if is Ubuntu 18.04 that handles grub files in a different way, but I cannot update my grub with my parameters.

This is my /etc/default/grub file:

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

# 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"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
Melebius
  • 11,431
  • 9
  • 52
  • 78
Bob91
  • 1,172
  • 3
    Please edit your question and include your modified grub config file. Otherwise we're just trying to guess what you did. – Organic Marble May 14 '18 at 12:04
  • Do you have other distributions installed (dual boot)? – mook765 May 14 '18 at 12:22
  • it didn't work mean that my grub timeout is still set to 10 sec as by default @Melebius – Bob91 May 14 '18 at 12:27
  • I have windows in the same ssd and other distros installed on other hdd, but last month i had fedora 27 (instead of ubuntu 18) and it worked when i changed grub config file, so i think the other distros aren't the causes of this behavior @mook765 – Bob91 May 14 '18 at 12:35
  • @Bob91 Sounds like you run update-grub in the wrong distribution. Or, if installed in legacy-mode, you boot to the wrong drive. Installing multiple Linux-distribution can lead to confusion when it comes to the boot-loader (Grub). I always install Grub in only one distro, in additional distros I don't install Grub at all. – mook765 May 14 '18 at 12:51
  • The file in use is : /boot/grub/grub.cfg . Editing "/etc/defaults/grub file" does nothing. – Knud Larsen May 14 '18 at 15:00
  • @KnudLarsen The file /etc/default/grub is translated into /boot/grub/grub.cfg using the update-grub program. However, it might be actually useful if OP checked the /boot/grub/grub.cfg whether it gets updated. – Melebius May 15 '18 at 06:23
  • 1
    Could you please run Boot-Info and [edit] your question to include a link to its resulting info log? Thanks. – David Foerster May 15 '18 at 13:48
  • Do not change to 0. When later you need to get into grub, you will not be able to. Change to 3 sec or whatever is just long enough for you to press key to get grub menu when you have boot issues. – oldfred May 15 '18 at 15:25
  • @oldfred my problem is that i have bluetooth mouse and keyboard, so i can't access to grub options even if timeout is set to 10. – Bob91 May 15 '18 at 16:59
  • done ! @Melebius – Bob91 May 16 '18 at 13:04
  • A time out of 1 works for me. I have to have finger hovering over Escape key during boot if I need to change distro or kernel version. – WinEunuuchs2Unix May 23 '18 at 15:12
  • This question describes almost the same problem: https://askubuntu.com/questions/117525/hide-grub2-menu-unless-you-hold-down-shift-key-how-to-make-this-happen – mook765 May 23 '18 at 17:28
  • https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1273764 – mook765 May 23 '18 at 17:39

9 Answers9

18

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.

Melebius
  • 11,431
  • 9
  • 52
  • 78
Bob91
  • 1,172
  • 2
    work in the same way and almost like timeout that's because math in bash supports integers only. The shortest timeout that would make a difference is 1. – Marcin Orlowski Dec 03 '19 at 04:46
  • The GRUB manual says Set [GRUB_TIMEOUT] to '0' to boot immediately without displaying the menu, so this is either a patch added downstream by Ubuntu, or the GRUB project forgot to update their documentation. I'll have to set it to 1 instead, but it sucks. – Douglas Silva Oct 04 '23 at 04:22
  • I found more info. That conditional comes from the "os prober" module. If you don't need it, disable it with GRUB_DISABLE_OS_PROBER=true, then you can set timeout to zero. – Douglas Silva Oct 04 '23 at 04:31
10

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"
5

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.

Kalle Richter
  • 6,180
  • 21
  • 70
  • 103
guest
  • 51
  • Or you can do what @mook765 says and override the timeout in /etc/grub.d/40_custom instead, which is more correct because it's a file that is meant to be customized by the user. – Adrian Sep 26 '23 at 10:47
4

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.

  • 3
    You are right, but i think everytime you update grub (manually or when there are any os upgrade) the /boot/grub/grub.cfg will recreated with the condition above. – Bob91 May 24 '18 at 16:37
  • 2
    That is true, the file is overwritten on update, as I experienced recently. – asantas93 May 25 '18 at 17:20
1

Uncomment GRUB_HIDDEN_TIMEOUT=0 and run update-grub again.

Eliah Kagan
  • 117,780
hiigaran
  • 6,473
  • 4
  • 28
  • 40
1

We can simply add the line

set timeout=0

to /etc/grub.d/40_custom, make the file executable with

sudo chmod +x /etc/grub.d/40_custom

and run

sudo update-grub

to generate the new /boot/grub/grub.cfg-file. The set timeout-command we added is the last set timeout-command in /boot/grub/grub.cfg now, that is what counts.

mook765
  • 15,925
1

This behaviour is experienced in both Ubuntu 18.04 and 20.04 and even though some of the other answers has solutions that work as expected, either files that has on the header an "do not edit this file" notice such as the /boot/grub/grub.cfg are manually edited, or the changes are not persistent after system updates or regenerating grub configuration files (at least weren't for me). Here's a step by step of what I've been doing to change such behaviour in a persistent fashion.

Step 1 - Modify the template file /etc/grub.d/30_os-prober

Grub uses some template files located at /etc/grub.d in order to generate the /boot/grub/grub.cfg. Edit the file with your editor of choice...

# vim /etc/grub.d/30_os-prober

... and either comment or remove the lines below that override the timeout when it's set to zero.

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

Step 2 - Modify the file /etc/default/grub

Grub uses this file to set configuration values in order to generate the /boot/grub/grub.cfg. Edit the file with your editor of choice...

# vim /etc/default/grub

... and set the timeout for zero (use the second option if the GRUB_TIMEOUT_STYLE is set to hidden)

GRUB_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT=0

Step 3 - Generate the file /boot/grub/grub.cfg

# update-grub2

... and after the next machine reboot the expected behaviour is having a timeout of zero on grub menu.

  • Why commenting or removing the lines that set the timeout to 10 in /etc/grub.d/30_os-prober when you can edit it to set it to zero instead and save yourself from doing step 2? Or even better, instead of editing this file, edit /etc/grub.d/40_custom as @mook765 suggests – Adrian Sep 26 '23 at 10:56
0

You can set GRUB_TIMEOUT to -1.

Ex:GRUB_TIMEOUT="-1"

Sss
  • 1,022
  • 1
    'GRUB_TIMEOUT' Boot the default entry this many seconds after the menu is displayed, unless a key is pressed. The default is '5'. Set to '0' to boot immediately without displaying the menu, or to '-1' to wait indefinitely. from command info -f grub -n 'Simple configuration – Vijay Feb 20 '19 at 14:10
  • @GiceuCassiano your solution is the complete opposite of setting the timeout to zero because -1 waits forever until the user selects an option. It is therefore as if you specified infinity. – Adrian Sep 26 '23 at 10:50
-1

The solution is to add

GRUB_RECORDFAIL_TIMEOUT=0

to /etc/default/grub.

All other solutions will be reset on grub updates.

Pilot6
  • 90,100
  • 91
  • 213
  • 324
  • This solution works when the timeout is set to 30 seconds because the 30 seconds timeout comes from the default value of GRUB_RECORDFAIL_TIMEOUT, which is used when the first attempt to boot fails if I recall correctly (I might be wrong). Also, not all other solutions will be reset on grub updates. – Adrian Sep 26 '23 at 11:00