修改grub选项

 修改 /boot/grub/menu.lst 文件,使其中default值变动一下即可。
过程如下:

1、 打开命令行终端;
2、输入:
 cp /boot/grub/menu.lst /boot/grub/menu.lst.bak
 vi /boot/grub/menu.lst
注: 要使用root。
3、假设文件内容如下:
-------------------------------------------------------------
# menu.lst - See: grub(8), info grub, update-grub(8)
# grub-install(8), grub-floppy(8),
# grub-md5-crypt, /usr/share/doc/grub
# and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default 0

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 10

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

.
.
.

## ## End Default Options ##

title Ubuntu, kernel 2.6.15-23-386
root (hd0,2)
kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hda3 ro quiet splash
initrd /boot/initrd.img-2.6.15-23-386
savedefault
boot

title Ubuntu, kernel 2.6.15-23-386 (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hda3 ro single
initrd /boot/initrd.img-2.6.15-23-386
boot

title Ubuntu, memtest86+
root (hd0,2)
kernel /boot/memtest86+.bin
boot

### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
title Other operating systems:
root


# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/hda1
title Microsoft Windows XP Professional
root (hd0,0)
savedefault
makeactive
chainloader +1
-------------------------------------------------------------
现在default值为0,意即启动排行第一的操作系统,这里代表的就是Ubuntu。
现在把它修改成“default 4”,那么XP就成为默认的操作系统了。
因为从零数起,以title打头的Microsoft Windows XP Professional这一行排序为4。
另外通过修改timeout的值来变更默认等待时间
### 如何在 Ubuntu修改 GRUB 配置文件以及更新 GRUB 引导菜单 #### 修改 GRUB 配置文件 GRUB 的主要配置文件位于 `/etc/default/grub`,这是用户可以手动编辑的核心文件之一。通过调整此文件中的参数,可以更改 GRUB 的行为和显示选项。 以下是常见的配置项及其作用: - `GRUB_TIMEOUT`: 设置引导菜单的等待时间(单位为秒)。如果将其设为 0,则会跳过菜单直接进入默认系统[^3]。 - `GRUB_DEFAULT`: 定义默认启动条目。可以是一个索引值(如 `0` 表示第一个条目),也可以是具体的菜单名称。 - `GRUB_CMDLINE_LINUX_DEFAULT`: 这里定义传递给内核的参数,默认情况下通常包含 `quiet splash`,表示静默模式和图形化的启动画面。 要编辑该文件,可以使用如下命令打开文本编辑器: ```bash sudo nano /etc/default/grub ``` 完成所需的更改后保存退出。 #### 更新 GRUB 引导菜单 当对 `/etc/default/grub` 文件进行了修改之后,必须执行以下命令以应用更改到实际使用的 GRUB 配置中: 对于基于 BIOS 的系统: ```bash sudo update-grub ``` 这一步骤将会重新生成 `/boot/grub/grub.cfg` 或者类似的文件,并反映最新的设置变化[^1]。 如果是 UEFI 系统,可能还需要额外注意 EFI 分区上的相关路径情况[^4]。 #### 特殊场景下的注意事项 有时可能会遇到只读文件系统的情况,在这种情形下需要先将根分区改为可写状态才能继续操作。具体方法可通过运行下面这条指令实现: ```bash sudo mount -o remount,rw / ``` 这样就能确保能够正常保存所做的改动[^5]。 另外需要注意的是某些高级功能比如移除不必要的内核版本或是定制化主题等则建议借助专门工具如 Grub-Customizer 来简化流程。 ### 示例代码片段 假设想让 GRUB 菜单一直可见而不是自动隐藏,可以把超时时间延长至无限期并且禁用快速启动特性: ```bash # 编辑配置文件 sudo nano /etc/default/grub # 更改下列两行内容 GRUB_TIMEOUT=-1 # 设定无限制的时间延迟 GRUB_HIDDEN_TIMEOUT= # 清空此项取消隐匿倒计时逻辑 # 应用新设定 sudo update-grub ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值