📄 tech.tex
字号:
%% Copyright 1992-1998 by Werner Almesberger.% All rights reserved.%% See file COPYING for details.%\documentstyle[fullpage]{article}\parindent=0pt\parskip=4pt\hyphenation{hexa-decimal}\def\key#1{$[$#1$]$}\def\LILO{LILO}\def\SetFigFont#1#2#3{\tt}\begin{document}\title{\LILO \\ \Large Generic boot loader for Linux \\ Version 21 \\ ~\\ \bf Technical overview}\author{Werner Almesberger \\ {\tt Werner.Almesberger@epfl.ch}}\date{December 4, 1998}\maketitle{ \parskip=-4pt \setcounter{tocdepth}{1} \tableofcontents}~\\This document describes internals of \LILO\ and related parts of itsenvironment (kernel, etc.). It is not necessary to read or understandthis document in order to install or use \LILO. A general introductionand installation instructions can be found in the user's guide.{\bf This document has only been partially updated and does not entirelyreflect the current ('98) status of Linux or of \LILO\ (version 21).}\section{Load sequence}\label{load}The boot sector is loaded by the ROM-BIOS at address 0x07C00. It movesitself to address 0x96A00, sets up the stack (growing downwards from0x96A00 to 0x96800), loads the secondary boot loader at address0x96C00 and transfers control to it. It displays an ``L'' after movingitself and an ``I'' before starting the secondary boot loader. If a readerror occurs when loading the secondary boot loader, a two-digit hex codeis displayed after the ``L''. This results in an endless stream of errorcodes if the problem is permanent. Displaying these error codes is disabledif the build-time option {\tt NO1STDIAG} is set.The secondary boot loader loads the descriptor table at 0x98800 and thesector containing the default command line at 0x98C00. If the default commandline is enabled, its magic number is invalidated and the sector is writtenback to disk. This potentially dangerous operation can be disabled by defining{\tt LCF\_READONLY} when passing {\tt second.S} through {\sf cpp}. Next, thesecondary boot loader checksfor user input. If either the default is used or if the user has specifiedan alternate image, the options sector is loaded at 0x98C00 and the parameterline is constructed at 0x99000. If the resulting line contains the option\verb"lock", the command line as entered by the user (it is saved beforethe final line is constructed) is written to the disk as the new defaultcommand line. Also, if a fallback command line is set, it is copied to thedefault command line sector.If the user has supplied an initial RAM disk image, this file is loadedbelow the end of physical memory or 16 MB, whichever is lower. The startaddress is lowered to the next page boundary so that the memory areaoccupied by the initial RAM disk can later be easily returned to thesystem's free memory pool. The 16 MB limit exists because the BIOSfunctions used to transfer data in memory are only specified for an 24 bitaddress space.Next, the floppy boot sector of that image isloaded at 0x90000\footnote{The floppy boot sector is only used as a source ofsetup information.},the setup part is loaded at 0x90200 andthe kernel part is loaded at 0x10000, or, if the kernel has been compiledfor being loaded ``high'' (i.e. with {\tt make bzImage}), it is loadedat 0x100000 instead. During the load operations, the sectorsof the map file are loaded at 0x98600.If the loaded image is a kernel image, control is transferred toits setup code.If a different operating system is booted, things are a bit more difficult:the chain loader is loaded at 0x90200 and the boot sector of the other OSis loaded at 0x90400. The chain loader moves the partition table (loaded at0x903BE as part of the chain loader) to 0x00600 and the boot sector to0x07C00. After that, it passes control to the boot sector.Chain loaders that allow booting from a second drive (either floppy or harddisk) also install a small function to intercept BIOS calls and to swapthe drive numbers at the top of available memory.The secondary boot loader displays an ``L'' after being started and an ``O''after loading the descriptor table and the default command line. Beforeloading the descriptor table, it checks, whether it has been loaded at thecorrect location and displays a question mark if it hasn't. If thedescriptor table has an incorrect checksum, a minus sign is displayed.$$\begin{tabular}{l|c|l} \cline{2-2} \tt 0x00000 & & 1982 bytes \\ \cline{2-2} \tt 0x007BE & Partition table & 64 bytes \\ \cline{2-2} \tt 0x007FE & & 29 kB \\ \cline{2-2} \tt 0x07C00 & Boot load area & 512 bytes \\ \cline{2-2} \tt 0x07E00 & & 32.5 kB \\ \cline{2-2} \tt 0x10000 & & 448 kB \\ & & \\ & Kernel & \\ & & \\ & & \\ \cline{2-2} \tt 0x90000 & Floppy boot sector & 512 bytes \\ \cline{2-2} \tt 0x90200 & Setup (kernel) & 39.5 kB (2 kB used) \\ \cline{2-2} \tt 0x9A000 & Primary boot loader & 512 bytes \\ \cline{2-2} \tt 0x9A200 & Stack & 3.5 kB \\ \cline{2-2} \tt 0x9B000 & Secondary boot loader & 8 kB (3.5 kB used) \\ \cline{2-2} \tt 0x9D000 & Map load area & 512 bytes \\ \cline{2-2} \tt 0x9D200 & Descriptor table & 1 kB \\ \cline{2-2} \tt 0x9D600 & Default command line, etc. & 512 bytes \\ \cline{2-2} \tt 0x9D800 & Keyboard translation table & 512 bytes \\ \cline{2-2} \tt 0x9DA00 & Parameter line construction area & 1 kB \\ \cline{2-2} \tt 0x9DC00 & & 7.5 kB \\ & & \\ \cline{2-2} & Drive swapper & 1 kB \\ \cline{2-2} \multicolumn{3}{l}{\tt 0xA0000} \\\end{tabular}$$The area 0x90020-0x90023 is overlaid by a command-line descriptor whilethe secondary boot loader is running.If the build-time configuration option {\tt LARGE\_EBDA} is set, all theaddresses in the area 0x90000-0x9FFFF are changed to 0x80000-0x8FFFF,with the exception of the location of the driver swapper, which automaticallyfollows the end of the available memory.\section{File references}This section describes the references among files involved in the bootprocedures.$$ \input bootloader$$The boot sector contains the primary boot loader, the address of the defaultcommand line sector, the address of bothdescriptor table sectors and the addresses of the sectors of the secondaryboot loader. The generic boot sector is copied from {\tt boot.b}.The primary boot loader can store up to eight sector addresses of thesecondary boot loader.$$ \input map$$The map file consists of so-called sections and of special data sectors.Each sectionspans an integral number of disk sectors and contains addresses of sectorsof other files.There are three exceptions: 1. If a ``hole'' is beingcovered or if the floppy boot sector of an unstripped kernel has been omitted,the address of the zero sector is used. This sector is part of themap file. 2. When booting a different operating system, the first sector isthe merged chain loader that has been written to the map file before thatsection. 3. Each map section describing an image is followed by a sectorcontaining the options line of that image.The last address slot of each map sector is either unused (if the map sectionends in this sector) or contains the address of the next map sector in thesection.The ifive sectors at the beginning of the map file are special: the firstsector contains the default command line, the nexttwo sectors contain the boot image descriptor table and the fourth sectoris filled with zero bytes. This sector is mapped whenever a file containsa ``hole''. The fifth sector contains the keyboard translation table.$$ \input image$$A kernel image consists simply of a sequence of sectors beingloaded. The map section also contains a sector with a fallback command lineand a sector with parameter line options. Optionally, a RAM disk image,specified by a second map section, can be loaded.$$ \input other$$When booting another operating system, the chain loader ({\tt chain.b}) ismerged with the patched partition table\footnote{If the partition table isomitted, that area is filled with zero bytes.} and written into the map file.The map section of this boot image starts after that sector and contains onlythe address of a dummy floppy boot sector (the zero sector, but itscontents are irrelevant), the loadersector and the boot sector of the other operating system. Not that themap section also contains the fallback sector and a (useless) sector foroptions.\section{Configuration parameters}The boot sector of each kernel contains a set of configuration parametersthat have to be available at boot time before the kernel can accessfile systems. These parameters can be set when the kernel is compiled andlater be changed with programs like {\sf rdev}. \LILO\ can supersedethe parameters (in memory) at boot time by placing the correspondingitems on the parameter line passed to the kernel.The parameters are stored at the following (decimal) offsets:\begin{description} \item[497] the size of the setup code in sectors (512 bytes). Older kernels may put a zero at this place. \item[498-499] is a flag specifying whether the root file system should be mounted read-only (if non-zero) or read-write (if zero). \item[500-501] the size of the kernel, counted in paragraphs (16 bytes). \item[502-503] this parameter is currently unused. \item[504-505] the size of the RAM disk in kilobytes. No RAM disk is created if this parameter is set to zero. \item[506-507] the text mode the VGA is set to. \begin{description} \item[0xFFFD] the user is asked to specify the VGA mode at boot time. \item[0xFFFE] uses 80x50 (``extended'') mode. \item[0xFFFF] uses 80x25 (``normal'') mode. \end{description} Any other value selects the corresponding mode as displayed in the interactive VGA mode selection menu. This is the only option that is set by LILO by patching the boot sector instead of passing it on the parameter line. \item[508] the minor number of the device that should be mounted as root. \item[509] the major number of the device that should be mounted as root.\end{description}\section{Parameter line interface}The kernel supports processing of parameters that areprovided by the boot loader. The parameter string is a NUL-terminatedASCII string that contains space-separated words or{\tt {\it variable\/}={\it value\/}} pairs. A description of how they areinterpreted can be found in the section of the user's guide labeled``The boot prompt''.The following descriptor has to be set up to pass a parameter string tothe kernel:\begin{description} \item[0x90020] the magic number 0xA33F. \item[0x90022] the offset of the first byte of the parameter line relative to 0x90000.\end{description}The boot loader composes the parameter line from the command line, fromthe options sector and from some internally generated prefixes (typically\verb"auto" and \verb"BOOT_IMAGE="), as follows:$$ \input parameter$$Example: \\Command line: \verb"vmlinuz root=802"\\Options sector: \verb"root=801 ro"yields \verb"BOOT_IMAGE=vmlinuz root=801 ro root=802"Because parameter line options can typically be overridden, the first\verb"root" option is ignored by the kernel.\section{External interface}\LILO\ is able to receive its command line from a program that is bootedbefore it. This externally provided command line is only used if theuser does not use the normal mechanism to invoke the boot prompt.The following register contents are expected:\begin{description} \item[\bf DL] contains the value 0xFE. \item[\bf ES:SI] points to the string ``LILO''. The string must be in upper case and no terminating character is needed. The string must not cross segment boundaries, i.e. {\bf SI} must be below 0xFFFD. \item[\bf ES:BX] points to a NUL-terminated string that is used as the command line. This string has a maximum length of 78 characters (not including the terminating NUL) and must not cross segment boundaries.\end{description}There are two values of the externally provided command line that have aspecial meaning:\begin{itemize} \item an empty string ({\bf ES:BX} points to a NUL byte) is interpreted as a request to enter the boot prompt and to accept keyboard input. \item a string that consists only of blanks is interpreted as a request to boot the default boot image.\end{itemize}\LILO\ can also obtain the default command line from the map file. Itis only used if no externally provided command line is available.\section{Default command line in map file}The first sector of the map file is reserved for a default command line.Unless the user invokes the boot prompt by pressing a shift key or unless anexternally provided command line is present, the command line in the mapfile is interpreted as if it had been typed on the keyboard.The first two bytes of the first sector of the map file have to containthe magic number {\tt DC\_MAGIC} (0xF4F2) in little-endian byte order.They are followed by a NUL-terminated string with a maximum length of510 bytes, including the NUL. Note that the boot loader limits commandlines to 78 characters after removing duplicate spaces.The command line is disabled by either clobbering the magic number orby using an empty string (i.e. only a NUL byte) as the command line.\end{document}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -