如何在 Ubuntu 18.04 上将 GRUB 超时设置为 0

Bob*_*b91 17 boot grub2 18.04

我试图将我的 grub 配置文件更新为超时值为 0,因此操作系统启动很快。我/etc/default/grub在 Ubuntu 18.04 上修改了配置文件,然后运行:

sudo update-grub
Run Code Online (Sandbox Code Playgroud)

它没有用。我也跑了:

sudo grub-mkconfig
sudo update-grub
Run Code Online (Sandbox Code Playgroud)

但他们没有工作。

我在网上搜索了很多来解决这个问题,但所有指南都说运行 update-grub 命令来通过/etc/default/grub配置文件更新 grub 。我不知道 Ubuntu 18.04 是否以不同的方式处理 grub 文件,但我无法用我的参数更新我的 grub。

这是我的/etc/default/grub文件:

# 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"
Run Code Online (Sandbox Code Playgroud)

Bob*_*b91 18

/boot/grub/grub.cfg文件中有一个条件,几乎在文件的末尾,如果超时设置为 0,则将超时设置为 10。换句话说,如果您将超时设置为 0 /etc/default/grub,然后更新 grub,则上述条件将其重置为 10 秒。

if [ "${timeout}" = 0 ]; then
     set timeout=10
fi
Run Code Online (Sandbox Code Playgroud)

但是,/boot/grub/grub.cfg是只读文件,我无法删除该条件。我在/etc/default/grub. 我尝试了 1ms (0.001)、0.1s 和 1s,我发现低于 1 的值(如 0.1 和 0.001)以相同的方式工作,几乎就像超时设置为 0。

  • “以同样的方式工作,几乎像超时”,这是因为 bash 中的数学仅支持整数。能产生影响的最短超时是“1”。 (2认同)

小智 10

就我而言,问题是我的系统不支持“记录失败”,这导致将单独的块添加到 grub.cfg 中,默认超时为 30 秒。中的相关代码/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
Run Code Online (Sandbox Code Playgroud)

修复方法只是为GRUB_RECORDFAIL_TIMEOUTin添加一个值/etc/default/grubupdate-grub再次运行。例如:

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"
Run Code Online (Sandbox Code Playgroud)


小智 5

您可以设置GRUB_TIMEOUT0.

覆盖超时值的部分写在ajust_timeout函数顶部/etc/grub.d/30_os-prober

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

因此,您可以通过编辑文件并注释掉 if-block 来设置该值。


hii*_*ran 1

取消注释GRUB_HIDDEN_TIMEOUT=0update-grub再次运行。