无法减少 Grub 启动延迟

无法减少 Grub 启动延迟

我有一台戴尔笔记本电脑,在单个 320GB 硬盘上运行单个操作系统 Ubuntu Mate 15.10 和 GRUB,分区为/& /home。我想将默认 grub 启动延迟从 10 秒减少到最好是“0”。到目前为止,我尝试了其他地方建议的以下调整,无论是通过 Grub-Customizer 还是通过直接编辑,都没有成功。其他行保持不变。更改后,我每次/etc/default/grub都运行。Grub 启动延迟保持不变,为 10 秒。sudo update-grub

  • GRUB_TIMEOUT=”0”&GRUB_HIDDEN_TIMEOUT=”0”
  • GRUB_TIMEOUT=”0”&#GRUB_HIDDEN_TIMEOUT=”0”
  • GRUB_TIMEOUT=”0”&GRUB_HIDDEN_TIMEOUT=””
  • GRUB_TIMEOUT=”2”&GRUB_HIDDEN_TIMEOUT=”2”

请您建议如何解决此问题。谢谢。

我的新代码(经过建议的更改)/boot/grub/grub.cfg 的代码

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="Ubuntu"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}
function recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
else
  search --no-floppy --fs-uuid --set=root a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
else
  search --no-floppy --fs-uuid --set=root a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
fi
insmod gfxmenu
insmod png
set theme=($root)/boot/grub/themes/ubuntu-mate/theme.txt
export theme
if [ "${recordfail}" = 1 ] ; then
  set timeout=30
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=hidden
    set timeout=0
  # Fallback hidden-timeout code in case the timeout_style feature is
  # unavailable.
  elif sleep --interruptible 0 ; then
    set timeout=0
  fi
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
if background_color 60,59,55; then
  clear
fi

color_normal=light-gray/black

if [ -e ${prefix}/themes/ubuntu-mate/theme.txt ]; then
  insmod png
  theme=${prefix}/themes/ubuntu-mate/theme.txt
fi
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
    set gfxpayload="${1}"
    if [ "${1}" = "keep" ]; then
        set vt_handoff=vt.handoff=7
    else
        set vt_handoff=
    fi
}
if [ "${recordfail}" != 1 ]; then
  if [ -e ${prefix}/gfxblacklist.txt ]; then
    if hwmatch ${prefix}/gfxblacklist.txt 3; then
      if [ ${match} = 0 ]; then
        set linux_gfx_mode=keep
      else
        set linux_gfx_mode=text
      fi
    else
      set linux_gfx_mode=text
    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
export linux_gfx_mode
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-a2bdc1a5-f2fb-489d-adec-ba5a92514f0c' {
    recordfail
    load_video
    gfxmode $linux_gfx_mode
    insmod gzio
    if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
    else
      search --no-floppy --fs-uuid --set=root a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
    fi
    linux   /boot/vmlinuz-4.2.0-17-generic root=UUID=a2bdc1a5-f2fb-489d-adec-ba5a92514f0c ro  quiet splash $vt_handoff
    initrd  /boot/initrd.img-4.2.0-17-generic
}
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-a2bdc1a5-f2fb-489d-adec-ba5a92514f0c' {
    menuentry 'Ubuntu, with Linux 4.2.0-17-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.2.0-17-generic-advanced-a2bdc1a5-f2fb-489d-adec-ba5a92514f0c' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
        else
          search --no-floppy --fs-uuid --set=root a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
        fi
        echo    'Loading Linux 4.2.0-17-generic ...'
        linux   /boot/vmlinuz-4.2.0-17-generic root=UUID=a2bdc1a5-f2fb-489d-adec-ba5a92514f0c ro  quiet splash $vt_handoff
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initrd.img-4.2.0-17-generic
    }
    menuentry 'Ubuntu, with Linux 4.2.0-16-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.2.0-16-generic-advanced-a2bdc1a5-f2fb-489d-adec-ba5a92514f0c' {
        recordfail
        load_video
        gfxmode $linux_gfx_mode
        insmod gzio
        if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
        else
          search --no-floppy --fs-uuid --set=root a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
        fi
        echo    'Loading Linux 4.2.0-16-generic ...'
        linux   /boot/vmlinuz-4.2.0-16-generic root=UUID=a2bdc1a5-f2fb-489d-adec-ba5a92514f0c ro  quiet splash $vt_handoff
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initrd.img-4.2.0-16-generic
    }
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry 'Memory test (memtest86+)' {
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
    else
      search --no-floppy --fs-uuid --set=root a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
    fi
    knetbsd /boot/memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos1'
    if [ x$feature_platform_search_hint = xy ]; then
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
    else
      search --no-floppy --fs-uuid --set=root a2bdc1a5-f2fb-489d-adec-ba5a92514f0c
    fi
    linux16 /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

答案1

Grub 忽略零超时并设置为 10 秒

在您的系统中,/etc/default/grub您传递的是值“0”。Grub 会忽略零超时并将值重置为 10。要“欺骗”Grub,请传递值 0.0,但 Grub 测试时该值不等于 0。

将超时设置为零

在我的系统中/etc/default/grub,我设置了以下相关的线路:

#GRUB_DEFAULT=0 # Rather than option #1, we'll always default to last boot choice.
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
GRUB_HIDDEN_TIMEOUT=0.0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0.0

我使用不带双引号的值0.0来反映数值的使用方式。

注意第一行被注释掉了。这意味着 grub 不再默认为第一个菜单选项(在我的情况下是 Kernel 4.9.21),而是最后一个启动的选项(在我的情况下是 Kernel 4.4.0-72-generic,来自高级选项菜单

第二行和第三行确保您始终启动到上次选择的相同选项。

未出现菜单时更改启动选项

更好的方法是减少超时并提供强制菜单出现的选项。此方法如下所述:如何隐藏我的 GRUB 菜单,并让 Shift 或 esc 键在启动时显示隐藏的 GRUB 菜单

答案2

搜索/boot/grub/grub.conf字符串:

set timeout=10

如果你找到了它,周围的线条可能会帮助你找出问题所在。

编者注:最好不要/boot/grub/grub.conf手动编辑,因为它会时不时地被自动覆盖。

相关内容