Operating System Kernel and the boot process Nick Urbanik Copyright Conditions: GNU FDL (see http://www.gnu.org/licenses/fdl.html) Department of Information and Communications Technology OSSI — ver. 1.3 Operating System Kernel and Booting - p. 1/56 Operating System: Kernel and boot process Operating System: Kernel and boot process Role of OS What is it? What does it do? How does it start up? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 2/56 What is an operating system? I I I Is it what you get when you install Linux, Windows XP or Windows 2000? Does it include such things as (g)notepad, g++ or Visual C++? How about bash, cmd.exe or command.com? Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT OSSI — ver. 1.3 Operating System Kernel and Booting - p. 3/56 The I I OS is the kernel Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT The operating system is the kernel When the computer boots the operating system, it loads the kernel into memory. OSSI — ver. 1.3 Operating System Kernel and Booting - p. 4/56 Kernel in Linux I I I I In Linux, kernel can be loaded by LILO or grub Kernel is in /boot In RH 9, it is N /boot/vmlinuz-2.4.20-20.9, N or if you build your own, something like /boot/vmlinuz-2.4.22-ac6 It is a monolithic kernel Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT OSSI — ver. 1.3 Operating System Kernel and Booting - p. 5/56 Kernel in Windows I XP, 2000, Win NT Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT I I I I In %SystemRoot%\System32 N %SystemRoot% = C:\winnt, or D:\winnt,. . . Called ntoskrnl.exe Microsoft call it a layered kernel or microkernel. sometimes called the “Executive services” and the “NT executive” Bottom layer is the hardware abstraction layer OSSI — ver. 1.3 Operating System Kernel and Booting - p. 6/56 What does an I OS do? Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT I Provides a “government” to share out the hardware resources fairly Provides a way for the programmer to easily work with the hardware and software through a set of system calls — see slides §15–§18. N Sometimes also called supervisor calls OSSI — ver. 1.3 Operating System Kernel and Booting - p. 7/56 Is there a User Friendly I OS? Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT I I I I Some people have said that the Windows OSs are more user friendly than Linux Can this be the case? N Are the system calls more user friendly? I (see slides §15–§18 for more about system calls) N Does Windows manage the hardware in a more user friendly way? No! The user interface is not an operating system issue. See your subject Human Computer Interfaces (HCI) Do you want a more user friendly interface for Linux? N Then write one! Contribute to the Gnome or KDE projects. OSSI — ver. 1.3 Operating System Kernel and Booting - p. 8/56 Example: I MAC OS X Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT I I I I The Mac has a deserved reputation for a great user interface OS X is the latest OS from Apple Very beautiful, easy to use But it is Unix, built on FreeBSD! N The Unix that till now has mostly been used on servers; N considered by some to be less user friendly than Linux The User Interface is not part of the OS OSSI — ver. 1.3 Operating System Kernel and Booting - p. 9/56 Is I IE part of Windows OSs? Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT I I Is Internet Explorer part of the Windows operating systems? Please discuss this question with your neighbour. See http://news.com.com/2100-1001-219029.html?legacy=cnet OSSI — ver. 1.3 Operating System Kernel and Booting - p. 10/56 What resources does I OS manage? Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT The OS manages resources such as: N Use of CPU N Memory N Files and disk access N Printing N Network access N I / O devices such as keyboard, mouse, display, devices, . . . USB OSSI — ver. 1.3 Operating System Kernel and Booting - p. 11/56 . . . Allocated to who/what? I I I An operating system can be multiuser N In this case, resources must be allocated to the users fairly “Proper” operating systems are multitasking N Resources must be allocated fairly to the processes Users, processes must be protected from each other. Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT OSSI — ver. 1.3 Operating System Kernel and Booting - p. 12/56 Kernel mode and user mode I I I I I Kernel means “central part” The kernel is the central part of OS It is a program running at all times Application programs run in “user mode” N Cannot access hardware directly Kernel runs in “kernel mode” (or “supervisor mode”) N Can access hardware, special CPU registers Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT OSSI — ver. 1.3 Operating System Kernel and Booting - p. 13/56 How does user program access hardware? I I I I I I I A program that writes to the disk accesses hardware How? Standard library call, e.g., fprintf() Library contains system calls N see slides §15–§18 A system call passes the request to the kernel The kernel, (executing in kernel mode always) writes to the disk Returns telling user program that it was successful or not Operating System: Kernel and boot process Role of OS What is an operating system? The OS is the kernel Kernel in Linux Kernel in Windows XP, 2000, Win What does an OS do? Is there a User Friendly Example: MAC OS X IE part of Windows? What resources? . . . Allocated to who/what? Kernel mode and user mode Access Hardware? System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OS? NT OSSI — ver. 1.3 Operating System Kernel and Booting - p. 14/56 Kernel: programmers’ standard interface I I I This is the second important function of the operating system Provides a standard set of system calls, used by the libraries User programs usually use the system calls indirectly N since libraries give higher level interface Operating System: Kernel and boot process Role of OS System Calls System calls System Call System Calls — Linux Windows System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 15/56 System Call I I Low level details: N CPU provides a trap instruction which puts the CPU into a priveleged mode, i.e., kernel mode I On Intel ix86 architecture, the trap instruction is the int 0x80 instruction I See include/asm-i386/unistd.h and arch/i386/kernel/entry.S in Linux source code. See also http://en.tldp.org/LDP/khg/HyperNews/get/syscall/syscall86.html N Sometimes called a software interrupt N put parameters into CPU registers before the call N save values of many registers on a stack High level: all this buried in external library interface Operating System: Kernel and boot process Role of OS System Calls System calls System Call System Calls — Linux Windows System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 16/56 System Calls — Linux I POSIX I I specifies particular function calls that usually map directly to system calls — see man section 2 Provide a higher level interface to system calls Less than 300 of them. Examples: Description Operating System: Kernel and boot process Role of OS System Calls System calls System Call System Calls — Linux Windows System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References Call pid = fork() exit( status ) fd = open( file, O_RDONLY ) status = close( fd ) n = read( fd, buffer, nbytes ) n = write( fd, buffer, nbytes ) status = chdir( dirname ) Create a child process identical to parent process Terminate process and return status Open a file for reading, writing or both Close an open file Read data from file into a buffer Write data from buffer into a file Change working directory of process OSSI — ver. 1.3 Operating System Kernel and Booting - p. 17/56 System Calls — Windows and Win32 I I I I API Operating System: Kernel and boot process Role of OS System Calls System calls System Call System Calls — Linux Windows System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel I Win32 API provides many thousands of calls No one-one mapping to system calls Not all make a system call On some versions of Windows OSs, graphics calls are system calls, on others they are not Win32 API documented on MSDN. Examples: Win32 Description POSIX fork exit open close read write CreateProcess ExitProcess CreateFile CloseHandle ReadFile WriteFile create a new process Terminate execution Create a file or open existing file Close a file Read data from a file Write data to a file Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 18/56 Types of Operating System Operating System: Kernel and boot process Role of OS System Calls Types of OS Types of Operating System A rough breakdown of the types of OS Types of OS? Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 19/56 What types of operating systems are there? I I I I I OSSI — ver. 1.3 There are four main categories; depends on organisation of the kernel Monolithic operating systems N Linux is a monolithic OS Layered operating systems N Windows NT/2000/XP/2003 is described as a layered architecture Microkernel with client server architecture N The QNX real-time OS is truly a microkernel; the kernel is said to be only eight kilobytes in size! N Andrew Tanenbaum wrote the MINIX operating system as an example microkernel OS for students to study N The GNU Hurd OS has a microkernel architecture N Windows 2000 is described as having a hybrid layered-microkernel architecture, although Andrew Tanenbaum disagrees: http://www.cs.vu.nl/~ast/brown/ Virtual machine architecture Operating System: Kernel and boot process Role of OS System Calls Types of OS Types of Operating System Types of OS? Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References Operating System Kernel and Booting - p. 20/56 Monolithic Kernel I I A monolithic kernel has all procedures in the same address space. N This means that all the code can see the same global variables, same functions calls, and N there is only one set of addresses for all the kernel Purpose is speed: N to reduce overhead of communication between layers Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Monolithic Kernel Monolithic kernel — 2 Structure in a Monolithic Kernel Monolithic kernel: loadable modules Monolithic kernel: Loadable Modules Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 21/56 Monolithic kernel — 2 client process n client process 1 Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Monolithic Kernel Monolithic kernel — 2 Structure in a Monolithic Kernel Monolithic kernel: loadable modules Monolithic kernel: Loadable Modules ..... user mode Monolithic kernel includes: virtual memory, I/O, file handling scheduling, device drivers,... Hardware kernel mode Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 22/56 Structure in a Monolithic Kernel I I I To avoid chaos, a monolithic kernel must be well structured Linux kernel uses loadable modules, which support hardware and various software features Such as RAID, Logical Volume Managers, various file systems, support for various networking protocols, firewalling and packet filtering,. . . Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Monolithic Kernel Monolithic kernel — 2 Structure in a Monolithic Kernel Monolithic kernel: loadable modules Monolithic kernel: Loadable Modules Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 23/56 Monolithic kernel: loadable modules client process n client process 1 ..... dynamically loadable modules to support hardware, device drivers Monolithic kernel Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Monolithic Kernel Monolithic kernel — 2 Structure in a Monolithic Kernel Monolithic kernel: loadable modules Monolithic kernel: Loadable Modules user mode ... kernel mode Layered Kernel Microkernel Virtual machine Hardware Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 24/56 Monolithic kernel: Loadable Modules I I I I I I Loadable modules in Linux kernel support: Dynamic Linking: modules can be loaded and linked with the kernel, or unloaded, while kernel is executing Stackable Modules: Modules can provide support for each other, so many modules can be stacked on a lower level module. Reduces replication of code Hierarchical structure ensures that modules will remain loaded while required View loaded modules by typing lsmod Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Monolithic Kernel Monolithic kernel — 2 Structure in a Monolithic Kernel Monolithic kernel: loadable modules Monolithic kernel: Loadable Modules Layered Kernel Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 25/56 Layered kernel I I I I I I I Has different levels; example: Lowest level manages hardware Next level up manages, e.g., memory and disks Next level up manages I / O,. . . . Each layer may have its own address space Communication between layers requires overhead Advantage is different layers cannot interfere with each other. Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Layered kernel Layered Kernel — 2 Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 26/56 Layered Kernel — 2 5 4 3 2 1 0 Operating System: Kernel and boot process User Programs File Systems Interprocess Communication I/O and device management Virtual memory Primative process management Hardware Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Layered kernel Layered Kernel — 2 Microkernel Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 27/56 Microkernel with Client-Server Arch. I I I I Microkernel architecture keeps the kernel as small as possible, for the sake of reliability and security As much is done in the user space as possible User space provides servers, such as memory server, file server, terminal server, process server Kernel directs requests from user programs to user servers Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Microkernel with Client-Server Arch. Microkernel Architecture — 2 Microkernel Architecture — 3 Microkernel Architecture — Examples Windows 2000 Architecture Windows 2000 Architecture — 2 Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 28/56 Microkernel Architecture — 2 Operating System: Kernel and boot process Role of OS System Calls Types of OS file server ..... virtual memory process server device drivers client process user mode Monolithic Kernel Layered Kernel Microkernel Microkernel with Client-Server Arch. Microkernel Architecture — 2 Microkernel Architecture — 3 Microkernel Hardware kernel mode Microkernel Architecture — Examples Windows 2000 Architecture Windows 2000 Architecture — 2 Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 29/56 Microkernel Architecture — 3 I I I Most of operating system is a set of user processes the server processes do most of the work The microkernel mostly just passes requests from client processes to server processes virtual memory process server device drivers client process Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Microkernel with Client-Server Arch. Microkernel Architecture — 2 Microkernel Architecture — 3 Microkernel Architecture — Examples Windows 2000 Architecture Windows 2000 Architecture — 2 Virtual machine Boot Process ..... Client obtains service by sending messages to server process Microkernel file server Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 30/56 Microkernel Architecture — Examples I I I I Mach kernel used as core for many Unix OS N including the MAC OS X GNU Hurd OS, initiated by Richard Stallman for the GNU project The QNX distributed real-time Unix-like OS N kernel only 8 KB in size! It can be debated whether Windows NT/2000/XP/2003 operating systems are microkernels: “With all the security problems Windows has now, it is increasingly obvious to everyone that tiny microkernels, like that of MINIX, are a better base for operating systems than huge monolithic systems.” — Prof. Andrew Tanenbaum, http://www.cs.vu.nl/~ast/brown/ Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Microkernel with Client-Server Arch. Microkernel Architecture — 2 Microkernel Architecture — 3 Microkernel Architecture — Examples Windows 2000 Architecture Windows 2000 Architecture — 2 Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 31/56 Windows 2000 Architecture I I I Windows 2000 is described as a hybrid between a layered architecture and microkernel architecture. HAL provides an abstract machine—aim to make porting to other hardware architectures easier HAL + Microkernel ≈ normal microkernel Environment subsystem I/O Manager Executive Microkernel Hardware Abstraction Layer (HAL) Hardware Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Microkernel with Client-Server Arch. Microkernel Architecture — 2 Microkernel Architecture — 3 Microkernel Architecture — Examples Windows 2000 Architecture Windows 2000 Architecture — 2 Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 32/56 Windows 2000 Architecture — 2 I I I Environment subsystem aims to support DOS, Win32, OS/2 applications N each environment subsystem uses a DLL (dynamic link library) to convert system calls to Windows 2000 calls The I / O manager contains file system and device drivers Microkernel, HAL and “many functions of the executive” execute in kernel mode. N Sacrifice advantage of microkernel of reduced code executing in kernel mode N to reduce communication overhead Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Microkernel with Client-Server Arch. Microkernel Architecture — 2 Microkernel Architecture — 3 Microkernel Architecture — Examples Windows 2000 Architecture Windows 2000 Architecture — 2 Virtual machine Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 33/56 Virtual machine I I I I I I Virtual hardware Many operating systems run independently on same computer IBM now selling mainframes running many instances of Linux to Telecom companies — see next slides VMWare allows something similar on PC: http://www.VMWare.com http://www.connectix.com/ used to sell Virtual PC and Virtual Server, but they have been bought out by Microsoft, who of course, have dropped Linux support: http://www.msfn.org/comments.php?id=5516&catid=1 Java Virtual machine also provides virtual hardware that all programs can execute on. Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Virtual machine Virtual Machine OS Examples Linux on zVM on ZSeries Mainframe Many Individual Machines Many Virtual Machines, one Mainframe In Kernels, “small is beautiful” Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 34/56 Virtual Machine I IBM I I I OS Examples Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Virtual machine Virtual Machine OS Examples Linux on zVM on ZSeries Mainframe Many Individual Machines Many Virtual Machines, one Mainframe In Kernels, “small is beautiful” Boot Process Runlevels References I I designed the CP/CMS virtual OS for their S/360 mainframe. Later called VM/370 to run on their S/370 mainframes Later called VM/ESA on the S/390 hardware Now sold as zVM® running on zSeries mainframes N Supports running many different OS, particularly Linux N See http://www.vm.ibm.com/ See how MIT run Linux on VM/ESA on their S/390 mainframe: http://mitvma.mit.edu/system/vm.html Search the web for articles on Linux running on mainframes. OSSI — ver. 1.3 Operating System Kernel and Booting - p. 35/56 Linux on zVM on ZSeries Mainframe Virtual zSeries 900 machines OS executes I/O instruction here: User apps Linux 1 Linux 2 trap here Linux n Application makes a system call here: Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Virtual machine Virtual Machine OS Examples Linux on zVM on ZSeries Mainframe Many Individual Machines Many Virtual Machines, one Mainframe In Kernels, “small is beautiful” Boot Process Runlevels References trap here: zVM zSeries 900 Hardware OSSI — ver. 1.3 Operating System Kernel and Booting - p. 36/56 Many Individual Machines I A data centre may have many servers N Each must be powerful enough to meet peak demand N Most are not at peak demand most of the time N . . . so most are underused N . . . but must pay for electricity for cooling, and for powering all that reserve capacity Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Virtual machine Virtual Machine OS Examples Linux on zVM on ZSeries Mainframe Many Individual Machines Many Virtual Machines, one Mainframe In Kernels, “small is beautiful” Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 37/56 Many Virtual Machines, one Mainframe I I Can replace many individual servers with one mainframe running many instances of an OS such as Linux N The demand spread out among all the virtual machines, N total utilisation high — demand shared N busy virtual machines get more CPU power to meet peak demand N Much lower power requirements N Much less air conditioning cost N Much less floor space required Virtual machines partitioned from each other, like the individual machines in data centre Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Virtual machine Virtual Machine OS Examples Linux on zVM on ZSeries Mainframe Many Individual Machines Many Virtual Machines, one Mainframe In Kernels, “small is beautiful” Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 38/56 With Kernels, “small is beautiful” I I I I I The reliable operation of any computer depends on its operating system, i.e., it’s kernel. More complex software has higher chance of bugs, security problems, vulnerability to worms and viruses Linus Torvalds imposes a strict discipline on kernel developers to carefully restrict code that will increase size of kernel Linux does not suffer from “kernel bloat” N Compare the size of the Windows 2000 “microkernel:” several megabytes, cannot be booted from floppy N Linux: small enough to fit on one floppy together with many useful tools: http://www.toms.net/rb/ Movies: N Linus discusses Monolithic, Microkernel design, ETU, avi, avi2 Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Virtual machine Virtual Machine OS Examples Linux on zVM on ZSeries Mainframe Many Individual Machines Many Virtual Machines, one Mainframe In Kernels, “small is beautiful” Boot Process Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 39/56 Booting an Operating System Operating System: Kernel and boot process Role of OS System Calls The OS manages the hard disks. How can the system read the hard disk to start the OS? Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 40/56 Booting a I I I I I I I I PC Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References The process of starting the computer ready for use How does a computer boot? Involves: BIOS (“basic input output system”) finding the boot loader The boot loader starting the kernel For Linux: The kernel starting init init starting everything else OSSI — ver. 1.3 Operating System Kernel and Booting - p. 41/56 Boot Loader I I I I A boot loader is a piece of software that runs before any operating system, and is responsible for loading an operating system kernel, and transferring control to it Microsoft OS provides a boot loader that starts their OS from the first active primary partition We use the grub (Grand Unified Boot Loader) boot loader that can start any operating system from almost any hard disk, floppy or network. Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 42/56 The boot process for a I I PC Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References I the BIOS performs a power on self-test (POST) the BIOS initialises PCI (Peripheral Component Interconnect) devices the bootloader loads the first part of the kernel into system RAM I I I I I the kernel identifies and initialises the hardware in the computer the kernel changes the CPU to protected mode init starts and reads the file /etc/inittab the system executes the script /etc/rc.d/rc.sysinit the system executes scripts in /etc/rc.d/init.d to start services (daemons) OSSI — ver. 1.3 Operating System Kernel and Booting - p. 43/56 Before the bootloader: The I I I I BIOS Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References I I runs in real mode (like old 8086) BIOS tests hardware with basic Power On Self Test (POST) BIOS then initialises the hardware. Very important for the PCI devices, to ensure no conflicts with interrupts. See a list of PCI devices. BIOS settings determine order of boot devices; when finds one, loads first sector into RAM, starts executing that code. The BIOS OSSI — ver. 1.3 Operating System Kernel and Booting - p. 44/56 VMWare Boot Screen Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 45/56 Boot Loaders: what they do I I I Syslinux is the simplest, grub has the most features, LILO in between Grub provides many interactive commands that allow: N Reading many different file systems N Interactively choosing what to boot N Many, many more things (do pinfo grub) N All before any operating system started!! Grub and LILO let you choose what OS to boot Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 46/56 The kernel is loaded I I I I Boot loader reads first part of the kernel into RAM, executes the code This initial kernel code loads the rest of the kernel into RAM The kernel checks the hardware again The kernel switches from real mode to protected mode Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 47/56 Real and Protected mode I I I I I I I I I Real mode exists for booting, and so that can run old programs Uses only bottom 16 bits of registers Can only access the bottom 1 MB RAM BIOS only supports real mode Protected mode uses all 32 bits of address registers Allows access to all RAM Allows use of memory management unit Normal mode of operation for modern OSes on Intel platform. Cannot call BIOS functions in protected mode DOS Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 48/56 Kernel in Protected Mode: init, I PID 1 Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Booting an Operating System Booting a PC Boot Loader Boot Process BIOS VMWare Boot Screen Boot Loaders: what they do The kernel is loaded Real and Protected mode init Runlevels References I I I I The kernel then starts the first process, process 1: /sbin/init /sbin/init reads the /etc/inittab Init starts reading the script /etc/rc.d/rc.sysinit /etc/inittab tells init to do this init then executes scripts in /etc/rc.d/init.d to start services OSSI — ver. 1.3 Operating System Kernel and Booting - p. 49/56 Runlevels I A standard Linux system has 7 modes called runlevels: 0: halt (shut down the machine) 1: single user mode 2: multiuser with no network services 3: full mulituser mode 4: can be customised; default same as 3 5: multiuser with graphical login 6: reboot Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels Runlevels Directories for each runlevel Runlevel directories Example of service: yum Turning yum off Turning yum on References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 50/56 Directories for each runlevel I If you look in /etc/rc.d, you see one directory for each runlevel, and a directory called init.d: $ ls /etc/rc.d init.d rc0.d rc2.d rc1.d rc3.d rc rc4.d rc5.d rc6.d rc.local rc.sysinit Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels Runlevels Directories for each runlevel Runlevel directories Example of service: yum Turning yum off Turning yum on References I init.d contains one script for each service. You execute these scripts with the service command, i.e., $ sudo service autofs start OSSI — ver. 1.3 Operating System Kernel and Booting - p. 51/56 Runlevel directories I I I I Each of /etc/rc.d/rc[0-6].d contains symbolic links to scripts in /etc/rc.d/init.d N A symbolic link is a bit like a shortcut in Windows (but more fundamental) N We cover symbolic links in detail later If name of link begins with K, the script will stop (kill) the service If name of link begins with S, will start the service The chkconfig program creates these symbolic links Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels Runlevels Directories for each runlevel Runlevel directories Example of service: yum Turning yum off Turning yum on References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 52/56 Example of service: yum I I I In the laboratory, you set up the yum service to automatically install software updates You used the chkconfig program to enable the service. N For a complete manual on chkconfig, type: $ man chkconfig N For a brief summary of options, type: $ /sbin/chkconfig --help Here we use the program find (covered in detail later) to see the links before and after Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels Runlevels Directories for each runlevel Runlevel directories Example of service: yum Turning yum off Turning yum on References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 53/56 Turning yum Service Off I $ sudo /sbin/chkconfig yum off $ /sbin/chkconfig yum --list yum 0:off 1:off $ find /etc/rc.d -name ’*yum’ /etc/rc.d/init.d/yum /etc/rc.d/rc0.d/K01yum /etc/rc.d/rc1.d/K01yum /etc/rc.d/rc2.d/K01yum /etc/rc.d/rc3.d/K01yum /etc/rc.d/rc4.d/K01yum /etc/rc.d/rc5.d/K01yum /etc/rc.d/rc6.d/K01yum Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels Runlevels Directories for each runlevel Runlevel directories Example of service: yum Turning yum off Turning yum on References 2:off 3:off 4:off 5:off 6:off I After turning the service off, all the links start with ‘K’ in all runlevels: 0, 1, 2, 3, 4, 5 and 6. OSSI — ver. 1.3 Operating System Kernel and Booting - p. 54/56 Turning yum Service On I $ sudo /sbin/chkconfig yum on $ /sbin/chkconfig yum --list yum 0:off 1:off $ find /etc/rc.d -name ’*yum’ /etc/rc.d/init.d/yum /etc/rc.d/rc0.d/K01yum /etc/rc.d/rc1.d/K01yum /etc/rc.d/rc2.d/S50yum /etc/rc.d/rc3.d/S50yum /etc/rc.d/rc4.d/S50yum /etc/rc.d/rc5.d/S50yum /etc/rc.d/rc6.d/K01yum Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels Runlevels Directories for each runlevel Runlevel directories Example of service: yum Turning yum off Turning yum on References 2:on 3:on 4:on 5:on 6:off I Notice that after turning the service on, there are links that start with ‘S’ in runlevels 2, 3, 4 and 5. OSSI — ver. 1.3 Operating System Kernel and Booting - p. 55/56 References I I I Modern Operating Systems, Second Edition, Andrew S. Tanenbaum, Prentice Hall, 2001, Chapter 1. Good discussion of system calls. Operating Systems, Fourth Edition, William Stallings, Prentice Hall, 2001, chapter 2 particularly pp 85–91 and 98-99, chapter 4, pp 172–178 Operating Systems: A Concept Based Approach, D. M. Dhamdhere, McGraw Hill, 2002 Operating System: Kernel and boot process Role of OS System Calls Types of OS Monolithic Kernel Layered Kernel Microkernel Virtual machine Boot Process Runlevels References References OSSI — ver. 1.3 Operating System Kernel and Booting - p. 56/56