The boot process is the magic that makes your hardware come alive. You may not dwell on it, the process by which your cold, static, inanimate box kicks in, is a wonder of modern science.
The process begins when you press the power button.
Here's how it works:
Booting is a multi-stage process:
Read the BIOS ROM.
o Power Up
The first stage when switch on your machine is the surge of electricity to the power supply. This needs to be regulated so a steady stream can be pumped to the computer. Once the supply is regulated, a reset signal is sent to the CPU.
o BIOS ROM
Processor checks the end of system memory (the BIOS ROM) for a boot program it can load. This always resides at the same location in every BIOS: 0xF0000 to 0xFFFFF. The BIOS ROM always resides at the and of system memory.
o BIOS POST
Next the system runs POST to check all is healthy and A-OK. If it gets the all clear, it continues with the boot. If its a minor fault it beeps.
o Video BIOS
Next it reads and runs the video cards BIOS. This is located at: 0xC000 in memory.
o ATA BIOS
Next it looks for other BIOS on the system and reads them. This is normally the ATA disk drive BIOS located at: 0xC800.
o BIOS Display
The system then displays the familiar BIOS screen.
o Memory Check
BIOS now checks system memory and displays a total count.
Now BIOS performs system check to see what hardware is on the system.
o PnP Check
Now BIOS checks for Plug n Play devices on the system, and echos a message on screen for each one it finds
o BIOS Summary
BIOS displays a summary of system config. This includes serial ports and their I/O port addresses. The ports are:
Parallel ports, normally only one:
o Boot Device
The BIOS searches for a device to boot.
o Target Device
After identifying the target boot device, the BIOS now searches hard disk for cylinder 0, head 0, sector 1. (The first sector on the disk).
o Bootable Device
If the BIOS finds a bootable device at cylinder 0, head 0, sector 1. It loads the code into memory to move to stage two of the boot sequence. This is boot0, a simple program it lists the available slices you can boot from, if you have multi-OS on your system. If not this jumps straight to boot1
Next it reads and executes boot1. Boot1 is only 512 bytes, and stores information about the slice to find and execute boot2.
Boot2 understands the filesystem enough to find files on it, and choose the kernel or loader to run.
At this point you can boot into single user mode (boot -s), load and unload kernel or modules, load config scripts.
MBR layout always follow a standard format independent of the OS. The first 446 bytes are reserved for program code. The next 64 bytes hold space for a partition table up to four partitions. Without a partition table the disk could not be read. The last two bytes contain a special magic number (AA55).
o NoBootable Device
If it cannot find a bootable device, it diplays an error message and halts.
o Warm Boot, Cold Boot
The above process applies to a cold boot. A warm boot is the same except the POST is skipped and the boot process continues from step 8.
Once the kernel has finished booting, it passes control to init the last stage of the boot process, Init checks file systems for inconsistencies, if it finds any, it runs fsck to correct errors. If these are corrected the boot continues, if not it drops to single-use mode for sys admin to correct.
If the filesystems are found to be okay, the system enters multi-user mode, and runs resource configuration of the system. The system reads defaults from /etc/defaults/rc.conf and system specifics from /etc/rc.conf. It mounts the filesystems in /etc/fstab, starts networking services, various daemons, and finally the startup scripts of locally installed packages. See rc(8) for further reference.
If the shutdown command is run, init will attempt to run /etc/rc.shutdown, and send all process the TERM signal, if they don't respond, it will issue KILL signal.
At this point the machine powers down and its systems off.