Grub2 强大的引导程序,智能修复启动

简介: 偶然间发现ubuntu自9.10来就把grub2当作默认引导程序,而grub2的确功能强大。一直以来,人们都为安装linux和windows之后怎样修复启动而头疼。

偶然间发现ubuntu自9.10来就把grub2当作默认引导程序,而grub2的确功能强大。

一直以来,人们都为安装linux和windows之后怎样修复启动而头疼。

而grub2的出现,或许可以减少很多麻烦,因为比起grub,grub for dos,grub2的确智能很多。

 

grub2目前中文文档很少,下面是一些英文帮助页面。

ubuntu wiki页面:

https://help.ubuntu.com/community/Grub2

grub2 wiki

http://grub.enbug.org/FrontPage

grub2 命令

http://grub.enbug.org/CommandList

 

grub2的配置文件主要在下面三个位置

 

The configuration resides (generally) in three places:

  • in /etc/default/grub - where a set of general configuration options reside, created by grub-set-default, that you may not want to change much.

  • in /etc/grub.d - where a set of sh scripts are sequentially used to do useful things that generate the actual bootloader's config file, much like init scripts.

  • in /boot/grub - where the bootloader itself looks for configuration ( /boot/grub/grub.conf ). This file is written from the /etc/grub.d files, so changes here will be overwritten by some commands.


    !!! boot/grub/gurb.conf 可能有误,在ubuntu下是boot/grub/grub.cfg

     

    /etc/default/grub :默认配置

    /etc/grub.d          :类似shell脚本一样的配置

    /boot/grub/grub.cfg :所/etc/grub.d文件夹下的文件生成的配置文件,最重要的配置

 

 

下面主要说介绍怎样在ubuntu下修复windows启动

1.使用grub-mkconfig 命令智能生成grub.cfg

把生成的cfg文件覆盖到 /boot/grub/grub.cfg 就行了。

只能说grub-mkconfig命令真是神器,一直很希望能有这样的智能命令。

# grub-mkconfig -o /root/grubtrial/grub.conf_2 Generating grub.cfg ... Found linux image: /boot/vmlinuz-2.6.31-20-generic-pae Found initrd image: /boot/initrd.img-2.6.31-20-generic-pae Found linux image: /boot/vmlinuz-2.6.31-17-generic-pae Found linux image: /boot/vmlinuz-2.6.31-14-generic-pae Found initrd image: /boot/initrd.img-2.6.31-14-generic-pae Found memtest86+ image: /boot/memtest86+.bin Found Windows Vista (loader) on /dev/sda3 Found Debian GNU/Linux (5.0.3) on /dev/sda8 done 

 

2.能过编写grub2脚本来修复启动

首先查看分区的uuid

> sudo blkid  

可能是以下的结果

>/dev/sda2: UUID="10AC99D8AC99B8A4" TYPE="ntfs"  

参照下面编写脚本,用户的脚本文件是 /etc/grub.d/40_custom 

编辑 /etc/grub.d/40_custom   文件如下

如果熟悉grub 或者 grub for dos,很容易明白。

grub2的一大特点就是用uuid来代替了以前的(hd0,0)的写法。

因为硬盘可能增加,移动分区等,但是uuid通常不会改变,这避免了频繁修改配置文件

#!/bin/sh exec tail -n +3 $0 # 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. menuentry "Windows XP" { insmod chain insmod ntfs search --fs-uuid --set 10ac99d8ac99b8a4 chainloader +1 } 

执行

>sudo update-grub  

可以查看到配置文件更新了。

>cat /boot/grub/grub.cfg  

 

 

 

 

相关文章
|
8月前
|
机器学习/深度学习 Linux 决策智能
双系统出现grub rescue修复方法
双系统出现grub rescue修复方法
293 0
|
6月前
|
安全 Linux
Linux常见维护报错,修复MBR引导/修复grub2菜单/内核文件丢失
Linux常见维护报错,修复MBR引导/修复grub2菜单/内核文件丢失
58 0
Linux常见维护报错,修复MBR引导/修复grub2菜单/内核文件丢失
|
8月前
|
网络协议 安全 Linux
2.2.3开机流程中的BIOS与UEFI开机检测程序
2.2.3开机流程中的BIOS与UEFI开机检测程序
97 0
2.2.3开机流程中的BIOS与UEFI开机检测程序
|
网络安全
记一次grub修复
/boot/grub/grub.conf被清空,系统启动就进入grub状态(centos 6.8)
记一次grub修复
|
Linux Shell 数据安全/隐私保护