• On page 525 we’ll look at how to control the boot process.. • The second-level boot locates the third-level bootstrap, called loader, and loads it into memory.. By default, loader loca
Trang 1Star ting and stopping the system
In this chapter:
• Star ting the system
• Things you can do
• Shutting down and
rebooting the system
• Star ting the system
• Things you can do
• Shutting down and
rebooting the system
• In the next section, we’ll look at the startup process in more detail
• On page 525 we’ll look at how to control the boot process
• If something goes wrong, and the system doesn’t come up, those messages thatscrolled off the screen are very important We’ll look at what they mean on page 525
• It’s not so obvious that you need to adhere to a procedure when shutting down thesystem We’ll look at the hows and whys on page 537
• There are a number of ways of starting the system for particular applications Onpage 538 we’ll look at how to run FreeBSD without a disk
starting.mm,v v4.19 (2003/04/02 04:32:28) 523
Trang 2The Complete FreeBSD 524
Star ting the system
When you power up the system, or when you reboot, a number of actions occur beforethe system is up and running Starting the system is usually called ‘‘bootstrapping,’’ afterthe story of Baron von Munchhausen pulling himself up by his own bootstraps Thefollowing sequence describes the sequence on the PC architecture, but there are onlyrelatively minor differences on other platforms
• First, the BIOS1performs tests that check that the machine is working correctly and
determines the hardware configuration This Power On Self Test or POST has
nothing to do with FreeBSD
• Next, the BIOS bootstrap loads the Master Boot Record from the first sector of the
first disk on the system (C:in BIOS parlance) into memory and executes it Thisstep is the same for all operating systems on PCs
• It’s up to this bootstrap to decide which operating system to boot The bootstrap inthe MBR may or may not be part of the FreeBSD system FreeBSD can install twodifferent MBRs, as we saw on page 66 The standard MBR works withoutintervention, while the boot manager gives you the choice of booting from anypartition on the disk
• The FreeBSD bootstrap first loads the second-level bootstrap, BTX, from the next 15
sectors on disk and executes it
• The second-level boot locates the third-level bootstrap, called loader, and loads it into memory loader is an intelligent bootstrap component that allows preloading of multiple kernel components See the man page loader(8) for more information By default, loader locates the kernel, the file /boot/kernel/kernel on the root file system,
and loads it into memory You can interrupt the loader at this point, for example toload different or additional files
• The kernel performs its own tests to look for hardware it knows about It’s quiteverbose about this, and prints messages about both the hardware it finds and the
hardware it doesn’t find This operation is called probing Most kernels are built to
recognize a large selection of hardware, so it’s normal to have more ‘‘not found’’messages than ‘‘found’’ messages
• After the probe, the kernel starts two processes The first, process 0, is the swapper
and is responsible for emergency clearing of memory when the standard virtualmemory algorithms aren’t fast enough
• Process 1 is called init As the name suggests, it is responsible for starting up the
system and daemons When coming up in the default multi-user mode, it spawns a
shell to execute the shell script /etc/rc.
1 More accurately, the system firmware The firmware is called BIOS (Basic Input/Output System) on the i386 architecture, SRM on the Alpha architecture, and Open Firmware on a number of other architectures.
starting.mm,v v4.19 (2003/04/02 04:32:28)
Trang 3• /etc/rc first reads in the description files /etc/defaults/rc.conf, which contains defaults
for a number of configuration variables, and /etc/rc.conf, which contains your
modifications to the defaults It then proceeds to perform the steps necessary to bring
up the system, first starting virtual disk drivers, mounting swap space and checkingthe file system integrity if necessary
• When /etc/rc exits, init reads the file /etc/ttys and starts processes as determined
there It spends the rest of its life looking after these processes
Things you can do before booting
You can do a number of things before you boot the system:
• The most obvious thing to do is to decide what you’re going to boot The boot loadergives you the chance to load different operating systems or different FreeBSD kernelsand modules We’ll look at that below
• In addition, you can set a number of options for the kernel loader, includingspecification of hardware and software characteristics We’ll look at that on page527
What are you going to boot?
If you have multiple operating systems on your system, you can use the boot managerdescribed on page 64, to choose which one to boot For example, if you have two disks,the first of which contains four partitions, the first stage of the boot looks something likethis:
key If you press F5, you get a menu showing the partitions on the second disk, with F5
to return to the first disk
If you choose to boot FreeBSD, the bootstrap loaders load, and you see something like:
BTX loader 1.00 BTX version is 1.01
BIOS drive A: is disk0
BIOS drive C: is disk1
BIOS drive D: is disk1
starting.mm,v v4.19 (2003/04/02 04:32:28)
Trang 4What are you going to boot? 526
BIOS 639kB/130048kB available memory
These messages are printed by BTX If you’re loading from disk, the/character at theend of the previous line keeps changing through-,\, and|before going back to/again,
giving the impression that the character is rotating This display, called a twirling baton,
is your indication that the system hasn’t crashed and burned It’s normal for it to take afew seconds before the baton starts to twirl
Next, loader prints its prompt:
FreeBSD/i386 bootstrap loader, Revision 0.8
(grog@freebie.example.com, Thu Jun 13 13:06:03 CST 2002)
Loading /boot/defaults/loader.conf
Hit [Enter] to boot immediately, or any other key for command prompt.
Booting [kernel] in 6 seconds this counts down from 10 seconds
At this point, you would normally continue with the boot, either by pressing the Enter
key or just waiting the 10 seconds We’ll see what happens then on page 529
Sometimes you may want to change software or hardware characteristics In this case,you press the ‘‘any other key’’ (by tradition the space bar) and enter commands to theloader
Loader commands
There are two ways to communicate with the loader:
• A number of files in the directory /boot on the root file system tell the loader what to
do Most are not intended to be changed, but you can create a file called
/boot/loader.conf, into which you can enter commands to override the commands in /boot/defaults/loader.conf We’ll look at this below.
• In addition, the file /boot/device.hints takes the place of many configuration file
entries and allows you to set hardware characteristics such as information about IRQ,DMA, I/O address and other settings for the hardware You can change these valuesduring booting
The CD-ROM installation installs /boot/device.hints, but a kernel install does not.
You’ll find it in the conf directory for your architecture For example,
/usr/src/sys/i386/conf includes the configuration file GENERIC and the
correspond-ing hints file GENERIC.hints Install it like this:
Trang 5device sio0 at isa? port IO_COM1 flags 0x10 irq 4
device sio1 at isa? port IO_COM2 irq 3
device sio2 at isa? disable port IO_COM3 irq 5
device sio3 at isa? disable port IO_COM4 irq 9
The corresponding line in the Release 5 configuration file is:
More importantly, though, this means that you don’t need to recompile the kernel ifyou change the hardware addresses
• You can enter commands directly to the command prompt
When you hit the space bar, you get the following prompt:
Type ’?’ for a list of commands, ’help’ for more detailed help.
ok ?
Available commands:
reboot reboot the system
heap show heap usage
bcachestat get disk block cache stats
boot boot a file or loaded kernel
autoboot boot automatically after a delay
help detailed help
show show variable(s)
set set a variable
unset unset a variable
more show contents of a file
lsdev list all devices
include read commands from a file
ls list files
load load a kernel or module
unload unload all modules
lsmod list loaded modules
pnpscan scan for PnP devices
The most important of these commands areset,show,load,unloadandboot We’llsee some examples of their use in the following sections Note, however, that if you haveaccidentally hit the ‘‘any’’ key during boot and just want to continue with the boot, youjust have to enterboot
starting.mm,v v4.19 (2003/04/02 04:32:28)
Trang 6What are you going to boot? 528
loader.conf
Much of the behaviour of the loader is controlled by entries in /boot/defaults/loader.conf You shouldn’t change this file, though: put changes in a file /boot/loader.conf, which may not exist There are a large number of possible entries; in /boot/defaults/loader.conf
you’ll see the default values, frequently commented out because the loader already knowsthe defaults Here are some of the more interesting ones:
kernel="kernel"
verbose_loading="NO" # Set to YES for verbose loader output
#autoboot_delay="10" # Delay in seconds before autobooting
#console="vidconsole" # Set the current console
#currdev="disk1s1a" # Set the current device
module_path="/boot/kernel;/boot/modules;/modules" # Set the module search path
#prompt="\${interpret}" # Set the command prompt
#root_disk_unit="0" # Force the root disk unit number
#rootdev="disk1s1a" # Set the root filesystem
• The kernel entry gives the name of the kernel, relative to the kernel directory
/boot/kernel Sometimes it might be of interest to change this value, for example
when testing
• console=vidconsoletells the loader where to output its messages vidconsoleis
short for video console; you can also selectcomconsoleif you have a serial terminalconnected to a specified serial port
• currdevspecifies where to look for the root file system If you have multiple BIOSpartitions on a disk, you can select the correct one with this value
There are many more options to the loader; read the man page for more details
Loading other modules at boot time
By default, loader loads only the kernel That may not be what you want You might
want to load a different kernel, or you may want to load a kld as well
There are two ways to do this If you only want to do this once, you can interrupt the
boot sequence by pressing the space bar, and tell loader what to do:
Booting [kernel] in 6 seconds this counts down from 10 seconds
(space bar hit)
Type ’?’ for a list of commands, ’help’ for more detailed help.
OK load /boot/kernel.old/kernel load the old kernel
/boot/kernel.old/kernel text=0x3e474c data=0x52f00+0x81904 syms=[0x4+0x4cab0+0x4+0x5 b458]
OK load /boot/kernel.old/vinum.ko and the old vinum module
/boot/kernel.old/vinum.ko text=0x149a4 data=0xaf75c+0x164 syms=[0x4+0x11e0+0x4+0xcac]
Copyright (c) 1992-2002 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California All rights reserved.
FreeBSD 5.0-RELEASE #0: Sat 15 Feb 16:30:26 CST 2003
grog@monorchid.example.org:/usr/src/sys/i386/compile/BUMBLE
Preloaded elf kernel "/boot/kernel.old/kernel" at 0xc072a000.
starting.mm,v v4.19 (2003/04/02 04:32:28)
Trang 7Preloaded elf module "/boot/kernel.old/vinum.ko" at 0xc072a0bc.
Timecounter "i8254" frequency 1193182 Hz
(etc)
This example shows two separate activities: one is changing the kernel from
/boot/ker-nel/kernel to /boot/kernel.old/kernel, and the other is loading the vinum kld You don’t
need to reload the kernel to load the vinum module.
Automatic kld load
The method described above is cumbersome if you want to load the kld every time you
boot In this case, it’s easier to add the following line to /boot/loader.conf :
vinum_load="YES"
To see what commands you can use, look in /boot/defaults/loader.conf, where you would
find all normal configuration entries commented out
ccd_load="NO" # Concatenated disk driver
vinum_load="NO" # Concatenated/mirror/raid driver
md_load="NO" # Memory disk driver (vnode/swap/malloc)
Don’t change this file; it’s designed to be replaced on upgrade, and any changes wouldget lost when you upgrade
Running the kernel
The next step in the boot process is to run the kernel This is what happens by default ifyou do nothing at theBooting [kernel]prompt, or if you press Enter If you have
interrupted the boot process, you continue with the command:
ok boot
The following example shows the output of booting an Abit BP6 dual processormotherboard This board also has four IDE controllers on board, and the system had twoSCSI host adapters connected to it
The loader transfers control to the kernel it has preloaded Messages from the kernel are
in high-intensity text (brighter than normal) This is the most common time to see them,though they sometimes appear during normal machine operation These messages alsoget copied to the kernel message buffer, and you can retrieve the most recent messages
with the dmesg program In the course of time, other messages may fill the buffer, and you will no longer be able to find the boot messages with dmesg, so one of the final steps
in the startup saves the content of the boot messages in the file /var/run/dmesg.boot,
which should always contain the complete startup messages In the case of laptops, themessage buffer normally does not get cleared on shutdown, not even if the power goesdown, so you may find logs for multiple boots
starting.mm,v v4.19 (2003/04/02 04:32:28)
Trang 8Running the ker nel 530Once it has finished loading, the kernel prints some summary information and then callsall configured drivers to examine the hardware configuration of the machine on which it
is running This is called probing for the devices If you have time to follow it, it’s a
good idea to confirm that it’s correct Much of it appears so quickly that you can’t follow
it, but that’s not a problem Once the boot is complete, you can examine it with the
dmesg command If something goes wrong, it won’t scroll off the screen The place
where it stops is then of interest
Under normal circumstances, we see something like:
Copyright (c) 1992-2002 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
The Regents of the University of California All rights reserved.
FreeBSD 5.0-RELEASE #0: Sat 15 Feb 16:30:26 CST 2003
grog@monorchid.example.org:/usr/src/sys/i386/compile/BUMBLE
Preloaded elf kernel "/boot/kernel/kernel" at 0xc0663000.
Here the kernel identifies itself with information about the release number, when andwhere it was built, and where it was loaded from
Timecounter "i8254" frequency 1193182 Hz
CPU: Pentium II/Pentium II Xeon/Celeron (467.73-MHz 686-class CPU)
Origin = "GenuineIntel" Id = 0x665 Stepping = 5
Features=0x183fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,P AT,PSE36,MMX,FXSR>
real memory = 134217728 (128 MB)
avail memory = 123465728 (117 MB)
The lines above identify the basic hardware There is one time counter (somemotherboards have two), the CPU is a Celeron, Pentium II or Xeon, and it runs at 466MHz This information is relatively reliable The real memory value is the size of RAM.Some older systems reserve 1 kB of RAM in real mode, but this should not have anyeffect on the value of real memory Available memory is the memory available to usersafter the kernel has been loaded and initialized
On some older machines, the kernel reports only 16 MB although the system has morememory This is due to BIOS incompatibilities, and occurs surprisingly often on big-name machines To fix it, build a custom kernel that specifies the memory sizeexplicitly—see the description of the MAXMEM parameter, which is described in the
verbose configuration file /usr/src/sys/i386/conf/NOTES.
This machine is in fact a multiprocessor with two CPUs, so we see:
Programming 24 pins in IOAPIC #0
IOAPIC #0 intpin 2 -> irq 0
IOAPIC #0 intpin 16 -> irq 10
IOAPIC #0 intpin 17 -> irq 9
IOAPIC #0 intpin 18 -> irq 11
FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs
cpu0 (BSP): apic id: 0, version: 0x00040011, at 0xfee00000
cpu1 (AP): apic id: 1, version: 0x00040011, at 0xfee00000
io0 (APIC): apic id: 2, version: 0x00170011, at 0xfec00000
The IOAPIC is the I/O Advanced Programmable Interrupt Controller used by SMP
machines only It reassigns some interrupt requests This information is provided in case
starting.mm,v v4.19 (2003/04/02 04:32:28)
Trang 9you need to debug the kernel None of this appears for a normal machine.
Initializing GEOMetry subsystem
Pentium Pro MTRR support enabled
npx0: <math processor> on motherboard numeric coprocessor, on chip
npx0: INT 16 interface
Using $PIR table, 7 entries at 0xc00fdda0
The GEOMetry subsystem is a disk I/O system that was introduced in FreeBSD Release
5 This processor is a P6 class processor, so it has Memory Type Range Registers or
MTRRs, which are used to optimize memory usage.
Next we look at the other chips on the motherboard, starting with the so-called ‘‘chipset,’’the processor support chips
pcib0: <Intel 82443BX (440 BX) host to PCI bridge> at pcibus 0 on motherboard pci0: <PCI bus> on pcib0
agp0: <Intel 82443BX (440 BX) host to PCI bridge> mem 0xe0000000-0xe3ffffff at devic
e 0.0 on pci0
pcib1: <PCIBIOS PCI-PCI bridge> at device 1.0 on pci0
pci1: <PCI bus> on pcib1
This motherboard has an Intel 82443 BX chipset with two PCI buses Next we see some
of the devices on the motherboard:
pci1: <Matrox MGA G200 AGP graphics accelerator> at 0.0
isab0: <Intel 82371AB PCI to ISA bridge> at device 7.0 on pci0
atapci0: <Intel PIIX4 ATA33 controller> port 0xf000-0xf00f at device 7.1 on pci0 ata0: at 0x1f0 irq 14 on atapci0 primary IDE controller
ata1: at 0x170 irq 15 on atapci0 secondary IDE controller
uhci0: <Intel 82371AB/EB (PIIX4) USB controller> port 0xc000-0xc01f irq 10 at device
usb0: <Intel 82371AB/EB (PIIX4) USB controller> on uhci0USB bus
usb0: USB revision 1.0
uhub0: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
uhub0: 2 ports with 2 removable, self powered
Timecounter "PIIX" frequency 3579545 Hz
pci0: <bridge, PCI-unknown> at device 7.3 (no driver attached)
The system doesn’t know which devices are implemented internally in the chipset, whichare separate chips on the mother board, and which are on plug-in boards So far it hasfound the IDE controllers, but not the disks; it’ll look for them later
Next we find two Symbios SCSI host adapters:
sym0: <875> port 0xc400-0xc4ff mem 0xec002000-0xec002fff,0xec003000-0xec0030ff irq 1
0 at device 9.0 on pci0
sym0: Symbios NVRAM, ID 7, Fast-20, SE, NO parity
sym0: open drain IRQ line driver, using on-chip SRAM
sym0: using LOAD/STORE-based firmware.
sym0: SCAN FOR LUNS disabled for targets 0.
sym1: <875> port 0xc800-0xc8ff mem 0xec001000-0xec001fff,0xec000000-0xec0000ff irq 9
at device 13.0 on pci0
sym1: No NVRAM, ID 7, Fast-20, SE, parity checking
The first Symbios adapter is on IRQ 10 It is on ID 7, like most SCSI host adapters, and
it doesn’t support parity The second board is on IRQ 9 and does support parity, but it
starting.mm,v v4.19 (2003/04/02 04:32:28)
Trang 10Running the ker nel 532doesn’t hav e a BIOS This is not a problem for FreeBSD, which doesn’t use the BIOS,but if it were in the system by itself, the POST would not find it In this particular case,the BIOS on the other Symbios board does in fact find the second host adapter.
dc0: <Macronix 98715AEC-C 10/100BaseTX> port 0xe000-0xe0ff mem
0xe7800000-0xe78000ff irq 11 at device 11.0 on pci0
dc0: Ethernet address: 00:80:c6:f9:a6:c8
miibus0: <MII bus> on dc0
dcphy0: <Intel 21143 NWAY media interface> on miibus0
dcphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
This is a Macronix Ethernet card with associated PHY interface at IRQ 11
After that, we return to on-board peripherals, in this case two additional IDE controllersand legacy ISA peripherals:
atapci1: <HighPoint HPT366 ATA66 controller> port 0xd800-0xd8ff,0xd400-0xd403,0xd000 -0xd007 irq 11 at device 19.0 on pci0
atapci2: <HighPoint HPT366 ATA66 controller> port 0xe400-0xe4ff,0xe000-0xe003,0xdc00 -0xdc07 irq 11 at device 19.1 on pci0 Fourth IDE controller
ata3: at 0xdc00 on atapci2
orm0: <Option ROMs> at iomem 0xc0000-0xc7fff,0xc8000-0xc87ff on isa0
fdc0: ready for input in output Floppy controller
fdc0: cmd 3 failed at out byte 1 of 3
The floppy driver command failure here is caused by the lack of any floppy drive on thismachine
atkbdc0: <Keyboard controller (i8042)> at port 0x60,0x64 on isa0
atkbd0: <AT Keyboard> flags 0x1 irq 1 on atkbdc0 keyboard
kbd0 at atkbd0
vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0
sc0: <System console> at flags 0x100 on isa0 system console
sc0: VGA <16 virtual consoles, flags=0x300>
sio0 at port 0x3f8-0x3ff irq 4 flags 0x10 on isa0 first serial port
sio1 at port 0x2f8-0x2ff irq 3 on isa0 second serial port
sio1: type 16550A
sio3 not found at 0x2e8
UNIX starts counting device numbers from 0, whereas Microsoft starts counting from 1
Devices /dev/sio0 through /dev/sio3 are known as COM1: through COM4: in the
Microsoft world
ppc0: <Parallel port> at port 0x378-0x37f irq 7 on isa0 parallel port controller
ppc0: Generic chipset (NIBBLE-only) in COMPATIBLE mode
plip0: <PLIP network interface> on ppbus0
lpt0: <Printer> on ppbus0 line printer on parallel port
lpt0: Interrupt-driven port
ppi0: <Parallel I/O> on ppbus0 alternate I/O on the same port
Next, on this multiprocessor board, we get some SMP-specific messages The systemtests the IO-APIC, which can sometimes cause problems, and then starts the secondprocessor:
starting.mm,v v4.19 (2003/04/02 04:32:28)
Trang 11APIC_IO: Testing 8254 interrupt delivery
APIC_IO: routing 8254 via IOAPIC #0 intpin 2
SMP: AP CPU #1 Launched!
Finally, the system detects the disks connected to this machine:
ad0: 19574MB <WDC WD205BA> [39770/16/63] at ata0-master UDMA33
ad4: 19574MB <WDC WD205BA> [39770/16/63] at ata0-master UDMA66
Waiting 15 seconds for SCSI devices to settle
(noperiph:sym0:0:-1:-1): SCSI BUS reset delivered.
da0 at sym1 bus 0 target 3 lun 0
da0: <SEAGATE ST15230W SUN4.2G 0738> Fixed Direct Access SCSI-2 device
da0: 20.000MB/s transfers (10.000MHz, offset 15, 16bit), Tagged Queueing Enabled da0: 4095MB (8386733 512 byte sectors: 255H 63S/T 522C)
da1 at sym1 bus 0 target 0 lun 0
da1: <SEAGATE ST15230W SUN4.2G 0738> Fixed Direct Access SCSI-2 device
da1: 20.000MB/s transfers (10.000MHz, offset 15, 16bit), Tagged Queueing Enabled da1: 4095MB (8386733 512 byte sectors: 255H 63S/T 522C)
Here, we have four disks, one each on the first and third IDE controllers, both as master,and two on the second SCSI host adapter There is nothing on the first host adapter.Finally, the system starts Vinum and mounts the root file system and the swap partition:
Mounting root from ufs:/dev/ad0s1a
vinum: loaded
vinum: reading configuration from /dev/ad0s1h
vinum: updating configuration from /dev/ad4s2h
swapon: adding /dev/ad0s1b as swap device
swapon: /dev/vinum/swap: No such file or directory
Automatic reboot in progress
At this point, the system is up and running, but it still needs to start some services Theremaining messages come from processes, not from the kernel, so they are in normalintensity
add net default: gateway 223.147.37.5
Additional routing options: tcp extensions=NO TCP keepalive=YES.
routing daemons:.
Mounting NFS file systems.
additional daemons: syslogd
Doing additional network setup: portmap.
Starting final network daemons: rwhod.
setting ELF ldconfig path: /usr/lib /usr/lib/compat /usr/X11R6/lib /usr/local/lib setting a.out ldconfig path: /usr/lib/aout /usr/lib/compat/aout /usr/X11R6/lib/aout starting standard daemons: inetd cron
Initial rc.i386 initialization:.
rc.i386 configuring syscons: blank_time.
Local package initialization:.
Additional TCP options:.
Tue Apr 23 13:59:05 CST 2000
At this point, the kernel has finished probing, and it transfers control to the shell script
/etc/rc From this point on the display is in normal intensity /etc/rc first reads the
configuration information in /etc/defaults/rc.conf and /etc/rc.conf (see page 546) Next,
it checks the consistency of the file systems Normally you’ll see messages like this for
each file system in /etc/fstab:
starting.mm,v v4.19 (2003/04/02 04:32:28)