Tải bản đầy đủ (.pdf) (23 trang)

Tài liệu Chapter-29-Starting and stopping the system doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (228.55 KB, 23 trang )

2Apr il 2003, 17:00:47 The Complete FreeBSD (starting.mm), page 523
29
Star ting and
stopping the system
In this chapter:
• Star ting the system
• Things you can do
before booting
• What are you going
to boot?
• Running the ker nel
• Single-user mode
• Shutting down and
rebooting the system
• FreeBSD without
disks
• Networ k booting
• Disk substitutes
In this chapter:
• Star ting the system
• Things you can do
before booting
• What are you going
to boot?
• Running the ker nel
• Single-user mode
• Shutting down and
rebooting the system
• FreeBSD without
disks
• Networ k booting


• Disk substitutes
Before you can run FreeBSD, you need to start it up. That’snormally pretty
straightforward: you turn the machine on, a lot of things scroll offthe screen, and about a
minute later you have a login: prompt or an X login windowonthe screen. Sometimes,
though, the process is of more interest. Youhav e anumber of options when booting, and
it’salso a source of a number of problems, so it pays to understand it. In this chapter
we’ll look at the following topics:
• In the next section, we’ll look at the startup process in more detail.
• On page 525 we’ll look at howtocontrol the boot process.
• If something goes wrong, and the system doesn’tcome up, those messages that
scrolled offthe screen are very important. We’lllook at what theymean on page 525.
• It’snot so obvious that you need to adhere to a procedure when shutting down the
system. We’ll look at the hows and whys on page 537.
• There are a number of ways of starting the system for particular applications. On
page 538 we’ll look at howtorun FreeBSD without a disk.
starting.mm,v v4.19 (2003/04/02 04:32:28) 523
The Complete FreeBSD 524
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 524
Star ting the system
When you power up the system, or when you reboot, a number of actions occur before
the system is up and running. Starting the system is usually called ‘‘bootstrapping,’’ after
the story of Baron von Munchhausen pulling himself up by his own bootstraps. The
following sequence describes the sequence on the PC architecture, but there are only
relatively minor differences on other platforms.
• First, the BIOS
1
performs 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. This
step is the same for all operating systems on PCs.
• It’suptothis bootstrap to decide which operating system to boot. The bootstrap in
the MBR may or may not be part of the FreeBSD system. FreeBSD can install two
different MBRs, as we sawonpage 66. The standard MBR works without
intervention, while the boot manager givesyou the choice of booting from any
partition on the disk.
• The FreeBSD bootstrap first loads the second-levelbootstrap, BTX,from the next 15
sectors on disk and executes it.
• The second-levelboot locates the third-levelbootstrap, 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 to
load different or additional files.
• The kernel performs its own tests to look for hardware it knows about. It’squite
verbose about this, and prints messages about both the hardware it finds and the
hardware it doesn’tfind. This operation is called probing.Most kernels are built to
recognize a large selection of hardware, so it’snormal to have more ‘‘not found’’
messages than ‘‘found’’messages.
• After the probe, the kernel starts twoprocesses. The first, process 0, is the swapper
and is responsible for emergencyclearing of memory when the standard virtual
memory algorithms aren’tfast enough.
• Process 1 is called init.Asthe 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)onthe 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)
525 Chapter 29: Starting and stopping the system

