📄 grub.texi
字号:
@example@group# For booting Windows NT or Windows95title Windows NT / Windows 95 boot menuroot (hd0,0)makeactivechainloader +1# For loading DOS if Windows NT is installed# chainload /bootsect.dos@end group@end exampleThe same as the above, but for Windows.@example@group# For installing GRUB into the hard disktitle Install GRUB into the hard diskroot (hd0,0)setup (hd0)@end group@end exampleThis will just (re)install GRUB onto the hard disk.@example# Change the colors.title Change the colorscolor light-green/brown blink-red/blue@end exampleIn the last entry, the command @command{color} is used (@pxref{color}),to change the menu colors (try it!). This command is somewhat special,because it can be used both in the command-line and in the menu. GRUBhas several such commands, see @ref{General commands}.We hope that you now understand how to use the basic features ofGRUB. To learn more about GRUB, see the following chapters.@node Network@chapter Downloading OS images from a networkAlthough GRUB is a disk-based boot loader, it does provide networksupport. To use the network support, you need to enable at least onenetwork driver in the GRUB build process. For more information pleasesee @file{netboot/README.netboot} in the source distribution.@menu* General usage of network support::* Diskless::@end menu@node General usage of network support@section How to set up your networkGRUB requires a file server and optionally a server that will assign anIP address to the machine on which GRUB is running. For the former, onlyTFTP is supported at the moment. The latter is either BOOTP, DHCP or aRARP server@footnote{RARP is not advised, since it cannot serve muchinformation}. It is not necessary to run both the servers on onecomputer. How to configure these servers is beyond the scope of thisdocument, so please refer to the manuals specific to thoseprotocols/servers.If you decided to use a server to assign an IP address, set up theserver and run @command{bootp} (@pxref{bootp}), @command{dhcp}(@pxref{dhcp}) or @command{rarp} (@pxref{rarp}) for BOOTP, DHCP or RARP,respectively. Each command will show an assigned IP address, a netmask,an IP address for your TFTP server and a gateway. If any of theaddresses is wrong or it causes an error, probably the configuration ofyour servers isn't set up properly.Otherwise, run @command{ifconfig}, like this:@examplegrub> @kbd{ifconfig --address=192.168.110.23 --server=192.168.110.14}@end exampleYou can also use @command{ifconfig} in conjuction with @command{bootp},@command{dhcp} or @command{rarp} (e.g. to reassign the server addressmanually). @xref{ifconfig}, for more details.Finally, download your OS images from your network. The network can beaccessed using the network drive @samp{(nd)}. Everything else is verysimilar to the normal instructions (@pxref{Booting}).Here is an example:@example@groupgrub> @kbd{bootp}Probing... [NE*000]NE2000 base ...Address: 192.168.110.23 Netmask: 255.255.255.0Server: 192.168.110.14 Gateway: 192.168.110.1grub> @kbd{root (nd)}grub> @kbd{kernel /tftproot/gnumach.gz root=sd0s1}grub> @kbd{module /tftproot/serverboot.gz}grub> @kbd{boot}@end group@end example@node Diskless@section Booting from a networkIt is sometimes very useful to boot from a network, especially when youuse a machine which has no local disk. In this case, you need to obtaina kind of Net Boot @sc{rom}, such as a PXE @sc{rom} or a free softwarepackage like Etherboot. Such a Boot @sc{rom} first boots the machine,sets up the network card installed into the machine, and downloads asecond stage boot image from the network. Then, the second image willtry to boot an operating system actually from the network.GRUB provides two second stage images, @file{nbgrub} and@file{pxegrub} (@pxref{Images}). These images are the same as thenormal Stage 2, except that they set up a network automatically, and tryto load a configuration file from the network, if specified. The usageis very simple: If the machine has a PXE @sc{rom}, use@file{pxegrub}. If the machine has an NBI loader such as Etherboot, use@file{nbgrub}. There is no difference between them except theirformats. Since the way to load a second stage image you want to useshould be described in the manual on your Net Boot @sc{rom}, pleaserefer to the manual, for more information.However, there is one thing specific to GRUB. Namely, how to specify aconfiguration file in a BOOTP/DHCP server. For now, GRUB uses the tag@samp{150}, to get the name of a configuration file. The following is anexample with a BOOTP configuration:@example@group.allhost:hd=/tmp:bf=null:\ :ds=145.71.35.1 145.71.32.1:\ :sm=255.255.254.0:\ :gw=145.71.35.1:\ :sa=145.71.35.5:foo:ht=1:ha=63655d0334a7:ip=145.71.35.127:\ :bf=/nbgrub:\ :tc=.allhost:\ :T150="(nd)/tftpboot/menu.lst.foo":@end group@end exampleNote that you should specify the drive name @code{(nd)} in the name ofthe configuration file. This is because you might change the root drivebefore downloading the configuration from the TFTP server when thepreset menu feature is used (@pxref{Preset Menu}).See the manual of your BOOTP/DHCP server for more information. Theexact syntax should differ a little from the example.@node Serial terminal@chapter Using GRUB via a serial lineThis chapter describes how to use the serial terminal support in GRUB.If you have many computers or computers with no display/keyboard, itcould be very useful to control the computers through serialcommunications. To connect one computer with another via a serial line,you need to prepare a null-modem (cross) serial cable, and you may needto have multiport serial boards, if your computer doesn't have extraserial ports. In addition, a terminal emulator is also required, such asminicom. Refer to a manual of your operating system, for moreinformation.As for GRUB, the instruction to set up a serial terminal is quitesimple. First of all, make sure that you haven't specified the option@option{--disable-serial} to the configure script when you built yourGRUB images. If you get them in binary form, probably they have serialterminal support already.Then, initialize your serial terminal after GRUB starts up. Here is anexample:@example@groupgrub> @kbd{serial --unit=0 --speed=9600}grub> @kbd{terminal serial}@end group@end exampleThe command @command{serial} initializes the serial unit 0 with thespeed 9600bps. The serial unit 0 is usually called @samp{COM1}, so, ifyou want to use COM2, you must specify @samp{--unit=1} instead. Thiscommand accepts many other options, so please refer to @ref{serial},for more details.The command @command{terminal} (@pxref{terminal}) chooses which type ofterminal you want to use. In the case above, the terminal will be aserial terminal, but you can also pass @code{console} to the command,as @samp{terminal serial console}. In this case, a terminal in whichyou press any key will be selected as a GRUB terminal.However, note that GRUB assumes that your terminal emulator iscompatible with VT100 by default. This is true for most terminalemulators nowadays, but you should pass the option @option{--dumb} tothe command if your terminal emulator is not VT100-compatible orimplements few VT100 escape sequences. If you specify this option thenGRUB provides you with an alternative menu interface, because the normalmenu requires several fancy features of your terminal.@node Preset Menu@chapter Embedding a configuration file into GRUBGRUB supports a @dfn{preset menu} which is to be always loaded beforestarting. The preset menu feature is useful, for example, when yourcomputer has no console but a serial cable. In this case, it iscritical to set up the serial terminal as soon as possible, since youcannot see any message until the serial terminal begins to work. So itis good to run the commands @command{serial} (@pxref{serial}) and@command{terminal} (@pxref{terminal}) before anything else at thestart-up time.How the preset menu works is slightly complicated:@enumerate@itemGRUB checks if the preset menu feature is used, and loads the presetmenu, if available. This includes running commands and reading bootentries, like an ordinary configuration file.@itemGRUB checks if the configuration file is available. Note that this checkis performed @strong{regardless of the existence of the presetmenu}. The configuration file is loaded even if the preset menu wasloaded.@itemIf the preset menu includes any boot entries, they are cleared whenthe configuration file is loaded. It doesn't matter whether theconfiguration file has any entries or no entry. The boot entries in thepreset menu are used only when GRUB fails in loading the configurationfile.@end enumerateTo enable the preset menu feature, you must rebuild GRUB specifying afile to the configure script with the option@option{--enable-preset-menu}. The file has the same semantics asnormal configuration files (@pxref{Configuration}).Another point you should take care is that the diskless support(@pxref{Diskless}) diverts the preset menu. Diskless images embed apreset menu to execute the command @command{bootp} (@pxref{bootp})automatically, unless you specify your own preset menu to the configurescript. This means that you must put commands to initialize a network inthe preset menu yourself, because diskless images don't set it upimplicitly, when you use the preset menu explicitly.Therefore, a typical preset menu used with diskless support would belike this:@example@group# Set up the serial terminal, first of all.serial --unit=0 --speed=19200terminal --timeout=0 serial# Initialize the network.dhcp@end group@end example@node Security@chapter Protecting your computer from crackingYou may be interested in how to prevent ordinary users from doingwhatever they like, if you share your computer with other people. Sothis chapter describes how to improve the security of GRUB.One thing which could be a security hole is that the user can do toomany things with GRUB, because GRUB allows one to modify its configurationand run arbitrary commands at run-time. For example, the user can evenread @file{/etc/passwd} in the command-line interface by the command@command{cat} (@pxref{cat}). So it is necessary to disable all theinteractive operations.Thus, GRUB provides a @dfn{password} feature, so that only administratorscan start the interactive operations (i.e. editing menu entries andentering the command-line interface). To use this feature, you need torun the command @command{password} in your configuration file(@pxref{password}), like this:@examplepassword --md5 PASSWORD@end exampleIf this is specified, GRUB disallows any interactive control, until youpress the key @key{p} and enter a correct password. The option@option{--md5} tells GRUB that @samp{PASSWORD} is in MD5 format. If itis omitted, GRUB assumes the @samp{PASSWORD} is in clear text.You can encrypt your password with the command @command{md5crypt}(@pxref{md5crypt}). For example, run the grub shell (@pxref{Invoking thegrub shell}), and enter your password:@example@groupgrub> md5cryptPassword: **********Encrypted: $1$U$JK7xFegdxWH6VuppCUSIb.@end group@end exampleThen, cut and paste the encrypted password to your configuration file.Also, you can specify an optional argument to @command{password}. Seethis example:@examplepassword PASSWORD /boot/grub/menu-admin.lst@end exampleIn this case, GRUB will load @file{/boot/grub/menu-admin.lst} as aconfiguration file when you enter the valid password.Another thing which may be dangerous is that any user can choose anymenu entry. Usually, this wouldn't be problematic, but you might want topermit only administrators to run some of your menu entries, such as anentry for booting an insecure OS like DOS.GRUB provides the command @command{lock} (@pxref{lock}). This commandalways fails until you enter the valid password, so you can use it, likethis:@example@grouptitle Boot DOSlockrootnoverify (hd0,1)makeactivechainload +1@end group@end exampleYou should insert @command{lock} right after @command{title}, becauseany user can execute commands in an entry until GRUB encounters@command{lock}.You can also use the command @command{password} instead of@command{lock}. In this case the boot process will ask for the passwordand stop if it was entered incorrectly. Since the @command{password}takes its own @var{PASSWORD} argument this is useful if you wantdifferent passwords for different entries.@node Images@chapter GRUB image filesGRUB consists of several images: two essential stages, optional stagescalled @dfn{Stage 1.5}, and two network boot images. Here is a shortoverview of them. @xref{Internals}, for more details.@table @file@item stage1This is an essential image used for booting up GRUB. Usually, this isembedded in an MBR or the boot sector of a partition. Because a PC bootsector is 512 bytes, the size of this image is exactly 512 bytes.All @file{stage1} must do is to load Stage 2 or Stage 1.5 from a localdisk. Because of the size restriction, @file{stage1} encodes thelocation of Stage 2 (or Stage 1.5) in a block list format, so it neverunderstand any filesystem structure.@item stage2This is the core image of GRUB. It does everything but booting upitself. Usually, this is put in a filesystem, but that is not required.@item e2fs_stage1_5@itemx fat_stage1_5@itemx ffs_stage1_5@itemx jfs_stage1_5@itemx minix_stage1_5@itemx reiserfs_stage1_5@itemx vstafs_stage1_5@itemx xfs_stage1_5
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -