如何删除 GRUB 菜单中的“Ubuntu 高级选项”?

如何删除 GRUB 菜单中的“Ubuntu 高级选项”?

如何在 GRUB 菜单中删除“Ubuntu 高级选项”?

这是我在 GRUB 菜单中看到的内容:

Ubuntu 
Advanced Options for Ubuntu 
OpenSUSE 
Advanced Options for OpenSUSE 
CentOS 
Advanced Options for CentOS

我希望我的 GRUB 看起来像:

Ubuntu
OpenSUSE
CentOS

我正在使用这些命令来删除 memtest86:

sudo chmod -x /etc/grub.d/20_memtest86+
sudo update-grub

并且它可以运行,但我找不到任何命令来删除高级选项菜单。

答案1

这可以在 GUI 中使用 来完成grub-customizer

打开程序后,它将显示当前的菜单选项集:

在此处输入图片描述

右键单击菜单行将允许您上下移动该行、重命名菜单项或删除菜单项以满足您的需要。

可以通过 PPA 获取 Grub-Customizer,网址为:https://launchpad.net/~danielrichter2007/+archive/ubuntu/grub-customizer

答案2

好的,诀窍是编辑/etc/grub.d/10_linux文件,删除在 grub 菜单中生成该选项的正确模板条目:

 # TRANSLATORS: %s is replaced with an OS name
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {" 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
is_top_level=false
  fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%linux_entry "${OS}" "${version}" advanced \
%              "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
%  for supported_init in ${SUPPORTED_INITS}; do
%    init_path="${supported_init#*:}"
%    if [ -x "${init_path}" ] && [ "$(readlink -f /sbin/init)" != "${init_path}" ]; then
%      linux_entry "${OS}" "${version}" "init-${supported_init%%:*}" \
%         "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} init=${init_path}"
%    fi
%  done
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
    linux_entry "${OS}" "${version}" recovery \
                "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
  fi

  list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
done
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%# If at least one kernel was found, then we need to       
%# add a closing '}' for the submenu command.              
%if [ x"$is_top_level" != xtrue ]; then                    
%  echo '}'                                                   
%fi                                                        
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo "$title_correction_code"

现在请注意%使用的字符,我用它们包围了应该从该文件中删除的行,以使Advanced options for Ubuntugrub 菜单不显示,它们不是原始文件的一部分。这些行存在于345该文件中。再次,应删除该外壳内的所有内容,并与您自己的10_linux文件进行比较

编辑后打开/etc/default/grub文件并添加以下行:

GRUB_DISABLE_RECOVERY=true

现在运行sudo update-grub

酸性测试

运行sudo update-grub,如果输出正常并且您可以看到启动映像,那么很可能没问题,但请备份并注意下面提到的警告。

警告

仔细编辑,我建议几种方法:

  1. 编辑前请先备份
    • 然后编辑该备份副本并确保它与我这里的一样。
  2. 先使用虚拟机进行测试。
  3. 在虚拟机上测试

前:

在此处输入图片描述

后:

在此处输入图片描述

答案3

我删除了高级选项...通过添加线条

 GRUB_DISABLE_RECOVERY="true"
 GRUB_DISABLE_SUBMENU=y

在文件中/etc/default/grub,然后运行

sudo update-grub

相关内容