OS fundamentals - 10 - Bootloader.pdf
Document Details
Uploaded by TopnotchJubilation234
Tags
Related
- Artificial Intelligence & Data Science S.E. Operating Systems Past Paper PDF - 2019 Pattern
- The Bootloader: Definition, Location, Functioning, and Examples PDF
- Computer Science: Chapter 3 - Operating Systems (PDF)
- Computer Science: Operating Systems PDF
- Computer Science DSC and GE Sem I-II PDF
- OCR Computer Science A Level 1.2.1 Systems Software Notes PDF
Full Transcript
OS FUNDAMENTALS Bootloaders 1 Phaedra Degreef CPU BASICS • A CPU executes instructions − Binary code, machine code • It puts a memory address on the address buss • It can then either − Write a binary value (16, 32 or 64 bits) to that (physical) address in memory − Read a binary value from that...
OS FUNDAMENTALS Bootloaders 1 Phaedra Degreef CPU BASICS • A CPU executes instructions − Binary code, machine code • It puts a memory address on the address buss • It can then either − Write a binary value (16, 32 or 64 bits) to that (physical) address in memory − Read a binary value from that memory location • This binary value can be − An instruction to execute − Data 2 EXECUTING MACHINE CODE • How does a CPU know which instruction to execute? − A CPU was designed to go to a specific memory address when powered up • Called the bootstrap address • For x86 CPUs this is address FFFFFFF0 − It will execute whatever instructions it will find on that address 3 PC BOOT • In a modern PC, some machine code is stored in a (persistent) memory chip on the motherboard − BIOS − Will provide interfacing with the hardware on the motherboard − This will be the first code that the CPU executes when starting the PC • BIOS begins at bootstrap address 4 THE PC BOOT PROCESS • Multi-stage process: 5 THE PC BOOT PROCESS - BIOS • BIOS: − Low-level software integrated on motherboard − Detects hardware, interfaces with hardware − Executes POST (Power-On Self Test) 6 THE PC BOOT PROCESS - BIOS • BIOS setup: − Hardware settings are auto-detected − Can be modified by user − Setting stored in EEPROM (non-volatile memory) 7 THE PC BOOT PROCESS - BIOS • BIOS setup – boot sequence − Which storage devices can be used to boot from − In which sequence/order will be look for an OS • If no OS is found on a device, we go to the next in the list » This is determined by the presence or absence of a Master Boot Record (MBR) on the device 8 THE PC BOOT PROCESS - MBR • Master Boot Record (MBR) − Contains the partition table and bootstrap code (512 bytes) • Aka first-stage bootloader • Too little space to contain a real bootloader » Will refer to the location of the “real” bootloader (stage 2) 9 THE PC BOOT PROCESS - BOOTLOADER • Stage 2 bootloader − Will be on the active partition of the boot device − Will contain more complex code to select and locate the OS kernel files 10 THE PC BOOT PROCESS - BOOTLOADER 11 COMMON BOOTLOADERS 12 BIOS • • • • • Legacy Basic Input/Output System Memory location 0xFFFF0 For 16-bits CPUs Limited to 1 MB of memory Stored in memory chip on motherboard − Used to be CMOS − Now flash device 13 BIOS: LEGACY • Will locate, identify and wake hardware components • Settings stored in − battery-backed RAM (aka CMOS): old-skool − Now: flash memory (EEPROM) • Look for a bootloader on an MBR partition − Loads MBR into RAM • Disadvantage: changes in settings required a reboot 14 BIOS • Old OS’s (MS-DOS) still used the code in the BIOS to access hardware • Modern OS’s use their kernel (32-bit or 64-bit) and disable the original BIOS interrupts • Important limitation: resume PC from sleep − Was impossible because OS had no access to hardware − Solved by adding a new extension to BIOS: ACPI 15 ACPI Added to BIOS in 1996 • Provides power management capabilities • Allows OS to interact with power management • − For ACPI capable hardware (firmware!) − Hardware devices have their own ACPI-capable BIOS 16 ACPI POWER STATES 17 (U)EFI • 32- and 64-bits code possible (MBR: 16-bits) − Can function as a proper bootloader now − Linux kernel can fit in there ☺ • More partitions possible − GUIDs instead of 2-bits number • Larger partitions possible • Better network boot possibilities 18 (U)EFI • Bootloader is contained in hidden EFI partition 19 UEFI • Settings can be modified from within OS 20 UEFI • Allows booting from removable media (USB) • Allows legacy (BIOS) boot − A legacy MBR is contained in the EFI partition for this purpose 21 LINUX BOOT PROCESS 22 LINUX BOOT PROCESS 23 LINUX BOOTLOADER • LiLo − Single-stage bootloader − Doesn’t know filesystems or OS’s • Grub − More complex − Allows network boot 24 LINUX BOOTLOADER - GRUB • Grub understands ext* filesystems − Can use disks larger than 8GB • Multi-stage (2-3) • Can be installed on any device − − − − − Floppy Hard disk CD/DVD USB network • Displays a list of available kernels − On Ubuntu, defined in /boot/grub/menu.lst − Entries can be modified during boot process 25 GRUB 26 WHAT DOES GRUB LOAD? • kernel – a compressed kernel image − Performs initial minimal hardware setup − Decompress the kernel image, puts it in memory − If present, loads RAM disk (see below) • initrd – initial RAM disk − Temporary root file system − Contains executables and drivers to load the real root 27 INITRD • Initial RAM disk – a small temporary file • • • • 28 system During stage 2 boot, initrd is copied into RAM and mounted Allows the kernel to fully boot without having to mount any physical disks Supports many hardware configurations through loadable modules After kernel is booted, the real root file system is mounted INIT The first user-space program • Typical for desktop Linux systems • For Ubuntu, init reads /etc/event.d • For other Linux systems, init reads /etc/inittab • 29 GRUB CONFIGURATION • menu.lst file 30 GRUB OPTIONS • Listed at the start of the menu.lst file − Default 0: first OS will be booted by default − Timeout 8: user has 8 seconds to make a selection before the default OS is booted 31 WINDOWS BOOT PROCESS WINDOWS BOOT PROCESS • Pre-boot − BIOS locates a valid system disk − Reads the MBR • Windows boot manager − Located on %SystemDrive%\bootmgr − Finds and starts the Windows loader • Windows OS loader • Windows OS kernel 33 WINDOWS BOOT PROCESS • Pre-boot • Windows boot manager • Windows OS loader − Located in %SystemRoot%\system32\winload.exe − Essential drivers required to start the kernel are loaded − Load Windows OS kernel • Windows OS kernel − Located in %SystemRoot%\system32\ntoskrnl.exe 34 WINDOWS BOOT MANAGER • Located on a “System reserved” partition − Has no drive letter 35 SYSTEM RESERVED PARTITION (WIN8) 36 MODIFY WINDOWS BOOT OPTIONS • Windows tool: bcdedit 37 • GUI version: easyBCD 38 WHAT IF THINGS GO WRONG? THEY WON’T BUT JUST IN CASE…. WINDOWS BOOT REPAIR TIPS AND TRICKS • Restore the MBR • Write a new MBR on the system partition 43 OTHER OPTIONS 44 XP • After having installed XP in dual-boot, you need to restore the Windows 7/8/10 bootloader • Then restore XP back to the boot menu 45 AUTOMATED STARTUP REPAIR 46 LINUX BOOT REPAIR COMMAND-LINE WAY • 1) Boot from a USB or CD/DVD medium • 2) open terminal − Try to locate the system partition 48 49 • Mount the system partition to /mnt • Re-install grub from other media • Restart • Start breathing again 50 GUI WAY • Boot from USB or CD/DVD • Open terminal 51 52 PXE BOOT PXE BOOT • Boot a PC via the network − Instead of from a local medium (hd, CD, USB,…) • Preboot eXecution Environment • Introduced by Intel (1999) • Requires − − − − 59 PXE-capable network card (NIC) in client DHCP server TFTP server NFS server (in case of Linux) PXE BOOT • Traditional sequence: − BIOS -> local boot sector • PXE sequence: − BIOS -> NIC PXE stack -> Network Boot Program (NBP) • NBP is downloaded from a TFTP server, into RAM • Responsibility of the NIC 60 TFTP • Trivial FTP • FTP = File Transfer Protocol − Client/server network protocol − Transfer files between client and server − Uses client authentication • TFTP uses no authentication − Designed to be small and efficient − No FTP commands like “list, delete, rename” − Used to read/write files 61 PXE BOOT PROCESS • • • • • BIOS launches PXE from NIC firmware (2) PXE client requests IP from DHCP server (3) Receives IP & PXE bootfile name (pxelinux.0) Client loads pxelinux.0 file into RAM and passes control to it Pxelinux.0 gets boot config file from TFTP server 62 PXE BOOT PROCESS Pxelinux.0 requests kernel and RAMdisk from TFTP server • Loaded kernel takes control • − 63 Loads remaining parts from TFTP server GETTING DHCP INFORMATION 64 LOADING CONFIGURATION FROM TFTP 65 KERNEL TAKES CONTROL 66 KERNEL LOADS OTHER PARTS 67 BOOTING COMPLETE 68