📄 grub.texi
字号:
Here, @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 number is apartition you want, the GRUB command-line (@pxref{Command-lineinterface}) options have argument completion. That means that, forexample, you only need to type @samp{root (}, followed by a @key{TAB},and GRUB will display the list of drives, partitions, or file names, soit should be quite easy to determine the name of your target partition,even with minimal knowledge of the syntax.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, see this example:@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. Do read the next chapter, to find out how toactually install GRUB on your drive.@node Installation@chapter InstallationFirst, you need to have GRUB itself properly installed on your system,(@pxref{Obtaining and Building GRUB}) either from the source tarball, oras a package for your OS.To use GRUB, you need to install it on your drive. There are two ways ofdoing that - either using the utility @command{grub-install}(@pxref{Invoking grub-install}) on a UNIX-like OS, or by using thenative Stage 2. These are quite similar, however, the utility mightprobe a wrong BIOS drive, so better 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 installed in thedirectory @file{/usr/share/grub/i386-pc}. You need to copy the files@file{stage1}, @file{stage2}, and @file{*stage1_5} to the directory@file{/boot/grub}. Here the directory where GRUB images are installedand the directory where GRUB will use to find them are called @dfn{imagedirectory} and @dfn{boot directory}, respectively.@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 should be okay. But generally, itwould be a good idea to back up the first sector of the partition onwhich you are installing GRUB's stage1. This isn't as important if youare installing GRUB on the first sector of a hard disk, since it's easyto 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 the GRUB boot disk, andreboot your computer with it. Otherwise, see @ref{Installing GRUB usinggrub-install}, for more details.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 theboot directory, like this:@examplegrub> @kbd{root (hd0,0)}@end exampleIf you are not sure which partition actually holds these files, 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 GRUB on the MBR in the first drive. If youwant to install GRUB into the @dfn{boot sector} of a partition insteadof the MBR, specify a partition 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.Now you can boot GRUB without a GRUB floppy. See the chapter@ref{Booting} to find out how to boot your operating systems from GRUB.@node Installing GRUB using grub-install@section Installing GRUB using grub-install@strong{Caution:} This procedure is definitely deprecated, because thereare several posibilities that your computer can be unbootable. Forexample, most operating systems don't tell GRUB how to map BIOS drivesto OS devices correctly, GRUB merely @dfn{guesses} the mapping. Thiswill succeed in most cases, but not always. So GRUB provides you with auser-defined map file called @dfn{device map}, which you must fix, if itis wrong. @xref{Device map}, for more details.Unfortunately, if you 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 easy. You only need to specify one argumentto the program, namely, where to install GRUB. The argument can beeither of a device file or a GRUB's drive/partition. So, this willinstall GRUB into the MBR of the first IDE disk under Linux:@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 exampleBut all the above examples assume that you use GRUB 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 in case that 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 becareful enough. If the output is wrong, it is unlikely that yourcomputer can 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 BootingFor Multiboot-compliant kernels, GRUB can load them 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 genenerally* 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 desirable, because you don't need to install ormaintain other boot loaders and GRUB is flexible enough to load anoperating system from an arbitrary disk/partition. However, the latteris sometimes required, since GRUB doesn't support all the existingoperating 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 are 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 bythe command @command{root} (@pxref{root}).@itemLoad the kernel image by 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 can load a kernel image by 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 the 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 by 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 by the command @command{chainloader}(@pxref{chainloader}):@examplegrub> @kbd{chainloader +1}@end example@samp{+1} indicates that GRUB should read one sector from the start ofthe partition. The complete description about this syntax can be foundin @ref{Block list syntax}.@itemRun the command @command{boot} (@pxref{boot}).@end enumerateHowever, DOS and Windows have some deficiencies, so you might have touse more complicated instructions. @xref{DOS/Windows}, for moreinformation.@node OS-specific notes@section Some caveats on OS-specific issuesHere, we describe some caveats on several operating systems.@menu* GNU/Hurd::* GNU/Linux::* FreeBSD::* NetBSD::* OpenBSD::* DOS/Windows::
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -