Booting an Operating System

Booting an Operating System

How do you run that first program?

Paul Krzyzanowski

Introduction

An manoeuver sytem is sometimes described as “ the inaugural broadcast, ” one that allows you to run other programs. however, it is normally stored as a file ( or, more normally, a collection of files ) on a disk. How does this “ first ” plan get to run ?
PDP-11/70 front panel
PDP–11/70 front panel
The operate on system is loaded through a bootstrapping process, more succinctly known as booting. A boot loader is a plan whose job is to load a bigger program, such as the operate arrangement .
When you turn on a calculator, its memory is normally uninitialized. Hence, there is nothing to run. early computers would have hardware that would enable the operator to press a clitoris to load a sequence of bytes from punch cards, punched paper videotape, or a tape drive. Switches on the computer ’ sulfur front control panel would define the source of the data and the prey memory address. In some cases, the boot loader software would be hard wired as non-volatile memory ( in early computers, this would be a power system of wires with cuts in the appropirate places where a 0-bit was needed ).

In early minicomputer and personal computer systems systems, a calculator hustler would use the switches on the calculator ’ randomness front gore to toggle in the code to load in a bigger program, programming each memory location and then starting the platform. This broadcast might do something basic such as read consecutive bytes into memory from a composition videotape attached to a teletype .
In subsequently systems, read-only memory would contain a modest bootloader that would have basic intelligence to read, say, the first sector ( 512 bytes ) of a disk .
Since this initial platform had to be a little as potential, it would have minimal capabilities. What frequently happened is that the boot stevedore would load another boot stevedore, called a second stage
loader
, which was more twist. This second stage loader would have error determine, among possibly other features, such as giving the user a choice of operating systems to boot, the ability to load diagnostic software, or enabling diagnostic modes in the operate system. This multi-stage boot loader, having a boot loader load a bigger boot loader, is called chain loading .
The boot stevedore will frequently perform some core low-level formatting of the system hardware and will then load the operating system. once the operating system is loaded, the boot stevedore transfers control to it and is no longer needed. The operate system will initialize itself, configure the system hardware ( for example, set up memory management, sic timers, set interrupts ), and load device drivers, if needed .

Intel-based (IA–32) startup

To make the example of the boot process concrete, let us take a attend at 32-bit Intel-compatible PCs ( we ’ ll get to 64-bit systems in a piece ). This computer architecture is known as IA–32 ( Intel Architecture, 32-bit ) and defines the teaching set of most Intel microprocessors since the Intel 80386 that was introduced in 1986. It is hush supported on Intel ’ s latest processors .
An IA–32-based personal computer is expected to have a BIOS ( Basic Input/Output System, which comprises the bootloader firmware ) in non-volatile memory ( ROM in the by and NOR flash memory these days ). The BIOS is a descendant of the BIOS found on early CP/M systems in that it contains low-level functions for accessing some basic arrangement devices, such as performing disk I/O, reading from the keyboard, and accessing the video expose. It besides contains code to load a stage 1 boot loader .
When the CPU is reset at inauguration, the computer starts execution at memory localization 0xffff0 ( the IA–32 architecture uses a segment : counterbalance form of addressing ; the code section is set to 0xf000 and the teaching cursor is set to fff0 ) .
The central processing unit starts up in real mode, which gives it access to only a 20-bit memory address space and provides it with mastermind access to I/O, interrupts, and memory ( 32-bit address and virtual memory comes into play when the processor is switched to protected mode ). The placement at 0xffff0 is actually at the conclusion of the BIOS ROM and contains a jump direction to a area of the BIOS that contains start-up code .
Upon start-up, the BIOS goes through the pursue succession :

  1. Power-on self-test (POST)
  2. Detect the video card’s (chip’s) BIOS and execute its code to initialize the video hardware
  3. Detect any other device BIOSes and invoke their initialize functions
  4. Display the BIOS start-up screen
  5. Perform a brief memory test (identify how much memory is in the system)
  6. Set memory and drive parameters
  7. Configure Plug & Play devices (traditionally PCI bus devices)
  8. Assign resources (DMA channels & IRQs)
  9. Identify the boot device

When the BIOS identifies the boot device ( typically one of several disks that has been tagged as the bootable disk ), it reads obstruct 0 from that device into memory placement 0x7c00 and jumps there .

Stage 1: the Master Boot Record

This first disk block, blocking 0, is called the Master Boot Record ( MBR ) and contains the beginning stage boot stevedore. Since the criterion stop size is 512 bytes, the entire bang stevedore has to fit into this space. The contents of the MBR are :

  • First stage boot loader (≤ 440 bytes)
  • Disk signature (4 bytes)
  • Disk partition table, which identifies distinct regions of the disk (16 bytes per partition × 4 partitions)

Stage 2: the Volume Boot Record

once the BIOS transfers control to the originate of the MBR that was loaded into memory, the MBR code scans through its partition table and loads the Volume Boot Record ( VBR ) for that partition. The VBR is a sequence of consecutive blocks starting at the first disk block of the designate division. The first block of the VBR identifies the partition type and size and contains an Initial Program Loader ( IPL ), which is code that will load the extra blocks that comprise the second stage boot
loader
. On Windows NT-derived systems ( for example, Windows Server 2012, Windows 8 ), the IPL loads a program called NTLDR, which then loads the operate system .
One cause that humble flat boot loaders have a unmanageable prison term with loading a full OS, specially one that may be composed of multiple files, is that doing therefore requires the ability to parse a file system structure. This means understanding how directories and file names are laid out and how to find the data blocks that correspond to a specific file. Without much code, it is far easier to just read straight blocks. A higher-level loader, such as Microsoft ’ mho NTLDR, can read NTFS, FAT, and ISO 9660 ( four hundred ) file formats .

Beyond Windows

There are many variations on booting other operating systems on an Intel personal computer. One popular boot loader on Linux systems is GRUB, or GRand Unified Bootloader. GRUB is besides a multistage boot stevedore. The BIOS, of run, does what it always does : identifies a bootable device, loads the Master Boot Record, and transfers control to this newly-loaded code. Under GRUB, the MBR typically contains a first-stage boot stevedore called GRUB Stage 1. This stage 1 boot stevedore loads GRUB Stage 2. The stagecoach 2 loader presents the exploiter with a choice of operating systems to boot and allows the user to specify any extra boot parameters for those systems ( for example, impel maximal memory, enable debug ). It then reads in the selected manoeuver system kernel and transfers control to it .
A specific trouble with using GRUB to boot Windows is that Windows is not Multiboot compliant. Multiboot is a free Software Foundation stipulation on loading multiple operating systems using a individual boot stevedore. What GRUB does in this sheath is fake a conventional Windows boot march. It boots a bootloader that would normally reside in the MBR ( or run the Windows boot menu program ). From that point forth, GRUB is out of the photograph, Windows has no idea what happened, and the native Windows boot process takes over .

Good-bye, BIOS. Hello UEFI

As 64-bit architectures emerged to replace 32-bit architectures, the BIOS was starting to look quite dated. Intel set out to create a specification of a BIOS successor that had no restrictions on having to run the inauguration code in 16-bit mode with 20-bit address. This specification is called the Unified Extensible Firmware Interface, or UEFI. Although developed by Intel, it was managed since 2005 by the Unified EFI Forum. It is used by many newer 64-bit systems, including Macs, which besides have bequest BIOS support for running Windows .
Some of the features that EFI supports are :

