📄 grub.texi
字号:
that you can specify a drive/partition.Look at the following examples and explanations:@example(fd0)@end exampleFirst of all, GRUB requires that the device name be enclosed with@samp{(} and @samp{)}. The @samp{fd} part means that it is a floppydisk. The number @samp{0} is the drive number, which is counted from@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/lib/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}, and run the@command{grub-set-default} (@pxref{Invoking grub-set-default}) if youintend to use @samp{default saved} (@pxref{default}) in yourconfiguration file. Hereafter, the directory where GRUB images areinitially placed (normally @file{/usr/lib/grub/i386-pc}) will becalled the @dfn{image directory}, and the directory where the bootloader needs to find them (usually @file{/boot/grub}) will be calledthe @dfn{boot directory}.@menu* Creating a GRUB boot floppy::* Installing GRUB natively::* Installing GRUB using grub-install::* Making a GRUB bootable CD-ROM::@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/lib/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 Making a GRUB bootable CD-ROM@section Making a GRUB bootable CD-ROMGRUB supports the @dfn{no emulation mode} in the El Toritospecification@footnote{El Torito is a specification for bootable CDusing BIOS functions.}. This means that you can use the whole CD-ROMfrom GRUB and you don't have to make a floppy or hard disk image file,which can cause compatibility problems.For booting from a CD-ROM, GRUB uses a special Stage 2 called@file{stage2_eltorito}. The only GRUB files you need to have in your bootable CD-ROM are this @file{stage2_eltorito} and optionally a config file@file{menu.lst}. You don't need to use @file{stage1} or @file{stage2},because El Torito is quite different from the standard boot process.Here is an example of procedures to make a bootable CD-ROMimage. First, make a top directory for the bootable image, say,@samp{iso}:@example$ @kbd{mkdir iso}@end exampleMake a directory for GRUB:@example$ @kbd{mkdir -p iso/boot/grub}@end exampleCopy the file @file{stage2_eltorito}:@example$ @kbd{cp /usr/lib/grub/i386-pc/stage2_eltorito iso/boot/grub}@end exampleIf desired, make the config file @file{menu.lst} under @file{iso/boot/grub}(@pxref{Configuration}), and copy any files and directories for the disc to thedirectory @file{iso/}.Finally, make a ISO9660 image file like this:@example$ @kbd{mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot \ -boot-load-size 4 -boot-info-table -o grub.iso iso}@end exampleThis produces a file named @file{grub.iso}, which then can be burnedinto a CD (or a DVD). @kbd{mkisofs} has already set up the disc to bootfrom the @kbd{boot/grub/stage2_eltorito} file, so there is no need to setup GRUB on the disc. (Note that the @kbd{-boot-load-size 4} bit isrequired for compatibility with the BIOS on many older machines.)You can use the device @samp{(cd)} to access a CD-ROM in yourconfig file. This is not required; GRUB automatically sets the root device to @samp{(cd)} when booted from a CD-ROM. It is only necessary to refer to @samp{(cd)} if you want to access other drives as well.@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* Making your system robust:: How to make your system robust@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 to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -