
GRUB2启动代码注释.doc
6页文档供参考,可复制、编制,期待您的好评与关注! GRUB启动代码分析 0818 袁意 200893111## DO NOT EDIT THIS FILE## It is automatically generated by /usr/sbin/grub-mkconfig using templates# from /etc/grub.d and settings from /etc/default/grub#### BEGIN /etc/grub.d/00_header ###if [ -s $prefix/grubenv ]; then#如果“ prefix/grubenv”目录不为空 load_env #从grubenv文件中加载环境变量fiset default="0" #启动第1项(以0开始计数,在我的电脑上,linux是第1项,即”0”,Windows7#是第2项,即”1”if [ ${prev_saved_entry} ]; then #如果prev_saved_entry的值不为空 set saved_entry=${prev_saved_entry} #将saved_entry的值设置成变量prev_saved_entry的值。
save_env saved_entry#将变量saved_entry保存到grubenv文件中 set prev_saved_entry=#将prev_saved_entry的值设置为空 save_env prev_saved_entry#将prev_saved_entry保存到grubenv文件中 set boot_once=true#将boot_once的值设置为真(貌似是为了标志已经设置过启动的相关环境变量了)fifunction savedefault { if [ -z ${boot_once} ]; then#如果已经设置过相关环境变量saved_entry=${chosen}#用变量chosen的值给saved_entry赋值save_env saved_entry#将saved_entry保存到grubenv文件中 fi}function recordfail { #存在启动失败记录时调用,设置变量recordfail set recordfail=1 if [ -n ${have_grubenv} ]; then if [ -z ${boot_once} ]; then save_env recordfail; fi; fi#如果grubenv文件存在,并已设置过相关变量,就将变量recordfail保存到grubenv文件。
}insmod ext2 #插入ext2文件系统支持的模块set root='(hd0,9)' # 指定系统root分区,也就是 / 分区为第1个磁盘的第9个分区search --no-floppy --fs-uuid --set d9985e84-7b54-4e5d-8ce9-c25cf88330aa# 指定uuid= d9985e84-7b54-4e5d-8ce9-c25cf88330aa的分区为root分区,如果前面的分区 # 号(hd0,9)的uuid与这里的uuid一致,这两句作用一样,如果不一致,则指定uuid的起 # 作用if loadfont /usr/share/grub/unicode.pf2 ; then#设置终端字体,unicode.pf2支持中文字符显示 set gfxmode=640x480#设置显示分辨率,默认为640×480 insmod gfxterm#插入终端模块gfxterm,支持中文字符显示和支持24位图像 insmod vbe#插入vbe模块,GRUB2引入模块化机制,要使用它,需要在这里加入 if terminal_output gfxterm ; then true ; else #检测grub2是否将终端设设定为gfxterm # For backward compatibility with versions of terminal.mod that don't # understand terminal_outputterminal gfxterm #设定grub2终端为gfxterm fifiinsmod ext2 #插入ext2文件系统支持的模块 set root='(hd0,9)' # 指定系统root分区,也就是 / 分区为第1个磁盘的第9个分区search --no-floppy --fs-uuid --set d9985e84-7b54-4e5d-8ce9-c25cf88330aa# 指定uuid= d9985e84-7b54-4e5d-8ce9-c25cf88330aa的分区为root分区,如果前面的分区 # 号(hd0,9)的uuid与这里的uuid一致,这两句作用一样,如果不一致,则指定uuid的起 # 作用。
set locale_dir=($root)/boot/grub/localeset lang=zhinsmod gettextif [ ${recordfail} = 1 ]; then set timeout=-1 #若有启动失败的记录,则不再倒计时else set timeout=10 #如果停留在grub选择系统界面,停顿时间就设置成10秒,十秒后按默认启动项#启动fi### END /etc/grub.d/00_header ###### BEGIN /etc/grub.d/05_debian_theme ###设置菜单颜色和背景颜色set menu_color_normal=white/black #设定菜单字体及背景颜色set menu_color_highlight=black/light-gray#设定选择项字体及背景颜色### END /etc/grub.d/05_debian_theme ###### BEGIN /etc/grub.d/10_linux ### #10_linux为系统自动添加的当前root分区linux引导项#菜单项,要包括 menuentry 双引号" " 和大括号 { }才完整,否则不显示菜单menuentry 'Ubuntu,Linux 2.6.32-30-generic' --class ubuntu --class gnu-linux --class gnu --class os { recordfail#执行recordfail 函数 insmod ext2#插入ext2文件系统支持的模块 set root='(hd0,9)' #指定系统root分区,也就是 / 分区为第1个磁盘的第9个分区 search --no-floppy --fs-uuid --set d9985e84-7b54-4e5d-8ce9-c25cf88330aa#这句与set root=(hd0,9)效果一样,可删除其一,二者不一致以这句为准 linux /boot/vmlinuz-2.6.32-30-generic root=UUID=d9985e84-7b54-4e5d-8ce9-c25cf88330aa ro quiet splash#加载内核# ro:可读写,当启动分区是JFS等格式时需要使用此参数使得系统可以在启动是存放日志。
quiet:安静模式,不显示启动详细信息splash:显示徽标 initrd /boot/initrd.img-2.6.32-30-generic#初始RAM磁盘,在系统引导过程中挂载的一个临时根文件系统}menuentry 'Ubuntu,Linux 2.6.32-30-generic (恢复模式)' --class ubuntu --class gnu-linux --class gnu --class os {#linux的恢复模式,与linux的启动项基本一样 recordfail#执行recordfail 函数 insmod ext2 set root='(hd0,9)' search --no-floppy --fs-uuid --set d9985e84-7b54-4e5d-8ce9-c25cf88330aa echo '载入 Linux ...' linux /boot/vmlinuz-2.6.32-30-generic root=UUID=d9985e84-7b54-4e5d-8ce9-c25cf88330aa ro single #加载内核 不知道single这个参数是什么意思 echo '载入引导虚拟磁盘。
' initrd /boot/initrd.img-2.6.32-30-generic#初始RAM磁盘,在系统引导过程中挂载的一个临时根文件系统}### END /etc/grub.d/10_linux ####20_memtest86+为系统自动添加的内存测试菜单项,之前存在这一项,但被我删掉了……### BEGIN /etc/grub.d/30_os-prober #### 30_os-prober或30_others为系统自动查找并添加其他系统菜单项,按windows、# linux、macos顺序查找并添加,支持windows 7识别menuentry "Windows 7 (loader) (on /dev/sda1)" { insmod ntfs#插入NTFS文件系统支持的模块 set root='(hd0,1)'#指定系统root分区,也就是 / 分区为第1个磁盘的第1个分区 search --no-floppy --fs-uuid --set 5802c4e402c4c7e8#这句与set root=(hd0,1)效果一样,可删除其一,二者不一致以这句为准 chainloader +1#指示GRUB读入分区的第一个扇区的引导记录。
}### END /etc/grub.d/30_os-prober ###### BEGIN /etc/grub.d/40_custom ####40_custom为自定义的启动项,如启动cdlinux# 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.### END /etc/grub.d/40_custom ### / 。












