The process of starting the computer and uploading the operating system is called the bootstrap process or simply boot. Running FreeBSD is characterized by very high flexibility and configurability. For example, it lets you choose which operating system you want to run if you have several. It even allows you to choose the version of the same system, or decide which system kernel to run.
This chapter discusses in detail the configuration options as well as how to personalize the FreeBSD boot process. It includes everything that happens before the system kernel is started, device detection, init (8). If you’re not sure when it’s happening, know that when the text color changes from light white to gray.
After reading this chapter, you should know:
- What happens and how elements of FreeBSD startup processes interact with each other.
- What FreeBSD startup options can be set.
X86 only This chapter describes only the startup process of FreeBSD operating on Intel x86 architectures.
Problem with running
Turning on the computer and starting the operating system shows an interesting problem. By definition, the computer does not know how to do it until the operating system is started. Of course, this includes running programs from the disk. So if the computer can not enable programs from the disk without the operating system, and the operating system programs are on the disk, how does the system boot at all?
In the early years of computerization, the term “bootstrap” was used to describe the mechanisms that run the operating system. This term, through evolution, has been shortened to “booting”.
On x86 hardware, it is the BIOS (Basic Input Output System) that is responsible for starting the operating system. To do this, the BIOS checks the MBR (Master Boot Record) of the disks. The BIOS is skillful enough to be able to load and run MBR content. Then, starting by the MBR, the system startup mechanisms are started.
If you only have one operating system on your disk, a standard MBR is enough. MBR searches for the first bootable partition on the disk, then runs the code contained on this partition to load the operating system.
If you have several operating systems on your disks, you can install another MBR, one that will display a list of available operating systems, and then allow you to choose between them. FreeBSD can be installed with just such MBR. Providers of other operating systems often offer an alternative MBR.
The FreeBSD startup process is divided into three parts. The first of these is the launch of the MBR, which knows as much as putting the computer in a specific state and starting the next, second stage of commissioning. This next stage is able to do a little more before starting the third stage. The last, third stage of loading the operating system, completes the entire procedure. The entire task of starting the system is divided into three parts, because the standards of personal computers impose restrictions on the size of programs that are executable in the first and second parts. FreeBSD connection allows you to get more flexible system uploads.
When the system kernel is started, it starts to detect the devices and tries to start them. When the kernel boot process is finished, the kernel passes control to the init (8) process, which makes sure that the disks are in good condition. Then init (8) starts the configuration of the user who mounts the hard disks, sets the network adapter configuration to be able to communicate with the network, then generally starts all processes that are run on FreeBSD startup.
MBR and start stages I, II, III.
MBR, / boot / boot0
MBR FreeBSD is located in / boot / boot0. This is a copy of a real MBR, because this one must be in a special part of the hard disk, outside the FreeBSD partition area.
boot0 is very simple, because the program residing in the MBR can have only 512 bytes. If you installed MBR with FreeBSD, you have several operating systems, then you will see a similar shot when you start the operating system.
Example - boot0
F5 Drive 1
Default: F2 (default option)
Some operating systems are known to overwrite the MBR. Such a system is for example Windows 95. If such an event occurs, or you want to replace an existing MBR with a FreeBSD MBR, you can use the following command.
# fdisk -B -b / boot / boot0 device
Where device is the disk from which you are booting the system, such as ad0 is the first IDE drive and ad2 the first IDE drive on the second controller. da0 is the first SCSI disk, etc.
If you are a Linux user, you prefer to use LILO to control the startup process, you can edit the
/etc/lilo.conf file. You can declare “Leave MBR unchanged” [“Leave the MBR untouched”] during the system installation process. If we have declared so, we can run linux, then edit /etc/lilo.conf by adding:
other = / dev / hdXY
table = / dev / HDB
loader = / boot / chain.b
label = FreeBSD
This will allow LILO to run both Linux and FreeBSD. In our example, we use XY to specify the drive and partition number. If you’re using a SCSI drive, you’ll probably want to change / dev / hdXY to / dev / sdXY, where the XY symbols have the same meaning.
The loader = / boot / chain.b option can be omitted if you have both operating systems on the same drive. You can now run / sbin / lilo -v to save changes, this should be verified with messages displayed on the screen.
Stage I, / boot / boot1, stage II, / boot / boot2
Deliberately elements of stages I and II are parts of the same program on the same part of the disk. Because the space is limited, it has been divided into 2 parts, but you will always install them together.
Elements I and II can be found in the boot-sector of the partition being started, i.e. where boot0 or any other MBR programs are waiting to find a program that will continue the boot process. The files in the / boot directory are only copies of the real ones that are outside the FreeBSD partitions.
boot1 is very simple. It can be up to 512 bytes in size, and it only knows about disklabel ( diskette label where information about the partition is stored) and how to find and run boot2.
boot2 is already more sophisticated and can understand the FreeBSD file system enough to be able to find the files on it and display a menu to select the system kernel or loader.
While the loader loader is even more extensive and provides an easy-to-use system boot configuration, boot2 usually launches the loader, before launching the kernel directly.
Example. boot2 screenshot
>> FreeBSD / i386 BOOT
Default: 0: ad (0, a) / kernel
If you ever need to replace boot1 and boo2, use disklabel (8).
FreeBSD # disklabel -B diskslice
Where diskslice is the disk and partition from which you boot the system, for example ad0s1 is the first partition, the first IDE disk.
Dangerously dedicated mode: If you only use the disk name, such as ad0, in disklabel, you will create a dangerously dedicated disk, without a partition. This is probably not what you wanted to do, so make sure you double check the disklabel (8) command syntax before you press Enter.
Stage III, / boot / loader.
Loader is the last part of the three-way startup process. It is already located in the file system, usually in / boot / loader.
The Loader loader is seen as a user-friendly tool that has a large number of built-in functions, supported by a built-in interpreter with a fairly complex syntax.
Operation of the loader
During initialization, the loader will attempt to detect the console and disks to find out which disk the boot runs from. Then the appropriate variables will be set, then the interpreting program is started, where the user’s commands (derived from scripts or interactive) are already recognized.
Then the loader reads /boot/loader.rc, which by default reads
/boot/defaults/loader.conf, setting the correct default settings, then reads /boot/loader.conf to replace the default variables with local variables. loader.rc is working on these variables, loading the selected modules and the kernel.
Finally, in the default configuration, the loader waits 10 seconds for the key to be pressed. Then it starts the kernel if no key is pressed. If the countdown time is interrupted, the user will be familiar with the prompt where you can give the loader easy-to-use commands. For example, you can fine-tune variables, unload all loaded kernel modules, load modules, eventually start the computer, or restart.
Commands built into the loader
Below are the most commonly used loader commands. If you would like to see a complete list of functions, please see the man page for loader (8).
It intends to run the kernel at a given time, unless it is interrupted. Displays the countdown. The default time is 10 seconds.
boot [-options] [kernel name]
Immediately starts the kernel with given options, if there are, with a kernel with that name, if it exists.
goes through the same automatic configuration of modules based on variables, as was the case at startup. This only makes sense if you use the unload command before. Then the variables change, most often the nucleus.