GRUB手册(5)

来源:互联网 发布:Sql server 删除临时表 编辑:程序博客网 时间:2024/05/06 00:49

15.   认证与授权

默认的,启动载入器接口对于任意可以物理进入控制台的人都是可访问的:任何人可以选择并编辑任意菜单项,并且可以直接访问一个GRUB shell。对于绝大多数系统,这是合理的,因为任何可以直接访问物理设备的人,有各种方法得到完全的访问,在启动载入器级别要求认证,只会使恢复崩溃的系统变得困难。

不过,在某些环境下,比如kiosks,锁住启动载入器,在执行某些操作之前要求认证,可能是合适的。

命令‘password’(参考14.3.33节【password】,43页)及‘password_pbkdf2’(参考14.3.34节【password pbkdf2】,43页)可以用来定义用户,每一个具有关联的口令。‘password’设置纯文本形式的口令,要求加密‘grub.cfg’;‘password_pbkdf2’使用基于口令的密钥导出函数(Password-Based Key Derivation Function(RFC 2898))来设置口令哈希,要求使用grub-mkpasswd-pbkdf2(参考第21章【调用grub-mkpasswd-pbkdf2】,79页)来产生口令哈希值。

为了激活认证支持,环境变量‘superusers’必须被设置为一组用户名,以空格,逗号,分号,|,或&分隔。超级用户允许使用GRUB命令行,编辑菜单项,及执行任意菜单项。如果设置了‘superusers’,那么命令行的使用自动地,仅限于超级用户。

其它用户可能通过,使用选项‘--users’的‘menuentry’命令(参考14.1.1节【menuentry】,36页)给出一组用户名(如上),允许访问特定菜单项。A如果对一个菜单项没有使用选项‘--users’,那么该项是未限定的。

总结起来,一个典型的‘grub.cfg’片段看起来可能像这样:

set superusers="root"

password_pbkdf2 root grub.pbkdf2.sha512.10000.biglongstring

password user1 insecure

menuentry "May be run by any user" {

set root=(hd0,1)

linux /vmlinuz

}

menuentry "Superusers only" --users "" {

set root=(hd0,1)

linux /vmlinuz single

}

menuentry "May be run by user1 or a superuser" --usersuser1 {

set root=(hd0,2)

chainloader +1

}

程序grub-mkconfig还没有对生成带认证的配置文件提供内建的支持。你可以使用‘/etc/grub.d/40_custom’来添加简单的超级用户认证,通过添加set superusers=及password或 password_pbkdf2命令。

16.   已支持的启动目标

对X86的支持总结在下表中。“Yes”表示该内核工作在给定的平台,“crashes”表示一个早期的内核崩溃,我们希望它将被有关的内核开发人员所解决。“no”表示GRUB在一个给定的平台上不能载入该内核。“headless”表示该内核可以工作,不过缺乏控制台驱动(你仍然可以使用串行或网络控制台)。对于“no”或“crashes”的情绪,在脚标中 给出原因。

BIOS                   Coreboot

BIOS chainloading                                  yes                      no (1)

NTLDR                                     yes                      no (1)

FreeBSD bootloader                         yes                      crashes(1)

32-bit kFreeBSD                              yes                      crashes (2,6)

64-bit kFreeBSD                              yes                      crashes (2,6)

32-bit kNetBSD                               yes                      crashes (1)

64-bit kNetBSD                               yes                      crashes (2)

32-bit kOpenBSD                                   yes                      yes

64-bit kOpenBSD                                   yes                      yes

Multiboot                                         yes                      yes

Multiboot2                                       yes                      yes

32-bit Linux(legacy protocol)                yes                      no (1)

64-bit Linux(legacy protocol)                yes                      no (1)

32-bit Linux(modern protocol)                     yes                      yes

64-bit Linux(modern protocol)                     yes                      yes

32-bit XNU                               yes                      ?

64-bit XNU                               yes                      ?

32-bit EFIchainloader                            no(3)                  no (3)

64-bit EFIchainloader                            no(3)                  no (3)

Appleloader                              no(3)                  no (3)

Multiboot            Qemu

BIOS chainloading                                  no (1)                  no (1)

NTLDR                                     no (1)                  no (1)

FreeBSD bootloader                         crashes (1)          crashes (1)

32-bit kFreeBSD                              crashes (6)          crashes (6)

64-bit kFreeBSD                              crashes (6)          crashes (6)

32-bit kNetBSD                               crashes (1)          crashes (1)

64-bit kNetBSD                               yes                      yes

32-bit kOpenBSD                                   yes              yes

64-bit kOpenBSD                                   yes                      yes

Multiboot                                         yes                      yes

Multiboot2                                       yes                      yes

32-bit Linux(legacy protocol)                no (1)                  no (1)

64-bit Linux(legacy protocol)                no (1)                  no (1)

32-bit Linux(modern protocol)                     yes                      yes

64-bit Linux(modern protocol)                     yes                      yes

32-bit XNU                               ?                   ?

64-bit XNU                               ?                  ?

32-bit EFIchainloader                            no(3)                  no (3)