BIOS components
preserved some components from the BIOS, including power
management (Advanced Configuration & Power Interface, ACPI)
and system management components (e.g., reading and setting date).
Support for larger disks
The BIOS only supported four partitions per disk, with a capacity
of up to 2.2 TB per partition. UEFI supports a maximum partition
size of 9.4 ZB (9.4 × 1021 bytes).
No need to start up in 16-bit (real) mode
The pre-boot execution environment gives you direct access to all of system memory.
Device drivers
UEFI includes device drivers, including the ability to interpret
architecture-independent EFI Byte Code (EBC). Operating systems use
their own drivers, however, so — as with the BIOS — the
drivers are generally used only for the boot process.
Boot manager
This is a significant one. The old BIOS only had the smarts
to load a single block, which necessitates multi-stage booting
process. UEFI has its own command interpreter
and complete boot manager. You no longer need a dedicated boot
loader. As long as you place the bootable files into the UEFI boot
partition, which is formatted as a FAT file system (the standard
file system format in older Windows systems; one that just about
every operating system knows how to handle).
Extensibility
The firmware is extensible. Extensions to UEFI can be loaded into non-volatile memory.

Booting with UEFI

With UEFI, there is no longer a motivation for the Master Boot Record to store a stage 1 boot loader ; UEFI has the smarts to parse a file system and load a file on its own, even if that charge does not occupy adjacent harrow blocks. rather, UEFI reads the GUID ( Globally Unique IDentifier ) Partition Table ( GPT ), which is located in blocks immediately after blocking 0 ( which is where the MBR still sits for bequest reasons ). The GPT describes the layout of the partition table on a magnetic disk. From this, the EFI bang stevedore identifies the EFI System Partition. This system partition contains boot loaders for all operate systems that are installed on other partitions on the device. For EFI-aware Windows systems, UEFI loads the Windows Boot Manager ( bootmgfw.efi ). For older 64-bit NT systems, EFI would load IA64ldr. For Linux, there are many options. Two common ones are to use an EFI-aware interpretation of GRUB ( the Grand Unified Bootloader ) and load a file such as grub.efi or to have EFI warhead load elilo.efi, the EFI loader.

In cosmopolitan, even with UEFI, the dominant set about is to load an boot stevedore dedicated to a specific operating system rather than load that manoeuver system immediately. however, the indigence for a multi-stage bang process that requires loading multiple bootloaders is no long necessity .

Non-Intel Systems

Our entire discussion therefore army for the liberation of rwanda has focused on booting with the Intel PC-based architecture ( which includes IA–32/IA–64 compatible architectures, such as those by AMD ). This is the prevailing architecture in nowadays ’ south PCs ( notebooks through servers ) but there are many, many non-Intel devices out there, peculiarly in embedded devices, such as cell phones. What about them ?
There are numerous implementations of the boot process. Many embedded devices will not load an operate system but have one already stored in non-volatile memory ( such as ostentation or ROM ). Those that load an OS, such as ARM-based Android phones, for case, will execute code in read-only memory ( typically in NOR ostentation memory ) when the device is powered on. This boot code is embedded within the CPU ASIC on some devices sol you do not need a disjoined flash memory nick on the board .
When the system is reset ( which includes a power-up ), the processor is in supervisory program ( SVC ) modality and interrupts are disabled. On ARM-based systems the central processing unit starts execution at address 0x00000000. The flash memory containing start-up code is mapped to address 0x00000000 on reset. This code performs respective initializations, including setting up an exception vector table in DRAM and copying application code from ROM to DRAM ( code runs faster in DRAM ). The code remaps the DRAM to address 0, thus hiding the flash memory ( the processor has a REMAP bit to change the map of flash memory ). The memory organization is then initialized. This involves setting up memory protection and setting up the organization stacks. I/O devices are then initialized and the processor is changed to user mode. The boot firmware detects bootable media and loads and runs the moment stage boot stevedore ( if necessary ). The second stage boot loader is often GRUB for larger systems or uBoot for embedded systems. This second base stage stevedore loads the engage system and transfers control to it .

Mac OS X

Older PowerPC-based versions of Apple Macintosh systems, as of at least OS 8 a well as OS X, were based on Open Firmware. Open Firmware originated at Sun and was used in non-Intel Sun computers. once Apple switched to Intel systems, it adopted UEFI as its boot-level firmware .

Older Macs

