ubuntu 中的 grub2 功能和操作方法详解【适用于所有的GRUB】

各ubuntu版本对应的grub版本号:

GRUB 2                       Ubuntu since version 9.10 (Karmic Koala)    //grub2 从9.10的ubuntu版本开始使用。

Grub version 1.99     Ubuntu 11.04 (Natty Narwhal)

 

 

改进 Improvements

 

GRUB 2's major improvements over the original GRUB include:

  • Scripting support including conditional statements and functions
  • Dynamic module loading
  • Rescue mode
  • Custom Menus
  • Themes
  • Graphical boot menu support and improved splash capability
  • Boot LiveCD ISO images directly from hard drive
  • New configuration file structure
  • Non-x86 platform support (such as PowerPC)
  • Universal support for UUIDs (not just Ubuntu)

在ubuntu系统中可以使用如下命令查看grub的版本号:

         grub-install -v

 

如果只装了一个操作系统,即ubuntu。

那么,默认是不会出现grub的启动菜单的。

有两种方法可以进入启动菜单:

       按键: 点击“SHIFT”  或者 “ESC ”  ,可以进去grub的启动菜单。

早期grub版本的配置文件  /boot/grub/menu.lst 在grub2中已经被替换为  /boot/grub/grub.cfg   .

grub.cfg         会被某些动作更新。 比如,当一个内核被添加或者移除时,或者当哦难怪乎运行 update -grub 命令时。

 

列出有效linux内核的菜单列表(menu list)是通过运行 update -grub 来自动产生的。

 

grub.cfg 会更新的时候会被覆盖,但是在 /etc/grub.d/  文件夹下有些自定义的配置文件可以使用 如 40_custom  。

ls /etc/grub.d/
00_header        10_linux      20_memtest86+  40_custom  README
05_debian_theme  20_linux_xen  30_os-prober   41_custom

改变菜单显示设置项的配置文件是: /etc/default/grub

[plain]  view plain copy
  1. # If you change this file, run 'update-grub' afterwards to update  
  2. # /boot/grub/grub.cfg.  
  3. # For full documentation of the options in this file, see:  
  4. #   info -f grub -n 'Simple configuration'  
  5.   
  6. GRUB_DEFAULT=0  
  7. GRUB_HIDDEN_TIMEOUT=0  
  8. GRUB_HIDDEN_TIMEOUT_QUIET=true  
  9. GRUB_TIMEOUT=10  
  10. GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`  
  11. GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"  
  12. GRUB_CMDLINE_LINUX=""  
  13.   
  14. # Uncomment to enable BadRAM filtering, modify to suit your needs  
  15. # This works with Linux (no patch required) and with any kernel that obtains  
  16. # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)  
  17. #GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"  
  18.   
  19. # Uncomment to disable graphical terminal (grub-pc only)  
  20. #GRUB_TERMINAL=console  
  21.   
  22. # The resolution used on graphical terminal  
  23. # note that you can use only modes which your graphic card supports via VBE  
  24. # you can see them in real GRUB with the command `vbeinfo'  
  25. #GRUB_GFXMODE=640x480  
  26.   
  27. # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux  
  28. #GRUB_DISABLE_LINUX_UUID=true  
  29.   
  30. # Uncomment to disable generation of recovery mode menu entries  
  31. #GRUB_DISABLE_RECOVERY="true"  
  32.   
  33. # Uncomment to get a beep at grub start  
  34. #GRUB_INIT_TUNE="480 440 1"  


分区编号已经改了!

现在第一个分区是 1,而不是 0 。

第一个设备驱动(device/drive)依然默认是 hd0 。如果需要,可以再 /boot/grub 下的 device.map 文件中配置。

当运行 update-grub 命令的时候,grub会自动去找其他的操作系统。 找到之后,相关的操作系统启动项可以再grub2的 菜单中找到。

对配置文件的任何改变不会立即起作用,必须 运行 update-grub 命令 之后才会生效。

 

 

从GRUB升级至GRUB2  ---- Upgrading to GRUB 2 From GRUB

https://help.ubuntu.com/community/Grub2/Upgrading  这里详细说明了 升级方法及过程。

 

文件结构  ---- File Structure

GRUB2改变目录的结构层次。 GRUB2的文件夹包括:

 /etc/grub.d    ---包括GRUB2的脚本

/boot/grub      ---包括GRUB2的模块和 menu文件(grub.cfg)

/etc/default/grub   --- 包括用户自定义配置

具体相关请参考: https://help.ubuntu.com/community/Grub2/Setup#File_Structure 

 

配置GRUB2    ---- Configuring GRUB 2

参考 https://help.ubuntu.com/community/Grub2/Setup

 

启动失败,进入安全模式

 

 设置安全模式下的 启动菜单超时时间:

  /etc/grub.d/00_header  , 找到 约236行 ,即make_timeout()函数的内容。有如下timeout的变量设置:

set timeout=0

For timeout=-1, 没有倒计时,会直接显示 启动菜单 。

  • For timeout=0,   即便是进入失败启动,启动菜单也不会显示。

  • For timeout>=1, 启动菜单将停住 一定的时间,这个时间就是这个数字所代表的秒数。

改动了之后,一定要 运行 update-grub 命令才生效。

 

上面的改变之后,grub依然会启动至 text graphics 模式。因此,可以修改 /etc/grub.d/10_linux (大约第188行)这个文件的内容来达到 相应的目的。

同样需要 运行 update-grub 命令才生效。

 

密码保护 --- Password Protection

GRUB2允许用户创建自定义的 启动菜单选项。

/etc/grub.d/40_custom   就是 提供给用户参考的一个有效样例。

具体请参考:https://help.ubuntu.com/community/Grub2/CustomMenus

 

故障解决 --- Troubleshooting

GRUB2 提供了优秀的能力来解决问题,以及通过启动菜单或者GRUB2的命令终端来纠正启动问题。

具体请参考: https://help.ubuntu.com/community/Grub2/Troubleshooting

   另外可以参考 https://help.ubuntu.com/community/Grub2/Troubleshooting#Selected_Problems_and_Bugs

 

显示 --- Displays

GRUB2 除了提供简单的黑白菜单之外,可以有更丰富的色彩。用户可以改变GRUB的启动菜单的字体、背景和分辨率。

更多相关的请参考:https://help.ubuntu.com/community/Grub2/Displays

 

Some people may have old bookmarks leading to this page in which case these links might be useful to them but it's better to link to the sub-pages directly as the sub-sections here are only here temporarily while this main page gets broken-up into digestible sub-pages.

GRUB 2 Splash Images

Grub2/Displays#Installing_Splash_Images

Set the splash image

Grub2/Displays#Installing_Splash_Images

Set menu font and highlight colors

Grub2/Displays#Setting_Menu_Font_Colors

 

Testing Fonts and Splash Images

Grub2/Displays#Testing_Fonts_and_Splash_Images

Changing Resolutions w/ Splash Images

Grub2/Displays#Changing_Menu_Resolutions

Creating User Splash Images

Grub2/Displays#Creating_User_Splash_Images

Resolution Settings

 

Grub2/Displays#Resolution_Settings

Image Creation and Setup

Grub2/Displays#Image_Creation_and_Setup

 

主题 --- Themes

GRUB 2 主题依然还在开发当中, 它集成了 gfxmenu. Theme elements will include colors, fonts, progress indicators, menus, and labels. 这些特征都没有在 Ubuntu 9.10 版本当中使用。

  • grub2.theme.dinxter.png

    grub2.theme.bennett.png

 

安装/重装/卸载GRUB2  --- Installing/Reinstalling/Moving GRUB2

请参考 : https://help.ubuntu.com/community/Grub2/Installing

 

从menuentry启动一个ISO文件 --- Booting an ISO from a Menuentry

通过GRUB的 menuentry  可以启动一个硬盘上面的 ISO(各种linux发布版的ISO文件都可以) 。这个功能允许可启动的镜像文件被存储在硬盘当中, 在没有CD/DVD的时候,这个功能是特别有用的。

具体请参考: https://help.ubuntu.com/community/Grub2/ISOBoot

 

 

安全性(通过GRUB命令行禁止启动)Security --> Preventing booting via Grub command-line

 通过使用grub命令行来启动的功能,构成了linux中的巨大风险。任何操作系统都可以通过USB或其他启动盘来启动,他们可以绕过BIOS的限制。通过 设置密码或者锁定 grub配置文件中的启动菜单项, 是没办法阻止 通过grub命令行手动输入命令来启动的用户的。一旦一个外部的OS被启动,当然,它可以访问硬盘上任何未加密的部分。

目前没有任何选项来 阻止grub命令行的使用。To prevent the command-line usage of Grub and require bootloading from menu options only, there are currently no options.

 

 

杂项 --- Miscellaneous

从串行控制台启动 --- Booting from a serial console

如果你希望 GRUB可以通过一条串行线来操作,你将需要 取消/etc/default/grub 文件中的GRUB_TERMINAL 那一行注释,并设置它的值为 “serial” 。默认串口控制台设置是使用9600bit/S的传输速度、8bit的数据宽度、1停止位和无奇偶校验 来操作第一个串口(ttyS0)。

If you want to use another serial port or if your console uses different settings, you must add aGRUB_SERIAL_COMMAND line to specify additional parameters to theserial command. The serial command in GRUB 2 uses the same syntax as its GRUB Legacy counterpart (documentedhere). For example, for a very common 9600 bit/s (baud) serial line with 8 data bits, 1 stop bit and no parity:

如果你想要使用另外一个串口,或者如果你的控制台使用不同的设置,你必须 另外添加一个GRUB_SERIAL_COMMAND 变量,并制定特定的参数给串口命令。 

GRUB_SERIAL_COMMAND="serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1"

An example is a 4800 bit/s (baud) serial line with 7 data bits, 1 stop bit and even parity:

GRUB_SERIAL_COMMAND="serial --unit=0 --speed=4800 --word=7 --parity=even --stop=1"

启动FreeBSD, NetBSD等多个OS --- Booting FreeBSD, NetBSD, and multiboot OSes

具体请参考 :https://help.ubuntu.com/community/Grub2%20Other%20Os 

 

 

 

 


 

CategoryBootAndPartitionCategoryRescueAndCloning

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值