修改grub2启动顺序

http://www.luckid.com/20100418336.html


皇天不负有心人,经过几个小时的资料学习和摸索,终于可以一劳永逸的搞定ubuntu 9.10的grub 启动顺序了。通过这个方法可以把其它系统的启动项改到最前面,这样就不怕linux 升级内核后把默认启动项打乱了。

经过grub2的资料学习,发现grub2是通过/etc/grub.d/目录下的文件顺序来决定启动项顺序的:

$cd /etc/grub.d
$ls -l

-rwxr-xr-x 1 root  root  3296 2009-10-24 08:44 00_header
-rwxr-xr-x 1 root  root  1154 2009-10-24 08:31 05_debian_theme
-rwxr-xr-x 1 root  root  3778 2009-10-24 08:44 10_linux
-rwxr-xr-x 1 root  root   772 2009-10-24 00:11 20_memtest86+
-rwxr-xr-x1 shawn shawn 5467 2010-04-17 23:52 30_os-prober
-rwxr-xr-x 1 root  root   214 2009-10-24 08:44 40_custom
-rw-r–r– 1 root  root   483 2009-10-24 08:44 README

30_os-prober是grub2自动生成的,因为我安装ubuntu linux 之前就有vista在电脑上。目录下有各README文件,打开查看里面的内容:

All executable files in this directory are processed in shell expansion order.

00_*: Reserved for 00_header.
10_*: Native boot entries.
20_*: Third party apps (e.g. memtest86+).

The number namespace in-between is configurable by system installer and/or administrator.  For example, you can add an entry to boot another OS as 01_otheros, 11_otheros, etc, depending on the position you want it to occupy in the menu; and then adjust the default setting via /etc/default/grub.

大意是:

该目录下的可以执行文件的顺序是按照shell扩展来排列的(就是按首字符排列的意思,用来配置grub的顺序)。

00_开头的文件是预留给00_header的
10_开头的用于系统本身
20_开头的用于第三方程序

可以新建和改变文件的顺序来配置gurb2的启动顺序。

知道以上这些就好办了。我们只要把30_os-prober的顺序设置到10_linux之前就可以让windows的选项在linux 之前。

运行以下命令把30_os-prober复制一份并且重命名为09_os-prober:

$sudo cp 30_os-prober 09_os-prober

然后去掉30_os-prober的可执行权限:

$sudo chmod 644 30_os-prober
$ls -l

-rwxr-xr-x 1 root  root  3296 2009-10-24 08:44 00_header
-rwxr-xr-x 1 root  root  1154 2009-10-24 08:31 05_debian_theme
-rwxr-xr-x 1 root  root  5467 2009-10-30 00:21 09_os-prober
-rwxr-xr-x 1 root  root  3778 2009-10-24 08:44 10_linux
-rwxr-xr-x 1 root  root   772 2009-10-24 00:11 20_memtest86+
-rw-r–r– 1 shawn shawn 5467 2010-04-17 23:52 30_os-prober
-rwxr-xr-x 1 root  root   214 2009-10-24 08:44 40_custom
-rw-r–r– 1 root  root   483 2009-10-24 08:44 README

然后打开/etc/default/grub把默认启动改成你要的那个:

$sudo gedit /etc/default/grub

找到GRUB_DEFAULT=,改后面的参数。(注意linux 的顺序是从0开始的哦),我设置为第一项vista,于是把默认改成噢0(GRUB_DEFAULT=0)

最后更新grub:

$sudo update-grub

[sudo] password for shawn:
Generating grub.cfg …
Found Windows Vista (loader) on /dev/sda1
Found Windows Vista (loader) on /dev/sda3
Found linux image: /boot/vmlinuz-2.6.31-21-generic
Found initrd image: /boot/initrd.img-2.6.31-21-generic
Found linux image: /boot/vmlinuz-2.6.31-20-generic
Found initrd image: /boot/initrd.img-2.6.31-20-generic
Found memtest86+ image: /boot/memtest86+.bin
done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值