Open Firmware is stored in ROM and, like the personal computer BIOS, is executed on power-on. Since Open Firmware was designed to be platform mugwump, it is implemented in Forth ( a simple stack-based speech ) and compiled to bytecodes quite than native machine instructions. The firmware contains a byte code interpreter .
Unlike the BIOS, Open Firmware provides the user with a command-line processor from which one can edit system configuration parameters, such as reduce the amount of physical memory, debug the system, or even start a telnet server so that you can interact with the firmware and boot serve from a distant machine via an ethernet connection .
Before booting the operating system, the Open Firmware generates a device tree by probing components on the main board and expansion devices .
Like the personal computer BIOS, Open Firmware contains device drivers that the bang process in the firmware can use to access the phonograph record, keyboard, monitor, and network. however, these drivers are all implemented in FCode, the Forth bytecode system. besides like the BIOS, these drivers are used only during the boot procedure. The operate system itself has its own native runtime drivers .
Unlike the BIOS, Open Firmware could parse the HFS/HFS+ file systems ( the native file arrangement on Macs ), so you could use the Open Firmware command spokesperson to load in a bang file from the arduous magnetic disk and run it. By default, Open Firmware loads a file from the arrangement division. On OS 9 systems, this was the file called “ Mac OS ROM ” in the System folder. On OS X systems, it loads /System/Library/CoreServices/BootX. BootX is bootloader that then loads in the kernel .

The Mac today

The Mac uses UEFI for its system firmware .
When the Mac starts up, the first code that gets executed is the BootROM. This sets up EFI drivers for relevant hardware devices, initializes some of the hardware interfaces, validates that sufficient memory is available, and performs a brief power-on self-test. Unlike the personal computer BIOS, which knew nothing about file systems and could only read bare-assed disk blocks, UEFI on the Mac has been extended to parse both FAT ( bequest DOS/Windows ) and HFS+ ( native Mac ) filesystems on a phonograph record. It reads the GPT ( GUID Partition Table ) to identify harrow partitions. The default kick volume is stored in NVRAM .
rather of specifying a path to a boot loader, the HFS+ volume header ( data at the start of an HFS+ file system ) points to a blessed file or blessed directory ( see the bless command. If a directory is blessed, that tells the EFI firmware to look in that directory for the kick loader. If a file is blessed, that tells the EFI firmware to load that file as the boot loader ( there are extra variations, such as booting from an unmounted volume ) .
By default, the boot stevedore is located in /System/Library/CoreServices/boot.efi on the beginning ( much entirely ) division of the harrow .
alternatively, the firmware supports downloading a second-stage bootloader or a kernel from a network waiter ( netboot server ) .
When the boot.efi file is loaded, the computer displays a metallic Apple logo on the shield. The boot stevedore loads in the kernel equally well as essential driver extensions, which then runs launchd, which executes the diverse startup scripts and programs. Once the kernel is loaded, the spin gear gear appears below the Apple logo. When the kernel runs the first process, launchd, the screen turns bluing .
A description of how OS ten starts up can be found in What is Mac OS X .
To support booting BIOS-based operating systems, such as older Windows systems and Linux systems that use GRUB or other BIOS-aware boot loaders, the EFI installs a “ compatibility accompaniment module ” ( CSM ) part from the system firmware. This then starts a BIOS-based boot process. This compatibility corroborate faculty is loaded alone when the exploiter selects Windows as the default OS to boot. The boot process now is a standard BIOS-based boot. The Master Boot Record ( MBR ) is loaded and executed, which then locates and loads the bulk Boot Record of the Windows ( or Linux ) partition.

References

Mac boot references
Mac OS X references :

  • Mac-GPT, Mac OS X Reference Library, Apple Inc.
  • Mac-Boot, Mac OS X Reference Library, Apple Inc.
  • Mac-Intel, HT2674, Apple Inc.
  • Mac-Admin, © 2007 Apple Inc.
  • Mac-bless
  • Mac-Intel-boot, rEFIt Sourceforge Project

This is an update version of the master document, which was written on September 14, 2010 .

source : https://swivelcard.info
Category : Tech FAQ

Related Posts

Leave a Reply

Your email address will not be published.