64-bit EFIchainloader                            no(3)                  no (3)

Appleloader                              no(3)                  no (3)

32-bit EFI            64-bitEFI

BIOS chainloading                                  no (1)                  no (1)

NTLDR                                     no (1)                  no (1)

FreeBSD bootloader                         crashes (1)          crashes (1)

32-bit kFreeBSD                              headless              headless

64-bit kFreeBSD                              headless              headless

32-bit kNetBSD                               crashes (1)          crashes (1)

64-bit kNetBSD                               yes                      yes

32-bit kOpenBSD                                   headless              headless

64-bit kOpenBSD                                   headless              headless

Multiboot                                         yes                      yes

Multiboot2                                       yes                      yes

32-bit Linux(legacy protocol)                no (1)                  no (1)

64-bit Linux(legacy protocol)                no (1)                  no (1)

32-bit Linux(modern protocol)                     yes                      yes

64-bit Linux (modernprotocol)                     yes                      yes

32-bit XNU                               yes                      yes

64-bit XNU                               yes (5)                 yes

32-bit EFIchainloader                            yes                     no (4)

64-bit EFIchainloader                            no(4)                  yes

Appleloader                              yes                     yes

IEEE1275

BIOS chainloading                                  no (1)

NTLDR                                     no (1)

FreeBSD bootloader                         crashes (1)

32-bit kFreeBSD                              crashes (6)

64-bit kFreeBSD                              crashes (6)

32-bit kNetBSD                               crashes (1)

64-bitkNetBSD                               ?

32-bitkOpenBSD                                   ?

64-bitkOpenBSD                                   ?

Multiboot                                         ?

Multiboot2                                       ?

32-bit Linux(legacy protocol)                no (1)

64-bit Linux(legacy protocol)                no (1)

32-bit Linux(modern protocol)                     ?

64-bit Linux(modern protocol)                     ?

32-bit XNU                               ?

64-bit XNU                               ?

32-bit EFIchainloader                            no(3)

64-bit EFIchainloader                            no(3)

Appleloader                              no(3)

  1. 要求BIOS
  2. 因为在0x0-0x1000的内存不存在,崩溃
  3. 仅EFI
  4. 32-bit及64-bit EFI有不同的结构,并工作在不同的CPU模式下,因此不可能在64位平台上链式载入32位启动载入器,反之亦然。
  5. 某些模块可能必须被禁止。
  6. 要求ACPI

PowerPC 及Sparc移植仅支持Linux。MIPS移植支持Linux及multiboot2。

17.   启动测试

正如在前面章节中看到的,这个支持的表格相当大,并且某些配置很少用到。为了确保对于所有x86平台,除了EFI链式载入器,Appleloader,及XNU以外,有优良的启动测试可用 。所有x86平台,除了ieee1275,都有启动测试设施。Multiboot,multiboot2,BIOS链式载入器,ntldr及freebsd-bootloader启动目标仅以一个假的内核映像测试。只有Linux是在使用Linux规程的有效内容中测试的,

以下变量必须被定义:

GRUB PAYLOADS DIR          包含所要求内核的目录

GRUB CBFSTOOL            来自Coreboot 包的cbfstoll(仅用于coreboot平台)

GRUB COREBOOT ROM               空的Coreboot ROM

GRUB QEMU OPTS 向QEMU提供的额外选项

要求的文件有:

kfreebsd env.i386                     32-bit kFreeBSD设备提示

kfreebsd.i386                     32-bit FreeBSD内核映像

kfreebsd.x86_64,                      类似的,来自64-bit kFreeBSD

kfreebsd env.x86_64

knetbsd.i386                      32-bit NetBSD内核映像

knetbsd.miniroot.i386              32-bit kNetBSDminiroot.kmod.

knetbsd.x86_64,                类似的,来自64-bit kNetBSD

knetbsd.miniroot.x86_64

kopenbsd.i386                   32-bit OpenBSD kernel bsd.rd 映像

kopenbsd.x86 64                      类似的,来自64-bit kOpenBSD

linux.i386                          32-bit Linux

linux.x86                           6464-bit Linux

18.   由GRUB产生的错误消息

18.1.  GRUB只提供一个救援shell

GRUB的普通的启动过程涉及,设置环境变量‘prefix’为由grub-install在core映像中设定的一个值,设置要匹配的变量‘root’,从prefix载入‘normal’模块,运行命令‘normal’(参考14.3.30节【normal】,42页)。这个命令负责读入 ‘/boot/grub/grub.cfg’,运行这个菜单,并执行所有GRUB假定会做的有用的事。

如果,相反,你只得到一个救援shell,这通常意味着GRUB出于某种原因不能载入 ‘normal’模块。它可能可以暂时地绕过之:比如,如果错误的原因是‘prefix’是错误的(可能它指向错误的设备,或可能到‘/boot/grub’的路径相对于该设备是不正确的),那么你可以修正之,并手动进入普通模式:

# Inspect the current prefix (and otherpreset variables):

set

# Find out which devices are available:

ls

# Set to the correct value, which might besomething like this:

set prefix=(hd0,1)/grub

set root=(hd0,1)

insmod normal

normal

不过,任何会导致你进入救援shell的问题,可能意味着GRUB没有正确安装。使用grubinstall设备(参考第19章【调用grub-install】,75页)尝试重写正确安装GRUB可能更有用。在这样做时,要记住几件事:

l        在你的操作系统上的驱动次序,可能与你的固件所使用的驱动启动次序不一样。不要假定你的第一个硬盘驱动(即,‘/dev/sda’)就是你的固件将从之启动的。‘device.map’(参考3.3节【设备映射】,7页)可以用于改写它,不过使用UUID或文件系统标签更好些,能完全避免设备的依赖。

l        至少在BIOS系统上,如果你告诉grub-install在一个分区上安装GRUB,但GRUB已经被安装在主启动记录中,那么在这个分区上GRUB的安装将被忽略。

l        如果可能,通常最好避免把GRUB安装到一个分区上(除非它是一个专门为GRUB使用的特殊分区,比如用在GPT中的BIOS启动分区)。这样做意味着GRUB可能,因为一个文件系统移动了数据块,比如在清除碎片,运行检查,或甚至普通操作期间,不能读入其core映像。安装到整个硬盘通常更牢靠些。

l        检查GRUB真的知道如何从设备及包含‘/boot/grub’的文件系统读入。它将不能从加密设备读入,也不能从尚未被GRUB支持的文件系统中读入。

19.   调用grub-install

程序grub-install,在你的驱动上,使用grub-mkimage及(在某些平台上)grub-setup安装GRUB。你必须指定你所希望安装GRUB的驱动名,像这样:

grub-install install_device

驱动名install_device是一个OS设备名或一个GRUB设备名。

grub-install接受以下选项:

‘--help’            打印该命令行的一个摘要并退出。

‘--version’ 打印GRUB的版本号并退出。

‘--boot-directory=dir’

在目录‘dir/grub/’下安装GRUB。当你希望把GRUB安装到一个独立的分区或一个可移动的硬盘时,这个选项是有用的。

如果没有指定这个选项,那么它缺省为‘/boot’,因此

grub-install/dev/sda

等效于

grub-install--boot-directory=/boot/ /dev/sda

这里是一个例子,你有一个独立的,安装在‘/mnt/boot’的启动分区:

grub-install--boot-directory=/mnt/boot /dev/sdb

‘--recheck’

重新检查设备映射,即便已经存在‘/boot/grub/device.map’。任何时候从你的计算机添加或移去一个硬盘时,你都应该使用这个选项。

20.   调用grub-mkconfig

程序grub-mkconfig为GRUB产生一个配置文件(参考5.1节【简单配置】,11页)。

grub-mkconfig -o /boot/grub/grub.cfg

grub-mkconfig接受以下选项:

‘--help’            打印该命令行的一个摘要并退出。

‘--version’ 打印GRUB的版本号并退出。

‘-ofile’

‘--output=file’

把产生的配置文件发送给file。缺省是发送给标准输出。

21.   调用grub-mkpasswd-pbkdf2

程序grub-mkpasswd-pbkdf2为GRUB生成口令哈希(参考第15章【安全】,48页)。

grub-mkpasswd-pbkdf2

grub-mkpasswd-pbkdf2接受以下选项:

‘-cnumber’

‘--iteration-count=number’

底层伪随机数函数的迭代次数。缺省为10000。

‘-lnumber’

‘--buflen=number’

所产生哈希的长度。缺省为64。

‘-snumber’

‘--salt=number’

Salt的长度。缺省为64。

22.   调用grub-mkrescue

程序grub-mkrescue产生一个可启动的GRUB救援映像(参考3.2节【制作一个GRUB可启动的CD-ROM】,7页)。

grub-mkrescue -o grub.iso

没有显式列出所有的参数,因为选项grub-mkrescue直接传给在mkisofs模拟模式中的xorriso。传给xorriso的选项通常将被解释为mkisofs的选项;如果使用了选项‘--’,那么后面跟着的东西将被解释为xorriso自己的选项。

非选项参数指定额外的源目录。这通常用于向映像中加入额外的文件:

mkdir -p disk/boot/grub

(向‘disk/boot/grub’加入额外文件)

grub-mkrescue -o grub.iso disk

grub-mkrescue接受以下选项:

‘--help’            打印该命令行的一个摘要并退出。

‘--version’ 打印GRUB的版本号并退出。

‘-ofile’

‘--output=file’

把输出保存入file。这个选项是必要的。

‘--modules=modules’

把具名的GRUB模块预载入映像中。modules中的多个项应该由空格分隔(因此你将可能需要在你的shell中引用之)。

‘--rom-directory=dir’

如果为QEMU或Coreboot平台产生映像,除了把生成的文件‘qemu.img’或‘coreboot.elf’ 包括入映像中,还分别把它们拷贝入目录dir。

‘--xorriso=file’

把file用作程序xorriso,而不是使用内建的。

‘--grub-mkimage=file’

把file用作程序grub-mkimage,而不是使用内建的。

23.   附录A

24.   附录B

25.   附录C

26.   附录D

 


原创粉丝点击