如何在Ubuntu 18.04上将GRUB超时设置为0
我试图将我的grub配置文件更新为超时为0的值,因此操作系统很快启动。 我修改了我的Ubuntu 18.04上的/etc/default/grub
配置文件,然后运行:
sudo update-grub
它不起作用。 我也跑了:
sudo grub-mkconfig sudo update-grub
但他们没有工作。
我在网上搜索了很多来解决这个问题,但是所有指南都说运行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"
在/boot/grub/grub.cfg
文件中,有一个条件,几乎在文件末尾,如果超时设置为0,则将超时设置为10.换句话说,如果在您的超时中将超时设置为0 /etc/default/grub
然后更新grub,上面的条件将其重置为10秒。
if [ "${timeout}" = 0 ]; then set timeout=10 fi
但是,/ /boot/grub/grub.cfg
是一个只读文件,我无法删除该条件。 我在/etc/default/grub
使用不同的超时值进行了一些测试。 我尝试了1ms(0.001),0.1s和1s,我发现低于1的值(如0.1和0.001)以相同的方式工作,几乎像超时设置为0。
取消注释GRUB_HIDDEN_TIMEOUT = 0并再次运行update-grub。
您可以将GRUB_TIMEOUT
设置为0
。
部分覆盖超时值写在/etc/grub.d/30_os-prober
顶部的ajust_timeout
函数中。
ajust_timeout () { ... if [ "\${timeout}" = 0]; then set timeout=10 fi ... }
因此,您可以通过编辑文件来设置值,并注释掉if-block。
像其他答案一样,取消注释GRUB_HIDDEN_TIMEOUT
并运行update-grub
。 然后评论出来
if [ "${timeout}" = 0 ]; then set timeout=10 fi
/boot/grub/grub.cfg
部分。 在vim中,您可以使用感叹号覆盖只读属性:x!
。 或者你可以跑
sudo chmod +w /boot/grub/grub.cfg sudo vim /boot/grub/grub.cfg sudo chmod -w /boot/grub/grub.cfg
在编辑文件时暂时具有写入权限。
您可以将GRUB_TIMEOUT
设置为-1
。
例如:
GRUB_TIMEOUT="-1"