📄 grub.texi
字号:
install 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}@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::* SCO UnixWare::* QNX::@end menu@node GNU/Hurd@subsection GNU/HurdSince GNU/Hurd is Multiboot-compliant, it is easy to boot it; there isnothing special about it. But do not forget that you have to specify aroot partition to the kernel.@enumerate@itemSet GRUB's root device to the same drive as GNU/Hurd's. Probably thecommand @code{find /boot/gnumach} or similar can help you(@pxref{find}).@itemLoad the kernel and the module, like this:@example@groupgrub> @kbd{kernel /boot/gnumach root=hd0s1}grub> @kbd{module /boot/serverboot}@end group@end example@itemRun the command @command{boot} (@pxref{boot}).@end enumerate@node GNU/Linux@subsection GNU/LinuxIt is relatively easy to boot GNU/Linux from GRUB, because it somewhatresembles to boot a Multiboot-compliant OS.@enumerate@itemSet GRUB's root device to the same drive as GNU/Linux's. Probably thecommand @code{find /vmlinuz} or similar can help you (@pxref{find}).@itemLoad the kernel:@examplegrub> @kbd{kernel /vmlinuz root=/dev/hda1}@end exampleIf you need to specify some kernel parameters, just append them to thecommand. For example, to set @option{vga} to @samp{ext}, do this:@examplegrub> @kbd{kernel /vmlinuz root=/dev/hda1 vga=ext}@end exampleSee the documentation in the Linux source tree for completeinformation on the available options.@itemIf you use an initrd, execute the command @command{initrd}(@pxref{initrd}) after @command{kernel}:@examplegrub> @kbd{initrd /initrd}@end example@itemFinally, run the command @command{boot} (@pxref{boot}).@end enumerate@strong{Caution:} If you use an initrd and specify the @samp{mem=}option to the kernel to let it use less than actual memory size, youwill also have to specify the same memory size to GRUB. To let GRUB knowthe size, run the command @command{uppermem} @emph{before} loading thekernel. @xref{uppermem}, for more information.@node FreeBSD@subsection FreeBSDGRUB can load the kernel directly, either in ELF or a.out format. Butthis is not recommended, since FreeBSD's bootstrap interface sometimeschanges heavily, so GRUB can't guarantee to pass kernel parameterscorrectly.Thus, we'd recommend loading the very flexible loader@file{/boot/loader} instead. See this example:@example@groupgrub> @kbd{root (hd0,a)}grub> @kbd{kernel /boot/loader}grub> @kbd{boot}@end group@end example@node NetBSD@subsection NetBSDGRUB can load NetBSD a.out and ELF directly, follow these steps:@enumerate@itemSet GRUB's root device with @command{root} (@pxref{root}).@itemLoad the kernel with @command{kernel} (@pxref{kernel}). You shouldappend the ugly option @option{--type=netbsd}, if you want to load anELF kernel, like this:@examplegrub> @kbd{kernel --type=netbsd /netbsd-elf}@end example@itemRun @command{boot} (@pxref{boot}).@end enumerateFor now, however, GRUB doesn't allow you to pass kernel parameters, soit may be better to chain-load it instead. For more information, pleasesee @ref{Chain-loading}.@node OpenBSD@subsection OpenBSDThe booting instruction is exactly the same as for NetBSD(@pxref{NetBSD}).@node DOS/Windows@subsection DOS/WindowsGRUB cannot boot DOS or Windows directly, so you must chain-load them(@pxref{Chain-loading}). However, their boot loaders have some criticaldeficiencies, so it may not work to just chain-load them. To overcomethe problems, GRUB provides you with two helper functions.If you have installed DOS (or Windows) on a non-first hard disk, youhave to use the disk swapping technique, because that OS cannot bootfrom any disks but the first one. The workaround used in GRUB is thecommand @command{map} (@pxref{map}), like this:@example@groupgrub> @kbd{map (hd0) (hd1)}grub> @kbd{map (hd1) (hd0)}@end group@end exampleThis performs a @dfn{virtual} swap between your first and second harddrive.@strong{Caution:} This is effective only if DOS (or Windows) uses BIOSto access the swapped disks. If that OS uses a special driver for thedisks, this probably won't work.Another problem arises if you installed more than one set of DOS/Windowsonto one disk, because they could be confused if there are more than oneprimary partitions for DOS/Windows. Certainly you should avoid doingthis, but there is a solution if you do want to do so. Use the partitionhiding/unhiding technique.If GRUB @dfn{hide}s a DOS (or Windows) partition (@pxref{hide}), DOS (orWindows) will ignore the partition. If GRUB @dfn{unhide}s a DOS (orWindows) partition (@pxref{unhide}), DOS (or Windows) will detect thepartition. Thus, if you have installed DOS (or Windows) on the firstand the second partition of the first hard disk, and you want to bootthe copy on the first partition, do the following:@example@groupgrub> @kbd{unhide (hd0,0)}grub> @kbd{hide (hd0,1)}grub> @kbd{rootnoverify (hd0,0)}grub> @kbd{chainloader +1}grub> @kbd{makeactive}grub> @kbd{boot}@end group@end example@node SCO UnixWare@subsection SCO UnixWareIt is known that the signature in the boot loader for SCO UnixWare iswrong, so you will have to specify the option @option{--force} to@command{chainloader} (@pxref{chainloader}), like this:@example@groupgrub> @kbd{rootnoverify (hd1,0)}grub> @kbd{chainloader --force +1}grub> @kbd{makeactive}grub> @kbd{boot}@end group@end example@node QNX@subsection QNXQNX seems to use a bigger boot loader, so you need to boot it up, likethis:@example@groupgrub> @kbd{rootnoverify (hd1,1)}grub> @kbd{chainloader +4}grub> @kbd{boot}@end group@end example@node Making your system robust@section How to make your system robustWhen you test a new kernel or a new OS, it is important to make surethat your computer can boot even if the new system is unbootable. Thisis crucial especially if you maintain servers or remote systems. Toaccomplish this goal, you need to set up two things:@enumerate@itemYou must maintain a system which is always bootable. For instance, ifyou test a new kernel, you need to keep a working kernel in adifferent place. And, it would sometimes be very nice to even have acomplete copy of a working system in a different partition or disk.@itemYou must direct GRUB to boot a working system when the new systemfails. This is possible with the @dfn{fallback} system in GRUB.@end enumerateThe former requirement is very specific to each OS, so thisdocumentation does not cover that topic. It is better to consult somebackup tools.So let's see the GRUB part. There are two possibilities: one of themis quite simple but not very robust, and the other is a bit complex toset up but probably the best solution to make sure that your systemcan start as long as GRUB itself is bootable.@menu* Booting once-only::* Booting fallback systems::@end menu@node Booting once-only@subsection Booting once-onlyYou can teach GRUB to boot an entry only at next boot time. Supposethat your have an old kernel @file{old_kernel} and a new kernel@file{new_kernel}. You know that @file{old_kernel} can bootyour system correctly, and you want to test @file{new_kernel}.To ensure that your system will go back to the old kernel even if thenew kernel fails (e.g. it panics), you can specify that GRUB shouldtry the new kernel only once and boot the old kernel after that.First, modify your configuration file. Here is an example:@example@groupdefault saved # This is important!!!timeout 10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -