grub升级到grub2的操作


grub升级到grub2的操作
 
由于公司大多数系统用的还是传统GRUB(0.97版),后阶段需要升级为GRUB2,该版本为1.96或者更新版本.
 
先来看下grub2与传统的grub相比之下主要增加的功能包含:
 
1.支持脚本,包括条件语法和函数
 
2.动态加载模块
 
3.救援模式
 
4.可定制菜单,主题
 
5.支持图形化启动菜单以及增强的引导画面功能
 
6.新的配置文件结构,全面支持UUID
 
        虽然grub2默认菜单对使用过grub的人来说看起来很熟悉,但是里面还是有很大不同.
 
1.没有/boot/grub/menu.1st。已被/boo/grub/grub.cfg取代
 
2.在grub提示符下没有find命令,已变成search.
 
3.grub2已经模块化,不再需要'stage1.5'.所以引导器可以变得很小.
 
4.磁盘分区编号变更。现在第一个磁盘分区是 1 而不是 0。然而第一个设备仍然是 0(没有改变) 
 
5./etc/grub/grub.cfg,不应在被手动编辑,主要用来编辑的配置文件是/etc/default/grub,还有所在/etc/grub.d/目录下的文件,在update-grub命令执行前,所有配置文件的修改都不会生效.
 
查看grub版本,升级至grub2
 
1
root@10.1.1.45:~# grub-install -v
2
grub-install (GNU GRUB 0.97)
01
root@10.1.1.45:~# dpkg -i grub-common_1.96+20080724-16_amd64.deb
02
(Reading database ... 35648 files and directories currently installed.)
03
Preparing to replace grub-common 1.96+20080724-16 (using grub-common_1.96+20080724-16_amd64.deb) ...
04
Unpacking replacement grub-common ...
05
Setting up grub-common (1.96+20080724-16) ...
06
root@10.1.1.45:~# dpkg -i grub-pc_1.96+20080724-16_amd64.deb
07
Selecting previously deselected package grub-pc.
08
dpkg: considering removing grub in favour of grub-pc ...
09
dpkg: yes, will remove grub in favour of grub-pc.
10
(Reading database ... 35648 files and directories currently installed.)
11
Unpacking grub-pc (from grub-pc_1.96+20080724-16_amd64.deb) ...
12
Setting up grub-pc (1.96+20080724-16) ...
13
Generating core.img
14
Saving menu.lst backup in /boot/grub/menu.lst_backup_by_grub2_postinst
15
Running update-grub Legacy to hook our core.img in it
16
    Searching for GRUB installation directory ... found: /boot/grub
17
    Searching for default file ... found: /boot/grub/default
18
    Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
19
    Searching for splash image ... none found, skipping ...
20
    Found GRUB 2: /boot/grub/core.img
21
    Found kernel: /boot/vmlinuz-2.6.26-2-amd64
22
    Updating /boot/grub/menu.lst ... done
23
     
24
Updating /boot/grub/grub.cfg ...
25
Found linux image: /boot/vmlinuz-2.6.26-2-amd64
26
Found initrd image: /boot/initrd.img-2.6.26-2-amd64
27
done
28
Processing triggers for man-db ...
1.期间会有提示信息,在选择「OK」后,下一个选项允许用户在正常的 GRUB 菜单中通过新增一个菜单项来测试GRUB2.选择「Yes」将在 GRUB 菜单中增加一个 Chainload 项.当下次使用 GRUB 启动时,使用者可以选择正常的 GRUB 菜单项或是将控制权通过 Chainload 菜单项转到 GRUB 2。  
 
 
2.下一步将会把来自 GRUB 的 menu.lst 中的内容导入到[Linux command line](如下图),或者导入[Linux default command line]。这些项目允许用户输入任意的特殊命令,例如 quiet, splash,noapic 或是其他同样性质的命令。GRUB 2 将会自动导入这些配置。通常用户不需要修改并选择「OK」。若有需要,选项也可以在以后再加入。
 
 
当系统已安装完成grub2,还需要更改几个参数
 
01
root@10.1.1.45:grub# cat /etc/default/grub
02
# This file is sourced by update-grub, and its variables are propagated
03
# to its children in /etc/grub.d/
04
GRUB_DEFAULT=0
05
GRUB_TIMEOUT=5
06
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
07
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS1,115200"  #在内核引导加入console连接的相关参数,保证可以通过ipmi连接该服务器.由于该机器型号是R710故用115200.
08
 
09
# Uncomment to disable graphical terminal (grub-pc only)
10
GRUB_TERMINAL=console #选择console作为终端设备,保证ipmi连接显示正色.
11
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
12
#GRUB_DISABLE_LINUX_UUID=true
1
root@10.1.1.45:# vi /etc/inittab
2
T1:23:respawn:/sbin/getty -L ttyS1 115200 vt100    保证登录不显示乱码
1
root@10.1.1.45:grub# update-grub             生效配置文件
2
Updating /boot/grub/grub.cfg ...
3
Found linux image: /boot/vmlinuz-2.6.26-2-amd64
4
Found initrd image: /boot/initrd.img-2.6.26-2-amd64
5
done
重启机器后可以看到更新的grub传统菜单欢迎画面,也会看到一个「Chainload into GRUB 2」菜单项,用来测试 GRUB 2 安装。选择 Chainload 选项将会把控制权转到 GRUB 2 并显示GRUB2菜单。
 
使用以下命令可以完全升至grub2.
 
01
root@10.1.1.45:~# upgrade-from-grub-legacy
02
 
03
Installing GRUB to Master Boot Record of your first hard drive ...
04
 
