03.0 (Conspect) Pre-SystemBoot
Power on. What now? Run a program? What program? All we have is CPU and pristine clean RAM
- So, we should Use ROM. Thus we copy it to the pre-defined address of RAM and start there.
ROM:
- There are BIOS — to make a simple I/O operations (video, keyboard, primitive disk)
We can:
- select the device to boot from
and boot something from it. Call it primary loader.
Primary loader:
- Very small.
- Very dull.
- Specific by the device it resides:
- Knows how to read blocks from device
Knows what to read ad run from this device (e. g. by hardcoding a list of blocks to read just into primary loader code)
Secondary loader:
- Very smart (must be):
- Must recognize a umber filesystems (e. g. ext2, ext3, ext4, jfs, xfs, btrfs, zfs, HPFS, ...) to find loadable file on
Must recognize a number of formats (e. g. linux, BSD, windows, OS/X etc) to load any OS kernel
Must have an ability to load and link modules (drivers) with the kernel
Why? Because no modern kernel is so monolith to include all the drivers in it, and disk driver is sufficient to the kernel, that must mount that version disk as root
IRL: No such thing as universal boot loader
- Knows about disk partition and filesystems
Can select and boot specific OS kernel or something alike from the given FS
Can boot other secondary loader to boot another OS (e. g. windows)
- Very smart (must be):
OS kernel:
- Checks and tunes hardware
- mounts root filesystem
- initial OS startup
So, theoretically:
- BootROM
- Select a device to boot from
- Load a Boot block from it
- Boot block (primary loader)
(almost never) select a secondary loader
load and boot a secondary loader from somewhere at the current device
- Boot program (secondary loader)
- Select and boot variant (one of kernels available and parameters) and boot it
- or select and chainload another secondary loader (capable for boot other type kernels)
- Kernel
- check and set-up devices
- find filesystem to mount as root, mount it and initiate OS startup
The locked key problem:
- Kernel is to mount / directory from the particular filesystem of the particular partition on the particular hard disk drive connected to the particular disk controller
There are so many filesystem types, disks and disk controllers, that no kernel has them compiled in. Those are loadable modules, that collected as files on the particular filesystem (often in the /lib/modules directory). The kernel shall load some of them first
so, let's pick the VirtualBox and check out its settings:
- External devices. Not real, but images
- There is an adjustment of the chipset
- Absolute positioning is used for the mouse ( as on a tablet )
- The system is located on a SATA virtual hard disk
How does the operating system load?
Programs are copied to RAM from a permanent storage device and run.
The ROM loader can only load one sector from an external device. This sector contains a loader that is specific to this device.
The secondary loader (of any size) starts next. It can load multiple operating system cores.
In order for the download to be normal, all levels must be independent.
Problems
- There is a dependency problem: If the lower-level operation is managed with a higher level. Then when you write a change to one component, the other component will stop working.
- Another problem is the recognition of external devices. In other words, the core must be very "smart", since it is not possible to support controllers of all devices. To do this, the corresponding modules are loaded.
The secondary loader functions are divided into two parts:
- Load the core
- Find all the necessary modules and use them to build the core
The starting virtual disk is a small OS that contains all the necessary drivers and can link them to the core.
Commands
The df command shows which file systems are currently in use.
The lsblk command shows all available block devices.
New loading sequence:
We have a partition on a 128MB disk with the FAT16 file system. When the computer starts, a small OS called EFI is loaded from the ROM. This is a universal loader that is needed for trusted downloads. It can also run programs. It has its own drivers. Can check the core signature.
Windows works differently.