2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 525
• /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 checking
the 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
Youcan 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 loader
givesyou the chance to load different operating systems or different FreeBSD kernels
and modules. We’lllook at that below.
• In addition, you can set a number of options for the kernel loader,including
specification of hardware and software characteristics. We’lllook at that on page
527.
What are you going to boot?
If you have multiple operating systems on your system, you can use the boot manager
described on page 64, to choose which one to boot. Forexample, if you have two disks,
the first of which contains four partitions, the first stage of the boot looks something like
this:
F1: FreeBSD
F2: Windows
F3: Linux
F4: FreeBSD
F5: Drive 1
Default: F1
After 10 seconds, the boot manager attempts to load the bootstrap from the default
partition; you can choose anyofthe selections by pressing the corresponding function
key. Ifyou 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:
/ this is a ‘‘twirling baton’’
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)
What are you going to boot? 526
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 526
BIOS 639kB/130048kB available memory
These messages are printed by BTX.Ifyou’re loading from disk, the / character at the
end 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’tcrashed and burned. It’snormal for it to takea
fewseconds before the baton starts to twirl.
Next, loader prints its prompt:
FreeBSD/i386 bootstrap loader, Revision 0.8
(, 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
keyorjust waiting the 10 seconds. We’llsee what happens then on page 529.
Sometimes you may want to change software or hardware characteristics. In this case,
you press the ‘‘anyother key’’ (by tradition the space bar) and enter commands to the
loader.
Loader commands
There are twoways to communicate with the loader:
• Anumber 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 manyconfiguration 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 values
during 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. Forexample,
/usr/src/sys/i386/conf includes the configuration file GENERIC and the correspond-
ing hints file GENERIC.hints.Install it likethis:
# cp /usr/src/sys/i386/conf/GENERIC.hints /boot/device.hints
The hints file contains entries of the following nature:
hint.sio.0.at="isa"
hint.sio.0.port="0x3F8"
hint.sio.0.flags="0x10"
hint.sio.0.irq="4"
hint.sio.1.at="isa"
hint.sio.1.port="0x2F8"
starting.mm,v v4.19 (2003/04/02 04:32:28)
527 Chapter 29: Starting and stopping the system
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 527
hint.sio.1.irq="3"
hint.sio.2.at="isa"
hint.sio.2.disabled="1"
hint.sio.2.port="0x3E8"
hint.sio.2.irq="5"
hint.sio.3.at="isa"
hint.sio.3.disabled="1"
hint.sio.3.port="0x2E8"

hint.sio.3.irq="9"
These entries describe the serial port configuration. Theyreplace the older method of
hard coding the information in the kernel. For example, the hints above contain the
configuration information contained in these lines of the Release 4 configuration file:
device 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:
device sio #8250, 16[45]50 based serial ports
More importantly,though, this means that you don’tneed to recompile the kernel if
you change the hardware addresses.
• Youcan 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 afile or loaded kernel
autoboot boot automatically after a delay
help detailed help
?list commands
show show variable(s)
set set avariable
unset unset avariable
more show contents of a file
lsdev list all devices
include read commands from a file

ls list files
load load akernel or module
unload unload all modules
lsmod list loaded modules
pnpscan scan for PnP devices
The most important of these commands are set, show, load, unload and boot.We’ll
see some examples of their use in the following sections. Note, however, that if you have
accidentally hit the ‘‘any’’key during boot and just want to continue with the boot, you
just have toenter boot.
starting.mm,v v4.19 (2003/04/02 04:32:28)
What are you going to boot? 528
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 528
loader.conf
Much of the behaviour of the loader is controlled by entries in /boot/defaults/loader.conf.
Youshouldn’tchange 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 knows
the 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 givesthe name of the kernel, relative tothe kernel directory
/boot/kernel.Sometimes it might be of interest to change this value, for example
when testing.

• console=vidconsole tells the loader where to output its messages. vidconsole is
short for video console;you can also select comconsole if you have a serial terminal
connected to a specified serial port.
• currdev specifies where to look for the root file system. If you have multiple BIOS
partitions on a disk, you can select the correct one with this value.
There are manymore 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 twoways 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 unload not the kernel we wanted
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]
ok boot then start the kernel
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
:/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)
529 Chapter 29: Starting and stopping the system
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 529

Preloaded elf module "/boot/kernel.old/vinum.ko" at 0xc072a0bc.
Timecounter "i8254" frequency 1193182 Hz
(etc)
This example shows twoseparate 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 iscumbersome if you want to load the kld every time you
boot. In this case, it’seasier 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’tchange this file; it’sdesigned to be replaced on upgrade, and anychanges would
get 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 if
you do nothing at the Booting [kernel] prompt, or if you press Enter.Ifyou have
interrupted the boot process, you continue with the command:
ok boot
The following example shows the output of booting an Abit BP6 dual processor
motherboard. This board also has four IDE controllers on board, and the system had two
SCSI 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 theysometimes appear during normal machine operation. These messages also

get 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,soone of the final steps
in the startup savesthe 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, the
message buffer normally does not get cleared on shutdown, not evenifthe power goes
down, so you may find logs for multiple boots.
starting.mm,v v4.19 (2003/04/02 04:32:28)
Running the ker nel 530
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 530
Once it has finished loading, the kernel prints some summary information and then calls
all 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 followit, it’sa
good idea to confirm that it’scorrect. Much of it appears so quickly that you can’tfollow
it, but that’snot a problem. Once the boot is complete, you can examine it with the
dmesg command. If something goes wrong, it won’t scroll offthe 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
:/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 and
where 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 (some
motherboards have two), the CPU is a Celeron, Pentium II or Xeon, and it runs at 466
MHz. This information is relatively reliable. The real memory value is the size of RAM.
Some older systems reserve1kBofRAM in real mode, but this should not have any
effect on the value of real memory.Available memory is the memory available to users
after the kernel has been loaded and initialized.
On some older machines, the kernel reports only 16 MB although the system has more
memory.This is due to BIOS incompatibilities, and occurs surprisingly often on big-
name machines. To fixit, build a custom kernel that specifies the memory size
explicitly—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 twoCPUs, 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.Itreassigns some interrupt requests. This information is provided in case
starting.mm,v v4.19 (2003/04/02 04:32:28)
531 Chapter 29: Starting and stopping the system
2April 2003, 17:00:47 The Complete FreeBSD (../tools/tmac.Mn), page 531
you 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,onchip
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,soithas Memory Type RangeRegisters 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
e0.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 twoPCI 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
isa0: <ISA bus> on isab0 ISA bus
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
7.2 on pci0 USB controller
usb0: <Intel 82371AB/EB (PIIX4) USB controller> on uhci0 USB 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’tknowwhich devices are implemented internally in the chipset, which
are separate chips on the mother board, and which are on plug-in boards. So far it has
found the IDE controllers, but not the disks; it’ll look for them later.
Next we find twoSymbios SCSI host adapters:
sym0: <875> port 0xc400-0xc4ff mem 0xec002000-0xec002fff,0xec003000-0xec0030ff irq 1
0atdevice 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, likemost SCSI host adapters, and
it doesn’tsupport 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)

×