A bootloader loads an operating system after hardware tests. It begins by initializing hardware and loading the BIOS. The BIOS then loads the master boot record from the disk, which loads secondary bootloaders. These load the operating system by accessing memory in both real and protected modes. The boot process involves loading kernel files and an initial ramdisk to start processes and mount the full filesystem.
3. What is a bootloader ?
●
●
A boot loader is a computer program that loads
the main operating system or run time
environment for the computer after completion
of the self-tests.
Will be covering the loading and working of a
bootloader with respect to the physical memory
implementation of the x86 based systems.
4. Booting
●
The term boot is short for bootstrap or bootstrap load and derives
from the phrase to 'pull oneself up by one's bootstraps'. The usage
calls attention to the requirement that, if most software is loaded onto
a computer by other software already running on the computer, some
mechanism must exist to load the initial software onto the computer.
5. ●
Two major sections
–
Lower memory (< 1MB)
–
High memory
●
First 640 KB backed by RAM
●
Reserved memory for BIOS
●
Real Mode
–
–
Can only access lower memory
–
●
16 bit instructions
BIOS interrupts are available
Protected mode
–
32 bit instructions
–
Can access high memory
–
BIOS interrupts are not available
6. Boot Sequence
●
Turn on the Power button.
●
CPU pins are reset and registers are set to specific value.
●
CPU jumps to address of BIOS (0xF0000), the reset vector.
●
●
●
●
BIOS run POST (Power-On Self Test) and other necessary
checks.
BIOS jumps to MBR (Master Boot Record) of the boot disk.
Primary Bootloader runs from MBR and jumps to Secondary
Bootloader.
Secondary Bootloaders loads Operating System.
7. When in BIOS
●
A firmware interface
●
Initialize and test the system hardware components (POST)
●
Provides interface to access hardware (with interrupts)
●
●
●
●
Stored on a non-volatile ROM/flash memory chip on the
motherboard
Table of interrupt vectors resides in the beginning that contain
the segmented addresses of the interrupt handlers. The number
of interrupt is essentially an index into this table.
Checks each device to see if it's bootable
Loads the first sector (boot sector) from the disk to memory
address 0x007C00
8. Boot Sector
●
●
A Master Boot Record (MBR) is the first sector of a data storage
device that has been partitioned. The MBR sector may contain code
to locate the active partition and invoke its Volume Boot Record.
A Volume Boot Record (VBR) is the first sector of a data storage
device that has not been partitioned, or the first sector of an individual
partition on a data storage device that has been partitioned. It may
contain code to load and invoke an operating system installed on that
device or within that partition.
●
First 446 bytes are the primary boot loader
●
Next sixty-four bytes are the partition table
●
Ends with two bytes that should be 0x55AA. These numbers act as
validation that this sector is the boot sector or Master Boot Record.
10. First stage
●
Resides in the boot sector of disk
●
Loaded by the BIOS.
●
Should be covered in 446 bytes due to size constraints in the boot
sector.
●
Load segment registers (%DS, %ES, %FS, %GS, %SS).
●
Set the stack pointer.
●
Reset disk controller.
●
Reads the 2nd stage bootloader and loads it into memory.
●
Jump to it.
11. Second Stage
●
●
●
●
●
●
Query the BIOS for the size of lower and upper memory( INT 12h
BIOS interrupt).
Loads the kernel from the boot disk into memory, prepare the system
for executing the kernel, and jump to the kernel entry point.
Switch into protected mode and load the kernel into high (> 1 MB)
memory.
BIOS services used to read sectors from the boot disk are available
only in real mode and real mode cannot access high memory.
Repeatedly switch back and forth between real mode and protected
mode while reading the kernel from the floppy disk.
Small kernel can be preloaded entirely into low memory before
transitioning into protected mode.
12. Starting up … finally!!
●
●
●
●
●
●
●
Kernel needs startup arguments while loading, but this cannot be
done at runtime.
Solution: Configuration files (grub.cfg,initramfs)
The bootloader loads the kernel as well as the temporary filesystem
before the actual file system is loaded.
Initramfs(initial ram file system) : successor of initrd. Solves the
chicken-egg problem.
An archive of the initial file system that gets loaded into memory. The
Linux kernel mounts it as root file system and starts the init process
from it.
initramfs needs to contain all of the device drivers and tools needed
to mount the real root filesystem.
After all these, /sbin/init, /etc/init, /bin/init, and /bin/sh are called in the
order; the first user process is init and they read etc/events.d or
etc/inittab. Hence the system starts.