05
Installation finished. No error reported.
06
This is the contents of the device map /boot/grub/device.map.
07
Check if this is correct or not. If any of the lines is incorrect,
08
fix it and re-run the script `grub-install'.
09
 
10
(hd0)   /dev/hda
11
 
12
GRUB Legacy has been removed, but its configuration files have been preserved,
13
since this script cannot determine if they contain valuable information.  If
14
you would like to remove the configuration files as well, use the following
15
command:
16
 
17
  rm -f /boot/grub/menu.lst*
 
下面介绍grub2使用的主要配置目录和文件:
 
1./boot/grub/grub.cfg:类似grub下/boot/grub/menu.1st的文件.包含grub2菜单信息.不应该手动编辑.应该由update-grub来更新,在/boot/grub目录小会看到许多*.mod文件,这表明grub2的模块化本质.grub2启动时按需要加载不同的模块.
 
01
root@10.1.1.45:grub# ls
02
acorn.mod      _bsd.mod        device.map    gzio.mod     lnxboot.img                        multiboot.mod  reiserfs.mod  vbe.mod
03
affs.mod       bsd.mod         diskboot.img  halt.mod     loadenv.mod                        normal.mod     search.mod    vbetest.mod
04
afs.mod        cat.mod         echo.mod      hello.mod    loopback.mod                       ntfscomp.mod   serial.mod    vga.mod
05
amiga.mod      cdboot.img      elf.mod       help.mod     ls.mod                             ntfs.mod       sfs.mod       video.mod
06
aout.mod       _chain.mod      ext2.mod      hexdump.mod  lspci.mod                          partmap.lst    sleep.mod     videotest.mod
07
apple.mod      chain.mod       fat.mod       hfs.mod      lvm.mod                            pci.mod        sun.mod       xfs.mod
08
ascii.pff      cmp.mod         font.mod      hfsplus.mod  memdisk.mod                        pc.mod         terminal.mod
09
ata.mod        command.lst     fshelp.mod    iso9660.mod  menu.lst                           play.mod       terminfo.mod
10
biosdisk.mod   configfile.mod  fs.lst        jfs.mod      menu.lst~                          png.mod        test.mod
11
bitmap.mod     core.img        fs_uuid.mod   jpeg.mod     menu.lst_backup_by_grub2_postinst  pxeboot.img    tga.mod
12
blocklist.mod  cpio.mod        gfxterm.mod   kernel.img   minix.mod                          raid.mod       udf.mod
13
boot.img       cpuid.mod       gpt.mod       _linux.mod   moddep.lst                         read.mod       ufs.mod
14
boot.mod       default         grub.cfg      linux.mod    _multiboot.mod                     reboot.mod     vbeinfo.mod
 
2./etc/default/grub:包含以前在 GRUB 传统的 menu.lst 前半部配置内容;以及每行内核配置后面的追加配置。
 
3./etc/grub.d/:在此目录中的文件将会在执行 update-grub 命令的时候读取,并将其中的命令合并至 /boot/grub/grub.cfg 中。 
 
在 grub.cfg 菜单中的菜单项顺序是依照在此目录中文件的顺序来决定。 具有较小数字前缀文件名的文件将会先执行.
在update-grub 执行过程中只有可执行文件会输出至 grub.cfg。  
在此目录中的默认文件为:  
00_header 配置初始显示项目,例如图形模式、默认选项、时间限制等等。这些配置信息一般由/etc/default/grub 中导入。使用者一般不需要对此文件做任何更动。  
05_debian_theme 此文件中的配置用来配置引导画面、文字颜色、高亮度选项及主题。再没有引导画面的情况下,此文件会配置一个单色的主题来显示初始菜单画面。如何配置字体显示及引导画面将会在引导画面和主题小节中讨论。  
10_hurd 定位 Hurd 内核位置。目前未使用。  
10_linux 定位当前操作系统使用中的 root 设备内核位置。此信息将会用来建立这些内核显示在菜单中的名称。
 
30_os-prober 此文件和 os-prober,用来搜索 Linux 和其他操作系统。结果将会依据此文件中的内容而放至 grub.cfg 中。此文件被划分成四个段落,代表由该脚本所处理的四种操作系统类型:Windows, Linux, OSX 和 Hurd。此脚本中的变量用来指定在 /boot/grub/grub.cfg 和 GRUB 2 菜单中的名称显示格式。熟悉基本脚本的用户可以修改这些变量来改变菜单选项的显示格式。此外,用户可以修改 /etc/default/grub 的一个选项来关闭这个脚本。
40_custom 用来加入自定义菜单项的样板,将会在执行 update-grub 命令时嵌入至 grub.cfg 中。此文件中的内容,在「exec tail -n +3 $0」这一行和默认的注释后,会毫无改变地直接导入至/etc/default/grub.cfg.
 
 
1
root@10.1.1.45:grub.d# ll
2
total 28
3
-rwxr-xr-x 1 root root 1897 2009-02-11 09:58 00_header
4
-rwxr-xr-x 1 root root 1143 2009-02-11 09:52 05_debian_theme
5
-rwxr-xr-x 1 root root 2369 2009-02-11 09:58 10_hurd
6
-rwxr-xr-x 1 root root 4050 2009-02-11 09:58 10_linux
7
-rwxr-xr-x 1 root root 2567 2009-02-11 09:58 30_os-prober
8
-rwxr-xr-x 1 root root   84 2009-02-11 09:58 40_custom
9
-rw-r--r-- 1 root root  483 2009-02-11 09:58 README
 
在升级其它debian机器时,其中重启机器过了grub遇到error: unknown command 'initrd'错误,后来谷歌一番,发现出问题的command list一般是如下形式:
 
1
menuentry "Debian GNU/Linux, linux 2.6.32-2-amd64" {
2
    set root=(hd0,1)
3
    search --fs-uuid --set c618b7d1-4769-4dfe-8169-66e9f8aace43
4
    linux   /boot/vmlinuz-2.6.32-2-amd64 root=UUID=c618b7d1-4769-4dfe-8169-66e9f8aace43 ro console=tty0 console=ttyS1,115200
5
    initrd  /boot/initrd.img-2.6.32-2-amd64
6
}
解决办法是删掉search那一行.

相关内容

    暂无相关文章