📄 grub.texi
字号:
@emph{zero}. This expression means that GRUB will use the whole floppydisk.@example(hd0,1)@end exampleHere, @samp{hd} means it is a hard disk drive. The first integer@samp{0} indicates the drive number, that is, the first hard disk, whilethe second integer, @samp{1}, indicates the partition number (or the@sc{pc} slice number in the BSD terminology). Once again, please notethat the partition numbers are counted from @emph{zero}, not fromone. This expression means the second partition of the first hard diskdrive. In this case, GRUB uses one partition of the disk, instead of thewhole disk.@example(hd0,4)@end exampleThis specifies the first @dfn{extended partition} of the first hard diskdrive. Note that the partition numbers for extended partitions arecounted from @samp{4}, regardless of the actual number of primarypartitions on your hard disk.@example(hd1,a)@end exampleThis means the BSD @samp{a} partition of the second hard disk. If youneed to specify which @sc{pc} slice number should be used, use somethinglike this: @samp{(hd1,0,a)}. If the @sc{pc} slice number is omitted,GRUB searches for the first @sc{pc} slice which has a BSD @samp{a}partition.Of course, to actually access the disks or partitions with GRUB, youneed to use the device specification in a command, like @samp{root(fd0)} or @samp{unhide (hd0,2)}. To help you find out which numberspecifies a partition you want, the GRUB command-line(@pxref{Command-line interface}) options have argumentcompletion. This means that, for example, you only need to type@exampleroot (@end examplefollowed by a @key{TAB}, and GRUB will display the list of drives,partitions, or file names. So it should be quite easy to determine thename of your target partition, even with minimal knowledge of thesyntax.Note that GRUB does @emph{not} distinguish IDE from SCSI - it simplycounts the drive numbers from zero, regardless of their type. Normally,any IDE drive number is less than any SCSI drive number, although thatis not true if you change the boot sequence by swapping IDE and SCSIdrives in your BIOS.Now the question is, how to specify a file? Again, consider anexample:@example(hd0,0)/vmlinuz@end exampleThis specifies the file named @samp{vmlinuz}, found on the firstpartition of the first hard disk drive. Note that the argumentcompletion works with file names, too.That was easy, admit it. Now read the next chapter, to find out how toactually install GRUB on your drive.@node Installation@chapter InstallationIn order to install GRUB as your boot loader, you need to firstinstall the GRUB system and utilities under your UNIX-like operatingsystem (@pxref{Obtaining and Building GRUB}). You can do this eitherfrom the source tarball, or as a package for your OS.After you have done that, you need to install the boot loader on adrive (floppy or hard disk). There are two ways of doing that - eitherusing the utility @command{grub-install} (@pxref{Invokinggrub-install}) on a UNIX-like OS, or by running GRUB itself from afloppy. These are quite similar, however the utility might probe awrong BIOS drive, so you should be careful.Also, if you install GRUB on a UNIX-like OS, please make sure that youhave an emergency boot disk ready, so that you can rescue your computerif, by any chance, your hard drive becomes unusable (unbootable).GRUB comes with boot images, which are normally put in the directory@file{/usr/share/grub/i386-pc}. If you do not use grub-install, thenyou need to copy the files @file{stage1}, @file{stage2}, and@file{*stage1_5} to the directory @file{/boot/grub}. Hereafter, thedirectory where GRUB images are initially placed (normally@file{/usr/share/grub/i386-pc}) will be called the @dfn{imagedirectory}, and the directory where the boot loader needs to find them(usually @file{/boot/grub}) will be called the @dfn{boot directory}.@menu* Creating a GRUB boot floppy::* Installing GRUB natively::* Installing GRUB using grub-install::@end menu@node Creating a GRUB boot floppy@section Creating a GRUB boot floppyTo create a GRUB boot floppy, you need to take the files @file{stage1}and @file{stage2} from the image directory, and write them to the firstand the second block of the floppy disk, respectively.@strong{Caution:} This procedure will destroy any data currently storedon the floppy.On a UNIX-like operating system, that is done with the followingcommands:@example@group# @kbd{cd /usr/share/grub/i386-pc}# @kbd{dd if=stage1 of=/dev/fd0 bs=512 count=1}1+0 records in1+0 records out# @kbd{dd if=stage2 of=/dev/fd0 bs=512 seek=1}153+1 records in153+1 records out#@end group@end exampleThe device file name may be different. Consult the manual for your OS.@node Installing GRUB natively@section Installing GRUB natively@strong{Caution:} Installing GRUB's stage1 in this manner will erase thenormal boot-sector used by an OS.GRUB can currently boot GNU Mach, Linux, FreeBSD, NetBSD, and OpenBSDdirectly, so using it on a boot sector (the first sector of apartition) should be okay. But generally, it would be a good idea toback up the first sector of the partition on which you are installingGRUB's stage1. This isn't as important if you are installing GRUB onthe first sector of a hard disk, since it's easy to reinitialize it(e.g. by running @samp{FDISK /MBR} from DOS).If you decide to install GRUB in the native environment, which isdefinitely desirable, you'll need to create a GRUB boot disk, andreboot your computer with it. Otherwise, see @ref{Installing GRUB usinggrub-install}.Once started, GRUB will show the command-line interface(@pxref{Command-line interface}). First, set the GRUB's @dfn{rootdevice}@footnote{Note that GRUB's root device doesn't necessarily meanyour OS's root partition; if you need to specify a root partition foryour OS, add the argument into the command @command{kernel}.} to thepartition containing the boot directory, like this:@examplegrub> @kbd{root (hd0,0)}@end exampleIf you are not sure which partition actually holds this directory, use thecommand @command{find} (@pxref{find}), like this:@examplegrub> @kbd{find /boot/grub/stage1}@end exampleThis will search for the file name @file{/boot/grub/stage1} and show thedevices which contain the file.Once you've set the root device correctly, run the command@command{setup} (@pxref{setup}):@examplegrub> @kbd{setup (hd0)}@end exampleThis command will install the GRUB boot loader on the Master BootRecord (MBR) of the first drive. If you want to put GRUB into the bootsector of a partition instead of putting it in the MBR, specify thepartition into which you want to install GRUB:@examplegrub> @kbd{setup (hd0,0)}@end exampleIf you install GRUB into a partition or a drive other than the firstone, you must chain-load GRUB from another boot loader. Refer to themanual for the boot loader to know how to chain-load GRUB.After using the setup command, you will boot into GRUB without theGRUB floppy. See the chapter @ref{Booting} to find out how to bootyour operating systems from GRUB.@node Installing GRUB using grub-install@section Installing GRUB using grub-install@strong{Caution:} This procedure is definitely less safe, becausethere are several ways in which your computer can becomeunbootable. For example, most operating systems don't tell GRUB how tomap BIOS drives to OS devices correctly---GRUB merely @dfn{guesses}the mapping. This will succeed in most cases, but notalways. Therefore, GRUB provides you with a map file called the@dfn{device map}, which you must fix if it is wrong. @xref{Devicemap}, for more details.If you still do want to install GRUB under a UNIX-like OS (suchas @sc{gnu}), invoke the program @command{grub-install} (@pxref{Invokinggrub-install}) as the superuser (@dfn{root}).The usage is basically very simple. You only need to specify oneargument to the program, namely, where to install the boot loader. Theargument can be either a device file (like @samp{/dev/hda}) or apartition specified in GRUB's notation. For example, under Linux thefollowing will install GRUB into the MBR of the first IDE disk:@example# @kbd{grub-install /dev/hda}@end exampleLikewise, under GNU/Hurd, this has the same effect:@example# @kbd{grub-install /dev/hd0}@end exampleIf it is the first BIOS drive, this is the same as well:@example# @kbd{grub-install '(hd0)'}@end exampleOr you can omit the parentheses:@example# @kbd{grub-install hd0}@end exampleBut all the above examples assume that GRUB should use images underthe root directory. If you want GRUB to use images under a directoryother than the root directory, you need to specify the option@option{--root-directory}. The typical usage is that you create a GRUBboot floppy with a filesystem. Here is an example:@example@group# @kbd{mke2fs /dev/fd0}# @kbd{mount -t ext2 /dev/fd0 /mnt}# @kbd{grub-install --root-directory=/mnt fd0}# @kbd{umount /mnt}@end group@end exampleAnother example is when you have a separate boot partitionwhich is mounted at @file{/boot}. Since GRUB is a boot loader, itdoesn't know anything about mountpoints at all. Thus, you need to run@command{grub-install} like this:@example# @kbd{grub-install --root-directory=/boot /dev/hda}@end exampleBy the way, as noted above, it is quite difficult to guess BIOS drivescorrectly under a UNIX-like OS. Thus, @command{grub-install} will promptyou to check if it could really guess the correct mappings, after theinstallation. The format is defined in @ref{Device map}. Please bequite careful. If the output is wrong, it is unlikely that yourcomputer will be able to boot with no problem.Note that @command{grub-install} is actually just a shell script and thereal task is done by the grub shell @command{grub} (@pxref{Invoking thegrub shell}). Therefore, you may run @command{grub} directly to installGRUB, without using @command{grub-install}. Don't do that, however,unless you are very familiar with the internals of GRUB. Installing aboot loader on a running OS may be extremely dangerous.@node Booting@chapter BootingGRUB can load Multiboot-compliant kernels in a consistent way,but for some free operating systems you need to use some OS-specificmagic.@menu* General boot methods:: How to boot OSes with GRUB generally* OS-specific notes:: Notes on some operating systems@end menu@node General boot methods@section How to boot operating systemsGRUB has two distinct boot methods. One of the two is to load anoperating system directly, and the other is to chain-load another bootloader which then will load an operating system actually. Generallyspeaking, the former is more desirable, because you don't need toinstall or maintain other boot loaders and GRUB is flexible enough toload an operating system from an arbitrary disk/partition. However,the latter is sometimes required, since GRUB doesn't support all theexisting operating systems natively.@menu* Loading an operating system directly::* Chain-loading::@end menu@node Loading an operating system directly@subsection How to boot an OS directly with GRUBMultiboot (@pxref{Top, Multiboot Specification, Motivation, multiboot,The Multiboot Specification}) is the native format supported by GRUB.For the sake of convenience, there is also support for Linux, FreeBSD,NetBSD and OpenBSD. If you want to boot other operating systems, youwill have to chain-load them (@pxref{Chain-loading}).Generally, GRUB can boot any Multiboot-compliant OS in the followingsteps:@enumerate@itemSet GRUB's root device to the drive where the OS images are stored withthe command @command{root} (@pxref{root}).@itemLoad the kernel image with the command @command{kernel} (@pxref{kernel}).@itemIf you need modules, load them with the command @command{module}(@pxref{module}) or @command{modulenounzip} (@pxref{modulenounzip}).@itemRun the command @command{boot} (@pxref{boot}).@end enumerateLinux, FreeBSD, NetBSD and OpenBSD can be booted in a similarmanner. You load a kernel image with the command @command{kernel} andthen run the command @command{boot}. If the kernel requires someparameters, just append the parameters to @command{kernel}, after thefile name of the kernel. Also, please refer to @ref{OS-specific notes},for information on your OS-specific issues.@node Chain-loading@subsection Load another boot loader to boot unsupported operating systemsIf you want to boot an unsupported operating system (e.g. Windows 95),chain-load a boot loader for the operating system. Normally, the bootloader is embedded in the @dfn{boot sector} of the partition on whichthe operating system is installed.@enumerate@itemSet GRUB's root device to the partition by the command@command{rootnoverify} (@pxref{rootnoverify}):@examplegrub> @kbd{rootnoverify (hd0,0)}@end example@itemSet the @dfn{active} flag in the partition using the command@command{makeactive}@footnote{This is not necessary for most of themodern operating systems.} (@pxref{makeactive}):@examplegrub> @kbd{makeactive}@end example@itemLoad the boot loader with the command @command{chainloader}(@pxref{chainloader}):@examplegrub> @kbd{chainloader +1}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -