Section 14.1. Overview

   


14.1. Overview

The FreeBSD kernel is only a program, albeit a complex one. Like any program, its binary image resides in a file on a filesystem until it is loaded and set running. FreeBSD presumes that the executable image of the kernel resides in a file named /boot/kernel/kernel on a filesystem that is designated as the root filesystem. The initial bootstrap mechanism is machine dependent. Often a small bootstrap program is placed in a reserved area near the start of the primary disk. This program is usually limited to a small area as little as one 512-byte disk sector and simply loads a larger program from the following area of the disk. This program, or some other mechanism, is usually used to load and run a special program, named boot. The boot program's task is to load and initialize the executable image of a program and to start that program running. Boot may come from the same storage device as the file that it bootstraps, or it may be loaded from a network file server.

When the boot program is started, it loads /boot/kernel/kernel and then begins a countdown that can be interrupted by the user. If the boot program's countdown is interrupted, it provides the user with a command line interpreter on the console and waits for input. The list of commands is shown in Table 14.1. The command line interpreter helps debug problems occurring at boot time. The most commonly used commands are the unload command, to remove the default kernel, followed by the load command, to load an alternative kernel. Typically the alternative kernel being loaded is /boot/kernel/kernel.old, saved by the kernel build system when installing a new kernel in case the new kernel proves to be faulty.

Table 14.1. Boot Program Commands.

Command

Description

beachestat

get disk block cache statistics

boot

boot a file or loaded kernel

autoboot

boot automatically after a delay

help

detailed help

?

list available commands

show

show variable(s)

set

set a variable

unset

unset a variable

echo

echo back some input, analogous to echo in the shell

read

emulate the shell command read

more

show contents of a file with paged output

lsdev

list all devices

include

read commands from a file

1s

list files that the boot program can see

load

load a kernel or module

unload

unload all modules

lsmod

list all loaded modules

pnpscan

scan for plug-and-play (PnP) devices

pnpload

load modules for plug-and-play devices


The kernel is started by issuing the boot command, either by the user or because the countdown has reached 0. The boot command starts by initializing the CPU, ensuring that the virtual-address translation is turned off and that hardware interrupts are disabled. The loaded program is responsible for enabling these facilities and any additional hardware, such as I/O devices, that it intends to use.

When the FreeBSD kernel is loaded by the boot program, the kernel goes through several stages of hardware and software initialization in preparation for normal system operation. The first stage is responsible for setting up the initial state of the CPU, including the run-time stack and virtual-memory mapping. Memory mapping, including virtual-address translation, is enabled early in the startup procedure to minimize the amount of special-purpose assembly-language code that those porting the kernel must write. Once virtual-memory mapping is enabled, the system does machine-dependent initializations and then machine-independent initializations. The machine-dependent operations include setting up mutexes and virtual-memory page tables, and configuring I/O devices; the machine-independent actions include mounting the root filesystem and initializing the myriad system data structures. This order is necessary because many of the machine-independent initializations depend on the I/O devices being initialized properly.

Following the setup of the machine-independent portions of the kernel, the system is in operational status. System processes are created and made runnable, and user-level programs are brought in from the filesystems to execute. At this point, the system is ready to run normal applications.


   
 


The Design and Implementation of the FreeBSD Operating System
The Design and Implementation of the FreeBSD Operating System
ISBN: 0201702452
EAN: 2147483647
Year: 2003
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net