5 Writing your own configuration file
5 编写你自己的配置文件
*************************************
GRUB is configured using 'grub.cfg', usually located under '/boot/grub'.This file is quite flexible, but most users will not need to write the whole thing by hand.
GRUB使用的配置为"grub.cfg",通常放在"/boot/grub"。这个文件非常灵活,然而大多数用户无需完全用手工去编写。
5.1 Simple configuration handling
5.1 简单的配置处理
=================================
The program 'grub-mkconfig' (*note Invoking grub-mkconfig::) generates 'grub.cfg' files suitable for most cases. It is suitable for use when upgrading a distribution, and will discover available kernels and attempt to generate menu entries for them.
这个"grub-mkconfig"程序(*注:调用grub-mkconfig)生成"grub.cfg"这适用于大部分情况。这个也适用于升级时一起配用,并且将发现有效的内核和尝试去生成它的菜单条目。
'grub-mkconfig' does have some limitations. While adding extra custom menu entries to the end of the list can be done by editing '/etc/grub.d/40_custom' or creating '/boot/grub/custom.cfg', changing the order of menu entries or changing their titles may require making complex changes to shell scripts stored in '/etc/grub.d/'. This may be improved in the future. In the meantime, those who feel that it would be easier to write 'grub.cfg' directly are encouraged to do so (*note Booting::, and *note Shell-like scripting::), and to disable any system provided by their distribution to automatically run 'grub-mkconfig'.
"grub-mkconfig"确实有一点局限性。然而可以通过添加额外的自定义菜单的列表可以通过编辑"/etc/grub.d/40_custom"来实现或创建"/boot/grub/custom.cfg",修改菜单项的顺序或修改它们的标题可能需要用到复杂的shell脚本去修改并储存到"/etc/grub.d/"。这可能在未来有所改进。在此期间,那些认为这样做将更容易地写好"grub.cfg"的人会直接地鼓励你这样做(*注:引导,和*注:shell-like scripting),并且去关闭任何系统所提供的自动运行"grub-mkconfig"的分配。
The file '/etc/default/grub' controls the operation of 'grub-mkconfig'. It is sourced by a shell script, and so must be valid POSIX shell input; normally, it will just be a sequence of 'KEY=value' lines, but if the value contains spaces or other special characters then it must be quoted. For example:
这个"/etc/default/grub"文件被控制操作自"grub-mkconfig"。它是源于一个shell脚本,所以必须具有有效的POSIX(可移植性操作系统接口)shell输入;它实际就是一列列"KEY=value"所组成的序列,但如果它的值包含空格或其他特殊的字符则必须以引号引用,例如:
GRUB_TERMINAL_INPUT="console serial"
Valid keys in '/etc/default/grub' are as follows:
"/etc/default/grub"里有效的关键点,如下:
'GRUB_DEFAULT'
The default menu entry. This may be a number, in which case it identifies the Nth entry in the generated menu counted from zero, or the title of a menu entry, or the special string 'saved'. Using the title may be useful if you want to set a menu entry as the default even though there may be a variable number of entries before it.
"GRUB_DEFAULT"
他是默认菜单项。它可能是一个数字,这种情况下它能够识别生成菜单中的第N个条目从零开始数。或是一个菜单条目的标题,或是一个特殊符串串"saved"。使用那个标题可能是有益的,如果你想要去设置一个默认的菜单项尽管它可能是一个以变量数作为的条目。
For example, if you have:
例如,如果你有:
menuentry 'Example GNU/Linux distribution' --class gnu-linux {
...
}
then you can make this the default using:
然后你可以使用这个default:
GRUB_DEFAULT='Example GNU/Linux distribution'
If you set this to 'saved', then the default menu entry will be that saved by 'GRUB_SAVEDEFAULT', 'grub-set-default', or 'grub-reboot'. The default is '0'.
如果你设置为"saved",那么默认菜单项将被保存为"GRUB_SAVEDEFAULT","grub-set-default",或"grub-reboot"。它的默认值为"0"。
'GRUB_SAVEDEFAULT'
If this option is set to 'true', then, when an entry is selected,save it as a new default entry for use by future runs of GRUB. This is only useful if 'GRUB_DEFAULT=saved'; it is a separate option because 'GRUB_DEFAULT=saved' is useful without this option, in conjunction with 'grub-set-default' or 'grub-reboot'. Unset by default. This option relies on the environment block, which may not be available in all situations (*note Environment block::).
"GRUB_SAVEDEFAULT"
如果将此选项设置为"true",那么,当一个条目被选中时,会将其结果保存为一个新的默认条目并提供给GRUB未来去运行。这是唯一有用的如"GRUB_DEFAULT=saved";因为它只有唯一一个单独选项"GRUB_DEFAULT=saved",相互协调于"grub-set-default"或"grub-reboot"。复原默认设置。这个选项依赖于环境,这在各种条件下可能不是有效的。(*注:Environment block)。
'GRUB_TIMEOUT'
Boot the default entry this many seconds after the menu is displayed, unless a key is pressed. The default is '5'. Set to '0' to boot immediately without displaying the menu, or to '-1' to wait indefinitely.
"GRUB_TIMEOUT"
启动显示菜单后默认多少秒进入默认项,除非一个键被按下。这里默认为"5"。设置为"0"则立即启动而没有显示菜单,或为"-1"则无限期等待。
'GRUB_HIDDEN_TIMEOUT'
Wait this many seconds for a key to be pressed before displaying the menu. If no key is pressed during that time, display the menu for the number of seconds specified in GRUB_TIMEOUT before booting the default entry. We expect that most people who use GRUB_HIDDEN_TIMEOUT will want to have GRUB_TIMEOUT set to '0' so that the menu is not displayed at all unless a key is pressed. Unset by default.
"GRUB_HIDDEN_TIMEOUT"
在按键被按下之后等待多少秒才显示菜单。如果没有按下按键,显示菜单中由GRUB_TIMEOUT指定的秒数引导到默认条目。我们预计大多数人使用 GRUB_HIDDEN_TIMEOUT 而又想把 GRUB_TIMEOUT 设置为"0" 因此那个菜单是不显示的除非一个键被按下。
'GRUB_HIDDEN_TIMEOUT_QUIET'
In conjunction with 'GRUB_HIDDEN_TIMEOUT', set this to 'true' to suppress the verbose countdown while waiting for a key to be pressed before displaying the menu. Unset by default.
"GRUB_HIDDEN_TIMEOUT_QUIET"
与"GRUB_HIDDEN_TIMEOUT"协同使用,设置它为"true"会抑制繁琐的倒计时 会等待一个显示菜单的键被按下。恢复默认设置。
'GRUB_DEFAULT_BUTTON'
"GRUB_DEFAULT_BUTTON"
'GRUB_TIMEOUT_BUTTON'
"GRUB_TIMEOUT_BUTTON"
'GRUB_HIDDEN_TIMEOUT_BUTTON'
"GRUB_HIDDEN_TIMEOUT_BUTTON"
'GRUB_BUTTON_CMOS_ADDRESS'
Variants of the corresponding variables without the '_BUTTON' suffix, used to support vendor-specific power buttons. *Note Vendor power-on keys.
"GRUB_BUTTON_CMOS_ADDRESS"
相应的变量变异没有"_BUTTON"后缀,用于支持特定供应商的电源按钮。*注:供应商开机键。
'GRUB_DISTRIBUTOR'
Set by distributors of GRUB to their identifying name. This is used to generate more informative menu entry titles.
"GRUB_DISTRIBUTOR"
由经销商设置GRUB显示名称。这是用于生成更多信息到菜单条目的标题。
'GRUB_TERMINAL_INPUT'
Select the terminal input device. You may select multiple devices here, separated by spaces.
"GRUB_TERMINAL_INPUT"
选择终端输入设备。在这里你可以选择多个设备,用空格作分隔。
Valid terminal input names depend on the platform, but may include 'console' (PC BIOS and EFI consoles), 'serial' (serial terminal), 'ofconsole' (Open Firmware console), 'at_keyboard' (PC AT keyboard, mainly useful with Coreboot), or 'usb_keyboard' (USB keyboard using the HID Boot Protocol, for cases where the firmware does not handle this).
有效的终端输入名称取决于平台,但可能包括"console"(PC BIOS和EFIconsoles控制台),"serial"(串口控制台),"ofconsole"(开放固件控制台),"at_keyboard"(PC机键盘,主要有助于Coreboot:段尾解析),或"usb_keyboard"(使用HID启动协议的USB键盘,当固件不处理这个问题的情况下。)
注Coreboot:
LinuxBIOS 計劃,一個 Free Software 的計劃,企圖取代掉現今多數電腦上的 BIOS 已經改名稱為 coreboot。實際上 coreboot 只是一個小型驅動硬體的韌體,只提供基本的硬體初始化,然後就把控制權交給其它眾多的載體之一。coreboot 並不是專為 Linux 而製作的,雖然它可以使用 Linux 核心來當作載體,像是你把 Linux 核心放到你的 flash ROM 晶片上面跟 coreboot 放在一起,或是間接透過 FILO 或 GRUB2 來啟動 Linux 核心,不過透過適當的載體也可以用來啟動其它作業系統像是 Plan 9、Windows、FreeBSD 等。(以上引自:http://www.oschina.net/p/coreboot/)
注HID:
是Human Interface Device的缩写,由其名称可以了解HID设备是直接与人交互的设备,例如键盘、鼠标与游戏杆等。不过HID设备并不一定要有人机接口,只要符合HID类别规范的设备都是HID设备(引自:http://baike.baidu.com/link?url=e71NiaE ... -0WQo7vIla)
The default is to use the platform's native terminal input.
它默认是使用平台的本地终端输入。
'GRUB_TERMINAL_OUTPUT'
Select the terminal output device. You may select multiple devices here, separated by spaces.
"GRUB_TERMINAL_OUTPUT"
选择终端输出设备。这里你可以选择多个设备,用空格分开。
Valid terminal output names depend on the platform, but may include 'console' (PC BIOS and EFI consoles), 'serial' (serial terminal), 'gfxterm' (graphics-mode output), 'ofconsole' (Open Firmware console), or 'vga_text' (VGA text output, mainly useful with Coreboot).
有效的终端输出名称取决于平台,但可能包括"console"(PC BIOS和EFIconsoles控制台),"serial"(串口控制台),"gfxterm"(图形-模式 输出),"ofconsole"(开放固件控制台),或"vga_text"(带VGA驱动的文本输出模式,主要有助于使用Coreboot)。
The default is to use the platform's native terminal output.
它默认是使用平台的本地终端输入。
'GRUB_TERMINAL'
If this option is set, it overrides both 'GRUB_TERMINAL_INPUT' and 'GRUB_TERMINAL_OUTPUT' to the same value.
"GRUB_TERMINAL"
如果设置了这个选项,它会覆盖"GRUB_TERMINAL_INPUT"与"GRUB_TERMINAL_OUTPUT"这两个功能里相同的值。
'GRUB_SERIAL_COMMAND'
A command to configure the serial port when using the serial console. *Note serial::. Defaults to 'serial'.
"GRUB_SERIAL_COMMAND"
当使用串行控制台时的一个串行端口配置命令。*注:serial。它默认值为"serial"。
'GRUB_CMDLINE_LINUX'
Command-line arguments to add to menu entries for the Linux kernel.
"GRUB_CMDLINE_LINUX"
命令行参数添加到Linux内核的菜单条目。
'GRUB_CMDLINE_LINUX_DEFAULT'
Unless 'GRUB_DISABLE_RECOVERY' is set to 'true', two menu entries will be generated for each Linux kernel: one default entry and one entry for recovery mode. This option lists command-line arguments to add only to the default menu entry, after those listed in 'GRUB_CMDLINE_LINUX'.
"GRUB_CMDLINE_LINUX_DEFAULT"
除非"GRUB_DISABLE_RECOVERY"设置为"true",否则这两个菜单条目将生成各自的Linux内核:一个默认条目和一个恢复模式的条目。这个命令行选项列表的参数只能添加到默认菜单条目,在那些"GRUB_CMDLINE_LINUX"列表的后面。
'GRUB_CMDLINE_NETBSD'
'GRUB_CMDLINE_NETBSD_DEFAULT' As 'GRUB_CMDLINE_LINUX' and 'GRUB_CMDLINE_LINUX_DEFAULT', but for NetBSD.
"GRUB_CMDLINE_NETBSD"
"GRUB_CMDLINE_NETBSD_DEFAULT" 如同 "GRUB_CMDLINE_LINUX"于"GRUB_CMDLINE_LINUX_DEFAULT"的关系一样,但区分于NetBSD。
'GRUB_CMDLINE_GNUMACH'
as 'GRUB_CMDLINE_LINUX', but for GNU Mach.
"GRUB_CMDLINE_GNUMACH"
和"GRUB_CMDLINE_LINUX"一样,但除了GNU Mach。
'GRUB_CMDLINE_XEN'
'GRUB_CMDLINE_XEN_DEFAULT'
The values of these options are appended to the values of 'GRUB_CMDLINE_LINUX' and 'GRUB_CMDLINE_LINUX_DEFAULT' for Linux and Xen menu entries.
"GRUB_CMDLINE_XEN"
"GRUB_CMDLINE_XEN_DEFAULT"
这些选项的值会附加到"GRUB_CMDLINE_LINUX"与"GRUB_CMDLINE_LINUX_DEFAULT"里对应的Linux和Xen菜单条目的值里。
注:
Xen 是一个开放源代码虚拟机监视器,一个基于X86架构、发展最快、性能最稳定、占用资源最少的开源虚拟化技术。由剑桥大学开发。(引自:http://baike.baidu.com/link?url=koikxgr ... -qZ52dKaiK)
'GRUB_CMDLINE_LINUX_XEN_REPLACE'
'GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT'
The values of these options replace the values of 'GRUB_CMDLINE_LINUX' and 'GRUB_CMDLINE_LINUX_DEFAULT' for Linux and Xen menu entries.
"GRUB_CMDLINE_LINUX_XEN_REPLACE"
"GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT"
这些选项的值会替换到"GRUB_CMDLINE_LINUX"与"GRUB_CMDLINE_LINUX_DEFAULT"里对应的Linux和Xen菜单条目里的值。
'GRUB_DISABLE_LINUX_UUID'
Normally, 'grub-mkconfig' will generate menu entries that use universally-unique identifiers (UUIDs) to identify the root filesystem to the Linux kernel, using a 'root=UUID=...' kernel parameter. This is usually more reliable, but in some cases it may not be appropriate. To disable the use of UUIDs, set this option to 'true'.
"GRUB_DISABLE_LINUX_UUID"
通常地,"grub-mkconfig"将使用全局唯一标识符(UUIDs)来生成菜单条目确定Linux内核的根文件系统,利用"root=UUID=..."内核参数。这通常更加可靠,但在一些案例它可能不是适当的。要禁止使用UUIDs,这个选项设置为"true"。
'GRUB_DISABLE_RECOVERY'
If this option is set to 'true', disable the generation of recovery mode menu entries.
"GRUB_DISABLE_RECOVERY"
如果这个选项设置为"true",则会关闭生成恢复模式的菜单条目。
'GRUB_VIDEO_BACKEND'
If graphical video support is required, either because the 'gfxterm' graphical terminal is in use or because 'GRUB_GFXPAYLOAD_LINUX' is set, then 'grub-mkconfig' will normally load all available GRUB video drivers and use the one most appropriate for your hardware. If you need to override this for some reason, then you can set this option.
"GRUB_VIDEO_BACKEND"
如果需要支持图形视频,要么"gfxterm"图形终端被使用或要么"GRUB_GFXPAYLOAD_LINUX"被设置,然后"grub-mkconfig"将通常加载所有有效的GRUB视频驱动程序并且使用一个最适合你的硬件驱动。
After 'grub-install' has been run, the available video drivers are listed in '/boot/grub/video.lst'.
在 "grub-install" 被运行结束之后,那些可用的视频驱动程序会在 "/boot/grub/video.lst"里列出。
'GRUB_GFXMODE'
Set the resolution used on the 'gfxterm' graphical terminal. Note that you can only use modes which your graphics card supports via VESA BIOS Extensions (VBE), so for example native LCD panel resolutions may not be available. The default is 'auto', which tries to select a preferred resolution. *Note gfxmode.
"GRUB_GFXMODE"
使用"gfxterm"图形终端去设置图像分辨率。注意你唯一只能使用通过支持VESA BIOS Extensions(VBE:视频电子标准协会 BIOS 扩展)的显卡,因此某些本地液晶屏分辨率可能不适用。它默认为"auto",它试图选择一个首选的分辨率。*注:gfxmode
'GRUB_BACKGROUND'
Set a background image for use with the 'gfxterm' graphical terminal. The value of this option must be a file readable by GRUB at boot time, and it must end with '.png', '.tga', '.jpg', or '.jpeg'. The image will be scaled if necessary to fit the screen.
"GRUB_BACKGROUND"
从"gfxterm"图形终端里设置使用的背景图片。在GRUB启动的过程中这个选项的值必须是一个可读的文件,而且它必须以".png",".tga",".jpg"或"jpeg"为结尾。为了适应屏幕的需要图像会被缩放。
'GRUB_THEME'
Set a theme for use with the 'gfxterm' graphical terminal.
"GRUB_THEME"
设置一个主题使用自"gfxterm"图形终端。
'GRUB_GFXPAYLOAD_LINUX'
Set to 'text' to force the Linux kernel to boot in normal text mode, 'keep' to preserve the graphics mode set using 'GRUB_GFXMODE', 'WIDTHxHEIGHT'['xDEPTH'] to set a particular graphics mode, or a sequence of these separated by commas or semicolons to try several modes in sequence. *Note gfxpayload.
"GRUB_GFXPAYLOAD_LINUX"
设置到"text"促使Linux内核启动到标准的文本模式,使用"GRUB_GFXMODE"里的"keep"能保存图形模式的设置,"WIDTHxHEIGHT"["xDEPTH"]能设置特定的图形模式,这些序列以逗号分隔或用分号去尝试几个模式序列。*注:gfxpayload
Depending on your kernel, your distribution, your graphics card, and the phase of the moon, note that using this option may cause GNU/Linux to suffer from various display problems, particularly during the early part of the boot sequence. If you have problems, set this option to 'text' and GRUB will tell Linux to boot in normal text mode.
根据你的内核,你的配置,你的显卡,和月亮的圆缺,注意使用这个选项可能引起 GNU/Linux 遭受来自各种各样的显示问题,特别是在早期的那部分启动循序。
'GRUB_DISABLE_OS_PROBER'
Normally, 'grub-mkconfig' will try to use the external 'os-prober' program, if installed, to discover other operating systems installed on the same system and generate appropriate menu entries for them. Set this option to 'true' to disable this.
"GRUB_DISABLE_OS_PROBER"
通常地,"grub-mkconfig"将尝试去使用一个外部的"os-prober"程序,如果已安装,则在上述系统上去发现其他已安装了的操作系统并且生成相应的菜单项。这个设置选项的"true"为关闭。
'GRUB_INIT_TUNE'
Play a tune on the speaker when GRUB starts. This is particularly useful for users unable to see the screen. The value of this option is passed directly to *note play.
"GRUB_INIT_TUNE"
当GRUB启动时从扬声器演奏一首曲子。这是对于无法看到屏幕上的用户尤其有用。它选项的值请直接转到 *便签:play。
'GRUB_BADRAM'
If this option is set, GRUB will issue a *note badram:: command to filter out specified regions of RAM.
"GRUB_BADRAM"
如果将此选项设置,GRUB将发出一个命令去过滤掉指定内存(RAM)区域。*注:badram。
'GRUB_PRELOAD_MODULES'
This option may be set to a list of GRUB module names separated by spaces. Each module will be loaded as early as possible, at the start of 'grub.cfg'.
"GRUB_PRELOAD_MODULES"
这个选项可以设置为一个列表而其中的GRUB模块名字要以空格键来分隔开。模块之间将从前往后地合理地被加载,在"grub.cfg"的开始阶段。
For more detailed customisation of 'grub-mkconfig''s output, you may edit the scripts in '/etc/grub.d' directly. '/etc/grub.d/40_custom' is particularly useful for adding entire custom menu entries; simply type the menu entries you want to add at the end of that file, making sure to leave at least the first two lines intact.
要更多详尽的定制化"grub-mkconfig"输出,你可以直接编辑位于"/etc/grub.d"的脚本。"etc/grub.d/40_custom"对于添加完整的定义菜单项目是格外有用的;只需把你想输入的菜单条目在文件的末尾添加,确保离开时最后的两行是原封不动的。
5.2 Writing full configuration files directly
5.2 直接写完整的配置文件
=============================================
'grub.cfg' is written in GRUB's built-in scripting language, which has a syntax quite similar to that of GNU Bash and other Bourne shell derivatives.
"grub.cfg"是写自GRUB内建的脚本语言,它的语法相当类似于GNU Bash及其他Bourne shell衍生产品。
Words
语句
=====
A "word" is a sequence of characters considered as a single unit by GRUB. Words are separated by "metacharacters", which are the following plus space, tab, and newline:
一个"词"是一个字符序列成为GRUB的一个单元。单词隔开自"元标签字符串",下述哪一些加上空格符,制表符与新行符:
{ } | & $ ; < >
Quoting may be used to include metacharacters in words; see below.
引用也许用到包含元字符的单词;见下文。
Reserved words
保留单词
==============
Reserved words have a special meaning to GRUB. The following words are recognised as reserved when unquoted and either the first word of a simple command or the third word of a 'for' command:
保留单词在GRUB里具有特殊意义。这下列单词当未被引用时是公认为保留的 并且 一个简单的命令的第一个单词或第三个单词为一个"for"命令:
! [[ ]] { }
case do done elif else esac fi for function if in menuentry select then time until while
案例实现为elif(if...else)判断否则esac fi 于函数里 当如果之前在 menuentry 里选择了时间的时候。
Not all of these reserved words have a useful purpose yet; some are reserved for future expansion.
这些保留单词并不是全部都是有作用的;有些是留给未来的扩展。
Quoting
引用
=======
Quoting is used to remove the special meaning of certain characters or words. It can be used to treat metacharacters as part of a word, to prevent reserved words from being recognised as such, and to prevent variable expansion.
引用是用于是删除特殊含义的某些字符串或词句。它能用于被视为元字符串而作为词的一部分,为了防止保留单词被认为是这样的,和为了防止变量膨胀。
There are three quoting mechanisms: the escape character, single quotes, and double quotes.
这里有三个引用的作用机制:转义字符,单引号和双引号。
A non-quoted backslash (\) is the "escape character". It preserves the literal value of the next character that follows, with the exception of newline.
一个非引号内的反斜杠(\)是一个"转义字符(逃跑字符)"。它保留了紧跟其后的下一个字符的字面值,除了换行符。
Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.
包含在单引号内的字符串将保留引号内的每个字符的文本值。一个单引号内不能出现另一组单引号,即使在引号前加上反斜杠。
Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of '$' and '\'. The '$' character retains its special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters: '$', '"', '\', or newline. A backslash-newline pair is treated as a line continuation (that is, it is removed from the input stream and effectively ignored(1) (*note Shell-like scripting-Footnote-1::)). A double quote may be quoted within double quotes by preceding it with a backslash.
包含在双引号内的字符串将被保留在引号内的所有字符串文本值,除了"$" 和 "\" 除外。"$" 字符在双引号内保留了特别的意义。反斜杠保留其特殊意义 只有当一个紧随其后的下列字符之一:"$" "," "\"或换行符。一对 反斜杠-换行符 被当作一个行的延续。(也就是说,它是删除了输入流和有效地忽视)。一个双引号可以通过反斜杠在其内引用另一个双引号。
Variable expansion
变量扩展(对于高级语言来说,意思为变量赋值,往后则以此为名)
==================
The '$' character introduces variable expansion. The variable name to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.
"$"字符作用于变量赋值。变量的名字的赋值可能封闭在花括号内,这是可选的 然而 为了保护变量的字符串赋值 并且 紧跟着它可以被解析成名字的一部分。
Normal variable names begin with an alphabetic character, followed by zero or more alphanumeric characters. These names refer to entries in the GRUB environment (*note Environment).
正常的变量名字以字母字符为开头,紧随为零个或更多字母数字的字符。这些名字请参考自GRUB 环境(GRUB environment)的条目。
Positional variable names consist of one or more digits. They represent parameters passed to function calls, with '$1' representing the first parameter, and so on.
位置的变量名字由一个或多个数字组成。它们代表为参数被传递到函数调用,用"$1"表示第一个参数,以此类推。
The special variable name '?' expands to the exit status of the most recently executed command. When positional variable names are active, other special variable names '@', '*' and '#' are defined and they expand to all positional parameters with necessary quoting, positional parameters without any quoting, and positional parameter count respectively.
特殊的变量名字"?"扩展到最近执行的命令的推出状态。当位置变量的名字为可用的时候,其他的特殊变量名字"@","*"和"#"为所有位置参数的定义和赋值去提供必要的引用,位置参数没有任何的引用,并且位置参数分别计数。
Comments
注释
========
A word beginning with '#' causes that word and all remaining characters on that line to be ignored.
在一个单词的前面加上"#"字符会导致这个词与这个词后面的在同一行上的所有字符都被忽视掉。
Simple commands
简单的命令
===============
A "simple command" is a sequence of words separated by spaces or tabs and terminated by a semicolon or a newline. The first word specifies the command to be executed. The remaining words are passed as arguments to the invoked command.
一个"简单命令"是一序列用空格分隔的单词或制表符与分号终止符或一个换行符。第一个字指定要执行的命令。剩余的词句作为参数传递给被调用的命令。
The return value of a simple command is its exit status. If the reserved word '!' precedes the command, then the return value is instead the logical negation of the command's exit status.
返回的值为简单命令的退出状态。如果保留字"!"在命令之前,那么返回的值是逻辑反的命令退出状态。
Compound commands
复合命令
=================
A "compound command" is one of the following:
for NAME in WORD ...; do LIST; done The list of words following 'in' is expanded, generating a list of items. The variable NAME is set to each element of this list in turn, and LIST is executed each time. The return value is the exit status of the last command that executes. If the expansion of the items following 'in' results in an empty list, no commands are executed, and the return status is 0.
一个"复合命令"是下列之一:
对于NAME在WORD之内...;做LIST;完成由词句组成列表遵循"in"去扩建,生成一个项目列表。这个变量NAME将依次被设置于这个列表的每个元素,然后LIST将按期执行一次。这个返回的值是执行的最后一个命令的退出状态。如果项目的赋值"in"的结果在一个空列表内,没有命令被执行,然后返回状态为"0"。
if LIST; then LIST; [elif LIST; then LIST;] ... [else LIST;] fi The 'if' LIST is executed. If its exit status is zero, the 'then' LIST is executed. Otherwise, each 'elif' LIST is executed in turn, and if its exit status is zero, the corresponding 'then' LIST is executed and the command completes. Otherwise, the 'else' LIST is executed, if present. The exit status is the exit status of the last command executed, or zero if no condition tested true.
如果LIST;那么LIST;[elif LIST;then LIST;]...[else LIST;] fi 那 "if" LIST 被执行。如果其退出状态是零,那"then"LIST 被执行。否则,每个 "elif" LIST 依次被执行,如果其退出状态是零,那相当于 "then" LIST 是被执行的并且命令完整执行。否则,那 "else" LIST 被执行,如果"else"是存在的。退出状态是最后一个命令执行后的退出状态,或如果环境测试没有返回true则为零。
while COND; do LIST; done
当 COND 的时候;做 LIST;完成
until COND; do LIST; done
在 COND 之前;做 LIST;完成
The 'while' command continuously executes the 'do' LIST as long as the last command in COND returns an exit status of zero. The 'until' command is identical to the 'while' command, except that the test is negated; the 'do' LIST is executed as long as the last command in COND returns a non-zero exit status. The exit status of the 'while' and 'until' commands is the exit status of the last 'do' LIST command executed, or zero if none was executed.
这个"while"命令不断执行那个"do" LIST 直到COND的最后一个命令并返回一个结束状态零。"until"命令是等同于"while"命令,除了它们的循环条件检测是相反的;"do"LIST 是不断执行直到COND完成最后一条命令后返回一个非零的退出状态。这个退出状态属于"while"和"until"命令在最后一次执行完"do"LIST命令时的退出状态,或 如果没有执行过"do"LIST则为零。
function NAME { COMMAND; ... }
This defines a function named NAME. The "body" of the function is the list of commands within braces, each of which must be terminated with a semicolon or a newline. This list of commands will be executed whenever NAME is specified as the name of a simple command. Function definitions do not affect the exit status in '$?'. When executed, the exit status of a function is the exit status of the last command executed in the body.
函数 NAME {命令;...}
这里定义一个函数名字NAME。函数的"主体(body)"里面的命令列表被包含在括号内,每一个各自的结束都必须用分号或换行符作终止。这个命令列表将被执行每当NAME被指定为一个简单的命令名。自定义函数里的"$?"不影响退出状态。在执行的时候,一个函数的退出状态是主体里执行到最后一条命令的结束时的退出状态。
menuentry TITLE ['--class=class' ...] ['--users=users'] ['--unrestricted'] ['--hotkey=key'] { COMMAND; ... } *Note menuentry.
Built-in Commands
内置命令
=================
Some built-in commands are also provided by GRUB script to help script writers perform actions that are otherwise not possible. For example, these include commands to jump out of a loop without fully completing it, etc.
一些内置命令也提供了GRUB脚本去帮助脚本编写者执行动作否则是不可能的。例如,这些包含跳出命令的循环没有被完全执行完,等等。
break ['n']
Exit from within a 'for', 'while', or 'until' loop. If 'n' is specified, break 'n' levels. 'n' must be greater than or equal to 1. If 'n' is greater than the number of enclosing loops, all enclosing loops are exited. The return value is 0 unless 'n' is not greater than or equal to 1.
break ['n']
离开自一个break位于其内的"for","while",或"until"循环。如果"n"被指定值,则返回"n"级。"n"必须大于或等于1。如果"n"大于其外的循环体数目,那所有的循环体会结束循环。它的返回值为0除非"n"为非大于或等于1。
continue ['n']
Resume the next iteration of the enclosing 'for', 'while' or 'until' loop. If 'n' is specified, resume at the 'n'th enclosing loop. 'n' must be greater than or equal to 1. If 'n' is greater than the number of enclosing loops, the last enclosing loop (the "top-level" loop) is resumed. The return value is 0 unless 'n' is not greater than or equal to 1.
continue ['n']
重新开始到下一次循环作用于包含其内的"for","while"或"until"循环。如果"n"被指定值,从新开始操作到"n"次以后作用于包含其内的循环。"n"必须大于或等于1。如果"n"大于包含其的循环的循环次数,则重新开始到包含其内的循环的最后一次循环(为"顶级"循环)。它的返回值为"0"除非"n"的值非大于或等于1。
return ['n']
Causes a function to exit with the return value specified by 'n'. If 'n' is omitted, the return status is that of the last command executed in the function body. If used outside a function the return status is false.
return ['n']
导致一个函数结束并返回指定为"n"的值。如果忽略掉"n",那返回状态为其函数体内的最后一条命令执行完时的返回状态。假如使用外部函数把返回状态定义为假。
shift ['n']
The positional parameters from 'n'+1 ... are renamed to '$1'.... Parameters represented by the numbers '$#' down to '$#'-'n'+1 are unset. 'n' must be a non-negative number less than or equal to '$#'. If 'n' is 0, no parameters are changed. If 'n' is not given, it is assumed to be 1. If 'n' is greater than '$#', the positional parameters are not changed. The return status is greater than zero if 'n' is greater than '$#' or less than zero; otherwise 0.
shift ['n']
位置参数从"n"+1... 被重命名为 "$1"... 参数所代表的数字 "$#" 往下到 "$#" - "n" + 1 被设置。"n"必须为非负的数字并且小于或等于"$#"。如果"n"为0,则没有参数被改变。如果"n"没给出,那它被假定为1。如果"n"大于那个"$#",那位置参数则不被改变。如果"n"是大于那个"$#"则其返回状态大于零或则小于零;否则为0。
(1) Currently a backslash-newline pair within a variable name is not handled properly, so use this feature with some care.
(1) 目前在一对 反斜杠-换行 内定义变量名字是处理不当的,所以使用这个特征会有一些好处。
5.3 Multi-boot manual config
5.3 多重-引导 手册 配置
============================
Currently autogenerating config files for multi-boot environments depends on os-prober and has several shortcomings. While fixing it is scheduled for the next release, meanwhile you can make use of the power of GRUB syntax and do it yourself. A possible configuration is detailed here, feel free to adjust to your needs.
一般地多重-引导环境会依赖于OS-探测器而自动生成配置文件虽然其有点缺点。而在下个发行版本的修复计划,你可以运用你的知识与力量去编写你自己的GRUB语法语句。一个详细的合理配置,感到自由地、免费的、解放...(free思想之意)地适合着你的需要。
First create a separate GRUB partition, big enough to hold GRUB. Some of the following entries show how to load OS installer images from this same partition, for that you obviously need to make the partition large enough to hold those images as well. Mount this partition on/mnt/boot and disable GRUB in all OSes and manually install self-compiled latest GRUB with:
首先创建一个单独的GRUB分区,大得足以容纳GRUB。以下技术示范条目为从同一个区里加载OS安装镜像,显然你的分区需要大得足够容纳这些镜像。挂载这个分区到 /mnt/boot 接着在所有操作系统里关闭GRUB并且手动安装 自主-编译 最新的GRUB:
'grub-install --boot-directory=/mnt/boot /dev/sda'
In all the OSes install GRUB tools but disable installing GRUB in bootsector, so you'll have menu.lst and grub.cfg available for use. Also disable os-prober use by setting:
在所有操作系统安装GRUB的工具但禁用安装GRUB到引导区,因此你将得到有效的 menu.lst 和 grub.cfg 以供使用。还要关闭 os-prober的使用通过设置:
'GRUB_DISABLE_OS_PROBER=true'
in /etc/default/grub Then write a grub.cfg (/mnt/boot/grub/grub.cfg):
在 /etc/default/grub 里去写 grub.cfg文件( /mnt/boot/grub/grub.cfg):
menuentry "OS using grub2" {
insmod xfs
search --set=root --label OS1 --hint hd0,msdos8
configfile /boot/grub/grub.cfg
}
menuentry "OS using grub2-legacy" {
insmod ext2
search --set=root --label OS2 --hint hd0,msdos6
legacy_configfile /boot/grub/menu.lst
}
menuentry "Windows XP" {
insmod ntfs
search --set=root --label WINDOWS_XP --hint hd0,msdos1
ntldr /ntldr
}
menuentry "Windows 7" {
insmod ntfs
search --set=root --label WINDOWS_7 --hint hd0,msdos2
ntldr /bootmgr
}
menuentry "FreeBSD" {
insmod zfs
search --set=root --label freepool --hint hd0,msdos7
kfreebsd /freebsd@/boot/kernel/kernel
kfreebsd_module_elf /freebsd@/boot/kernel/opensolaris.ko
kfreebsd_module_elf /freebsd@/boot/kernel/zfs.ko
kfreebsd_module /freebsd@/boot/zfs/zpool.cache type=/boot/zfs/zpool.cache
set kFreeBSD.vfs.root.mountfrom=zfs:freepool/freebsd
set kFreeBSD.hw.psm.synaptics_support=1
}
menuentry "experimental GRUB" {
search --set=root --label GRUB --hint hd0,msdos5
multiboot /experimental/grub/i386-pc/core.img
}
menuentry "Fedora 16 installer" {
search --set=root --label GRUB --hint hd0,msdos5
linux /fedora/vmlinuz lang=en_US keymap=sg resolution=1280x800
initrd /fedora/initrd.img
}
menuentry "Fedora rawhide installer" {
search --set=root --label GRUB --hint hd0,msdos5
linux /fedora/vmlinuz repo=ftp://mirror.switch.ch/mirror/fedora/li ... ide/x86_64 lang=en_US keymap=sg resolution=1280x800
initrd /fedora/initrd.img
}
menuentry "Debian sid installer" {
search --set=root --label GRUB --hint hd0,msdos5
linux /debian/dists/sid/main/installer-amd64/current/images/hd-media/vmlinuz
initrd /debian/dists/sid/main/installer-amd64/current/images/hd-media/initrd.gz
}
Notes:
* Argument to search after -label is FS LABEL. You can also use UUIDs with -fs-uuid UUID instead of -label LABEL. You could also use direct 'root=hd0,msdosX' but this is not recommened due to device name instability.
注释:
* 参数搜索FS LABEL在 -label 之后。你也可以用UUIDs以 -fs-uuid UUID 代替掉 -label LABEL,你还可以直接地使用 "root=hd0,msdosX" 但这是不推介的由于设备名并不稳定。
5.4 Embedding a configuration file into GRUB
5.4 将配置文件嵌入到GRUB
============================================
GRUB supports embedding a configuration file directly into the core image, so that it is loaded before entering normal mode. This is useful, for example, when it is not straightforward to find the real configuration file, or when you need to debug problems with loading that file. 'grub-install' uses this feature when it is not using BIOS disk functions or when installing to a different disk from the one containing '/boot/grub', in which case it needs to use the 'search' command (*note search) to find '/boot/grub'.
GRUB支持把配置文件直接地嵌入到核心镜像,以便它在加载后能进入正常模式。这是有益的,例如,因它要找到真正的配置文件是并不简单的,或当你需要去调试加载文件上的问题。"grub-install"使用此功能时不使用BIOS磁盘功能或当安装到一个包含" /boot/grub"的不同的磁盘,在这种情况下需要使用"search"命令去搜索 " /boot/grub"。(注:search)
To embed a configuration file, use the '-c' option to 'grub-mkimage'. The file is copied into the core image, so it may reside anywhere on the file system, and may be removed after running 'grub-mkimage'.
嵌入一个配置文件,使用 "-c"选项到"grub-mkimage"。配置文件被复制到核心镜像,所以它能够驻留在文件系统里的任何地方,并且或许在运行"grub-mkimage"之后删除。
After the embedded configuration file (if any) is executed, GRUB will load the 'normal' module (*note normal::), which will then read the real configuration file from '$prefix/grub.cfg'. By this point, the 'root' variable will also have been set to the root device name. For example, 'prefix' might be set to '(hd0,1)/boot/grub', and 'root' might be set to 'hd0,1'. Thus, in most cases, the embedded configuration file only needs to set the 'prefix' and 'root' variables, and then drop through to GRUB's normal processing. A typical example of this might look like this:
在嵌入配置文件之后(如果有)执行,GRUB将加载"normal"模块(注:normal),它将会读取真正的配置文件来自"$prefix/grub.cfg"。到此为止,"root"变量将被设置成根设备名。例如,"prefix"可能被设置为"(hd0,1)/boot/grub",并且"root"可能被设置为"hd0,1"。如此,大部分情况下,嵌入配置文件只需要设置"prefix"和"root"变量,并且向下递交到标准模式启动的GRUB进程。一个典型的例子看起来像这样:
search.fs_uuid 01234567-89ab-cdef-0123-456789abcdef root
set prefix=($root)/boot/grub
(The 'search_fs_uuid' module must be included in the core image for this example to work.)
("search_fs_uuid"模块必须包含到核心镜像并且在次例子中能运转)
In more complex cases, it may be useful to read other configuration files directly from the embedded configuration file. This allows such things as reading files not called 'grub.cfg', or reading files from a directory other than that where GRUB's loadable modules are installed. To do this, include the 'configfile' and 'normal' modules in the core image, and embed a configuration file that uses the 'configfile' command to load another file. The following example of this also requires the 'echo', 'search_label', and 'test' modules to be included in the core image:
在更复杂的情况下,它可能直接从嵌入的配置文件去读取其他有用的配置文件。这样允许那些被读文件不叫"grub.cfg",或读取文件自一个目录除了 GRUB去安装可加载模块 之外。要做到这些,把"configfile"和"normal"模块包含到核心镜像,并且嵌入一个配置文件以至于使用"configfile"命令去加载另一个文件。下列例子还需要用到 "echo","search_label",与 "test" 模块并被包含到核心镜像里:
search.fs_label grub root
if [ -e /boot/grub/example/test1.cfg ]; then
set prefix=($root)/boot/grub
configfile /boot/grub/example/test1.cfg
else
if [ -e /boot/grub/example/test2.cfg ]; then
set prefix=($root)/boot/grub
configfile /boot/grub/example/test2.cfg
else
echo "Could not find an example configuration file!"
fi
fi
The embedded configuration file may not contain menu entries directly, but may only read them from elsewhere using 'configfile'.
嵌入的配置文件可能不直接包含菜单条目,但可能只读于其他地方从而使用"configfile"。
GRUB2官方文档翻译项目2-05
-
- 帖子: 56
- 注册时间: 2011-11-01 14:22
-
- 帖子: 13
- 注册时间: 2014-03-20 8:58
- 系统: windowsxp
Re: GRUB2官方文档翻译项目2-05
Depending on your kernel, your distribution, your graphics card, and the phase of the moon, note that using this option may cause GNU/Linux to suffer from various display problems, particularly during the early part of the boot sequence. If you have problems, set this option to 'text' and GRUB will tell Linux to boot in normal text mode.
根据你的内核,你的配置,你的显卡,和月亮的圆缺,注意使用这个选项可能引起 GNU/Linux 遭受来自各种各样的显示问题,特别是在早期的那部分启动循序。
这个月亮的圆缺,好费解
根据你的内核,你的配置,你的显卡,和月亮的圆缺,注意使用这个选项可能引起 GNU/Linux 遭受来自各种各样的显示问题,特别是在早期的那部分启动循序。
这个月亮的圆缺,好费解
-
- 论坛版主
- 帖子: 18279
- 注册时间: 2009-08-04 16:33
Re: GRUB2官方文档翻译项目2-05
1. your distribution
http://zh.wikipedia.org/wiki/Linux%E5%8 ... C%E7%89%88
http://en.wikipedia.org/wiki/Linux_distribution
2. the phase of the moon
程序生命週期階段
http://en.wikipedia.org/wiki/Program_lifecycle_phase
http://www.ichacha.net/project%20life%20cycle.html
2-2. the phase of the moon
2-2-1. 月相階段 # 因為加了 the 定冠詞 表示一個特定的月相階段
2-3. Phases of the Moon # 因為 複數 表示所有的月相(階段)
http://zh.wikipedia.org/wiki/%E6%9C%88%E7%9B%B8
http://simple.wikipedia.org/wiki/Phases_of_the_Moon
1-1. 你的 (Linux) 發行版你的配置
http://zh.wikipedia.org/wiki/Linux%E5%8 ... C%E7%89%88
http://en.wikipedia.org/wiki/Linux_distribution
2. the phase of the moon
2-1. Program lifecycle phase月亮的圆缺
程序生命週期階段
http://en.wikipedia.org/wiki/Program_lifecycle_phase
http://www.ichacha.net/project%20life%20cycle.html
2-2. the phase of the moon
2-2-1. 月相階段 # 因為加了 the 定冠詞 表示一個特定的月相階段
2-3. Phases of the Moon # 因為 複數 表示所有的月相(階段)
http://zh.wikipedia.org/wiki/%E6%9C%88%E7%9B%B8
http://simple.wikipedia.org/wiki/Phases_of_the_Moon
-
- 帖子: 56
- 注册时间: 2011-11-01 14:22
Re: GRUB2官方文档翻译项目2-05
poloshiao 写了:1. your distribution1-1. 你的 (Linux) 發行版你的配置
http://zh.wikipedia.org/wiki/Linux%E5%8 ... C%E7%89%88
http://en.wikipedia.org/wiki/Linux_distribution
2. the phase of the moon2-1. Program lifecycle phase月亮的圆缺
程序生命週期階段
http://en.wikipedia.org/wiki/Program_lifecycle_phase
http://www.ichacha.net/project%20life%20cycle.html
2-2. moon
待補
因为本人理解能力差,还请需要指出修正的大大们,先在回帖的第一段贴出错误段落的内容,然后换行后再贴出更正好后的翻译,谢谢。

-
- 帖子: 13
- 注册时间: 2014-03-20 8:58
- 系统: windowsxp
Re: GRUB2官方文档翻译项目2-05
我猜3楼大侠的意思是:
Depending on your kernel, your distribution, your graphics card, and the phase of the moon, note that using this option may cause GNU/Linux to suffer from various display problems, particularly during the early part of the boot sequence. If you have problems, set this option to 'text' and GRUB will tell Linux to boot in normal text mode.
根据你的内核,你的配置(“发行版”),你的显卡,和月亮的圆缺(这里似乎建议将phase翻译做阶段,moon的解释还需要讨论),注意使用这个选项可能引起 GNU/Linux 遭受来自各种各样的显示问题,特别是在早期的那部分启动循序。
Depending on your kernel, your distribution, your graphics card, and the phase of the moon, note that using this option may cause GNU/Linux to suffer from various display problems, particularly during the early part of the boot sequence. If you have problems, set this option to 'text' and GRUB will tell Linux to boot in normal text mode.
根据你的内核,你的配置(“发行版”),你的显卡,和月亮的圆缺(这里似乎建议将phase翻译做阶段,moon的解释还需要讨论),注意使用这个选项可能引起 GNU/Linux 遭受来自各种各样的显示问题,特别是在早期的那部分启动循序。
-
- 论坛版主
- 帖子: 18279
- 注册时间: 2009-08-04 16:33
Re: GRUB2官方文档翻译项目2-05
1. 謝謝 小饼仙子 的幫忙我猜3楼大侠的意思是:
2. 上面 the phase of the moon 我已補上
3. 以上我提供的內容 純當參考用途
基於 繁體中文 與 簡體中文 可能還是 存在許多使用上的不同
不適合由我直接翻譯
還是請 小饼仙子 參酌 幫忙翻譯吧
-
- 帖子: 56
- 注册时间: 2011-11-01 14:22
Re: GRUB2官方文档翻译项目2-05
明白那句什么"月亮的圆缺"是个问题,但是那句"and the phase of the moon"我也不明白它的含义。
而我今早翻译13章的时候也同样出现了这句,卡着了。。。
还是明白此句含义的朋友直接给我贴上翻译好的内容,因为这句着实让我摸不着头脑。。。(只是香港台湾只用繁体不懂简体而已,其实大陆繁简体都有应用,不会看不懂,所以繁简也没所谓的。)
这里再次谢谢楼上2位大大的帮助,希望再次回帖的时候能找到更好的翻译修正。
而我今早翻译13章的时候也同样出现了这句,卡着了。。。
还是明白此句含义的朋友直接给我贴上翻译好的内容,因为这句着实让我摸不着头脑。。。(只是香港台湾只用繁体不懂简体而已,其实大陆繁简体都有应用,不会看不懂,所以繁简也没所谓的。)
这里再次谢谢楼上2位大大的帮助,希望再次回帖的时候能找到更好的翻译修正。
-
- 论坛版主
- 帖子: 18279
- 注册时间: 2009-08-04 16:33
Re: GRUB2官方文档翻译项目2-05
要精確翻譯 確實不容易明白那句什么"月亮的圆缺"是个问题,但是那句"and the phase of the moon"我也不明白它的含义。
而我今早翻译13章的时候也同样出现了这句,卡着了。。。
特別是 當 the phase of the moon 是一句通用的 俚語 或 俗語 時
例如 俚語 辭典
http://onlineslangdictionary.com/meanin ... f-the-moon
phase of the moon
a metaphorical condition that something depends on.
某件事所依賴於的隱喻條件
這句話
the phase of the moon
也許可以考慮翻譯成
星象註定(意思星象輪轉註定輪到它會發生)
麻煩 小饼仙子 幫忙 想一個合適 的翻譯吧