it2204: systems administration i 8b).booting (supplementary notes)

42
IT2204: Systems Administration I 8b).Booting (Supplementar y Notes)

Upload: clarissa-conley

Post on 16-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

IT2204: Systems

Administration I

8b).Booting(Supplementa

ry Notes)

Page 2: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

Derived From Ubuntu Unleased, Chapter 14:

The Boot Process

2

Page 3: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

A sneak pick into the booting process

• After you turn on the power switch, the boot process begins with the computer executing code stored in a chip called the BIOS (Basic Input Output System); this process occurs no matter what operating system you have installed.

• The Linux boot process begins when the code known as the boot loader starts loading the Linux kernel and ends only when the login prompt appears. 3

Page 4: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

• Although most people consider a computer to be either on or off, in Ubuntu and Linux in general, there are a number of states in between. Known as runlevels, they define what system services are started upon boot.

• These services are simply applications running in the background that provide some needed function to your system, such as getting information from your mouse and sending it to the display; or a service could monitor the partitions to see whether they have enough free space left on them. Services are typically loaded and run (also referred to as being started) during the boot process

4

Page 5: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

Beginning the Boot Loading Process

• The BIOS (basic input/output system) is an application stored in a chip on the motherboard that initializes the hardware on the motherboard (and often the hardware that’s attached to the motherboard). The BIOS gets the system ready to load and run the software that we recognize as the operating system.

• As a last step, the BIOS code looks for a special program known as the boot loader or boot code. The instructions in this little bit of code tell the BIOS where the Linux kernel is located, how it should be loaded into memory, and how it should be started. 5

Page 6: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

• If all goes well, the BIOS looks for a bootable volume such as a floppy disk, CD-ROM, hard drive, RAM disk, USB drive, or other media. The bootable volume contains a special hexadecimal value written to the volume by the boot loader application.

• The BIOS searches volumes in the order established by the BIOS settings (for example, USB first, followed by a DVD-ROM, and then a hard drive) and then boots from the first bootable volume it finds. Modern BIOSs allow considerable flexibility in choosing the device used for booting the system.

6

Page 7: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

Note:

• If the BIOS detects a hardware problem, the boot process fails, and the BIOS generates a few beeps from the system speaker. These “beep codes” indicate the nature of the problem the BIOS has encountered.

• The codes vary among manufacturers. If you encounter a problem, troubleshoot, consult the motherboard manual or contact the manufacturer of the motherboard. 7

Page 8: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

• Next, the BIOS looks on the bootable volume for boot code in the partition boot sector also known as the Master Boot Record (MBR) of the first hard disk. The MBR contains the boot loader code and the partition table—think of it like an index for a book, plus a few comments on how to start reading the book.

• If the BIOS finds a boot loader, it loads the boot loader code into memory. At that point, the BIOSs job is completed, and it passes control of the system to the boot loader.

• The boot loader locates the Linux kernel on the disk and loads it into memory. After that task is completed, the boot loader passes control of the system to the Linux kernel.

8

Page 9: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

Loading the Linux Kernel

• In a general sense, the kernel manages the system resources. As the user, you do not often interact with the kernel, but instead you interact with the applications that you are using.

• Linux refers to each application as a process, and the kernel assigns each process a number called a process ID (PID). Traditionally, the Linux kernel loads and runs a process named init, which is also known as the “ancestor of all processes” because it starts every subsequent process. Ubuntu has replaced init with Upstart, which is being written by Ubuntu developers and made available for any distribution to use.

9

Page 10: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

• This next step of the boot process traditionally begins with a message that the Linux kernel is loading, and a series of messages that are printed to the screen, giving you the status of each command. A failure should display an error message.

• The quiet option may be passed to the kernel at boot time to suppress many of these messages.

10

Page 11: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

• Ubuntu does not display these messages by default, but instead uses a boot process created by the Fedora/Red Hat developers called Plymouth that is fast and incorporates a beautiful boot screen.

• If the boot process were halted at this point, the system would just sit idle and the screen would be blank. To make the system useful for users, we need to start the system services. Those services are some of the applications that allow us to interact with the system.

11

Page 12: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

System Services and Runlevels

• The init command traditionally boots a Linux system to a specific system state, commonly referred to as its runlevel.

• Runlevels determine which of the many available system services are started, as well as in which order they start. A special runlevel is used to stop the system, and a special runlevel is used for system maintenance. There are other runlevels for special purposes.

• You traditionally use runlevels to manage the system services running on a Linux computer. All these special files and scripts are set up during installation but you can change and control them manually. 12

Page 13: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

Runlevel Definitions• The runlevels are defined in a traditional Linux

system in /etc/init.d.• Each runlevel tells the init command what services to

start or stop. Although runlevels might all have custom definitions, Ubuntu has adopted some standards for runlevels:

• Runlevel 0—Known as “halt,” this runlevel is used to shut down the system.

• Runlevel 1—This is a special runlevel, defined as “single,” which boots Ubuntu to a root access shell prompt where only the root user may log in. It has networking and multi-user access turned off. This is the maintenance or rescue mode. It allows the system administrator to perform work on the system, make backups, or repair configuration or other files.

13

Page 14: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

• (Runlevel 1 (also known as single-user mode or maintenance mode) is most commonly used to repair file systems and change the root password on a system when the password has been forgotten. Trespassers with physical access to the machine can also use runlevel 1 to access your system.)

• Runlevel 2—This is the default runlevel for Ubuntu.

• Runlevels 3–5—These runlevels aren’t used in Ubuntu but are often used in other Linux distributions.

• Runlevel 6—This runlevel is used to reboot the system.

14

Page 15: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

Booting into the Default Runlevel

• Ubuntu boots into runlevel 2 by default, which means it starts the system as normal and leaves you inside the X Window System looking at the graphical login prompt. It knows what runlevel 2 needs to load by looking in the rc*.d directories in /etc. Ubuntu contains directories for rc0.d through to rc5.d and rcS.d.

• Assuming that the value is 1, the rc script then executes all the scripts under the /etc/rc.1 directory and then launches the graphical login.

15

Page 16: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

Booting into the Default Runlevel

• If Ubuntu is booted to runlevel 1, for example, scripts beginning with the letter K followed by scripts beginning with the letter S under the /etc/rc1.d directory are then executed:

• matthew@seymour:~$ ls /etc/rc1.d/• K10jackd K20rsync K20vboxdrv K80cups

S70pppd-dns• System service scripts that reside in the

/etc/init.d directory.

16

Page 17: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

• The rc1.d links are prefaced with a letter and number, such as K15 or S10. The K or S in these prefixes indicate whether a particular service should be killed (K) or started (S) and pass a value of stop or start to the appropriate /etc/init.d script.

• The number in the prefix executes the specific /etc/init.d script in a particular order. The symlinks have numbers to delineate the order in which they are started.

• Nothing is sacred about a specific number, but some services need to be running before others are started.

17

Page 18: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

Final Stage of Initialization

• Each /etc/init.d script, or init script, contains logic that determines what to do when receiving a start or stop value. The logic might be a simple switch statement for execution.

• After all the system scripts have been run, your system is configured and all the necessary system services have been started. If you are using a runlevel other than 5, the final act of the init process is to launch the user shell—bash, tcsh, zsh, or any of the many command shells available. The shell launches, and you see a login prompt on the screen.

18

Page 19: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

•Other notes that may be helpful

19

Page 20: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

20

Why is Booting Required ?

• Hardware doesn’t know where the operating system resides and how to load it.

• Need a special program to do this job – Bootstrap loader. – E.g. BIOS – Boot Input Output System.

• Bootstrap loader locates the kernel, loads it into main memory and starts its execution.

• In some systems, a simple bootstrap loader fetches a more complex boot program from disk, which in turn loads the kernel.

Page 21: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

21

How Boot process occurs ?

• Reset event on CPU (power up, reboot) causes instruction register to be loaded with a predefined memory location. It contains a jump instruction that transfers execution to the location of Bootstrap program.

• This program is in form of ROM, since RAM is in unknown state at system startup. ROM is convenient as it needs no initialization and can’t be affected by virus.

Page 22: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

22

BIOS Interaction

Page 23: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

23

Tasks performed at boot up• Run diagnostics to determine the state of

machine. If diagnostics pass, booting continues.

• Runs a Power-On Self Test (POST) to check the devices that the computer will rely on, are functioning.

• BIOS goes through a preconfigured list of devices until it finds one that is bootable. If it finds no such device, an error is given and the boot process stops.

• Initializes CPU registers, device controllers and contents of the main memory. After this, it loads the OS.

Page 24: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

24

BIOS Setup

Page 25: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

25

Boot Procedure

Page 26: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

26

Tasks performed at boot up (Contd)

• On finding a bootable device, the BIOS loads and executes its boot sector. In the case of a hard drive, this is referred to as the master boot record (MBR) and is often not OS specific.

• The MBR code checks the partition table for an active partition. If one is found, the MBR code loads that partition's boot sector and executes it.

• The boot sector is often operating system specific, however in most operating systems its main function is to load and execute a kernel, which continues startup.

Page 27: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

27

Secondary Boot Loaders

• If there is no active partition or the active partition's boot sector is invalid, the MBR may load a secondary boot loader and pass control to it and this secondary boot loader will select a partition (often via user input) and load its boot sector.

• Examples of secondary boot loaders– GRUB – GRand Unified Bootloader– LILO – LInux LOader– NTLDR – NT Loader

Page 28: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

28

GRUB Loader

Page 29: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

29

Booting and ROM

• System such as cellular phones, PDAs and game consoles stores entire OS on ROM. Done only for small OS, simple supporting hardware, and rugged operation.

• Changing bootstrap code would require changing ROM chips. – EPROM – Erasable Programmable ROM.

• Code execution in ROM is slower. Copied to RAM for faster execution.

Page 30: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

30

Example : DOS

• After identifying the location of boot files, BIOS looks at the first sector (512 bytes) and copies information to specific location in RAM (7C00H) - Boot Record.

• Control passes from BIOS to a program residing in the boot record.

• Boot record loads the initial system file into RAM. For DOS, it is IO.SYS .

• The initial file, IO.SYS includes a file called SYSINIT which loads the remaining OS into the RAM.

• SYSINIT loads a system file MSDOS.SYS that knows how to work with BIOS.

Page 31: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

31

Example : DOS

• One of the first OS files that is loaded is the system configuration file, CONFIG.SYS in case of DOS. Information in the configuration file tells loading program which OS files need to be loaded (e.g. drivers)

• Another special file that is loaded is one which tells what specific applications or commands user wants to be performed as part of booting process. In DOS, it is AUTOEXEC.BAT. In Windows, it’s WIN.INI .

Page 32: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

32

References

• Operating System Principles – Silberchatz, Galvin and Gagne.

Page 33: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

33

Questions• What is the effect on boot sector and boot loader

when you install two OSs, for e.g. Windows and Linux in two separate partitions ?

• Suppose, you install Windows first. The default boot loader installed in MBR is NTLDR and contains information regarding the active partition of Windows. When you install Linux on this system, the installation prompts to overwrite a new secondary boot loader which identifies both Windows and Linux active partitions and therefore we get a choice of booting the desired OS when the system is started.

Page 34: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

34

Questions Cont’d

In contrast, if Linux is installed first and then Windows, the Windows Installer overwrites the MBR with its own boot loader which doesn’t recognize the Linux active partition. This creates a problem.

The problem can be corrected by using a LiveCD or any bootable disc which can be used to reinstall a secondary boot loader which identifies both the OSs and gives true choice.

Page 35: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

35

Questions

• If I have only a single OS, is there a secondary boot loader present on the system ?

• Older machines might not have this feature. But now-a-days, even Windows is installed with a default secondary boot loader (NTLDR). Linux is also installed usually with LILO or GRUB as the default boot loader.You might have also encountered that your system (Windows) is not able to boot after flashing the BIOS and is displaying the message “NTLDR missing”. This is because the primary boot loader transfer to NTLDR which might have become corrupt or deleted by mistake.

Page 36: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

36

Questions

• Difference between Boot Loader and Boot Manager ?

• Basically, these two are different but are sometimes combined into a single program.

• IBM's Boot Manager, PowerQuest's BootMagic and V Communications' System Commander are some examples of boot managers.

• Dual booting is the act of installing multiple operating systems on a computer, and being able to choose which one to boot when switching on the computer. The program, which makes dual booting possible is called a boot loader.

Page 37: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

37

Information

• Dual Boot• In the OS/2 world, the term dual boot has a

more specific meaning.• In a dual boot installation, two (or more)

operating systems are installed in a single partition. Selection of which operating system to boot is performed by running a dual boot utility program, which switches around the necessary boot loaders programs (by renaming files and copying boot sectors) to ensure that the chosen operating system is loaded at the next boot.

Page 38: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

38

Information

• In a boot manager installation, by contrast, the two (or more) operating systems are installed in their own, separate, individual, partitions. Rather than booting directly into an operating system, the machine boots into a specialised, operating system neutral, boot loader program (such as IBM's eponymous Boot Manager) installed on a floppy disk or in its own partition on a hard disk.

• This boot loader program presents a list of the available bootable partitions from which the user can choose, and then loads and invokes the boot loader in the boot sector of the chosen partition, to boot the chosen operating system.

Page 39: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

39

Information

• When installing an OS on a computer from scratch, here is how the partition table is created.

• The hard disk is denoted as “hda” where hd=hard disk, and the third letter could mean the hard-disk on the system. For e.g. the first hard disk is “hda”, the second is “hdb”.

• When the partitioning is done, “hda0” is the place of MBR. “hda1” is the primary partition. Then a secondary partition may be created which is further subdivided into logical drives. Another OS could be installed on any of these logical drives.

Page 40: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

hda0 – MBRhda1 – Primary Partition e.g. Windows XPhda2 – Secondary Partitionhda3 – Logical Drive 1 (FAT32 or NTFS partition)hda4 – Logical Drive 2 (FAT32 or NTFS partition)hda5 – Logical Drive 3 (Swap for Linux Partition)hda6 – Logical Drive 4 (Root for Linux Partition)

The above example is a simple example. Specific cases can be different.

40

Page 41: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

41

Information• When the kernel is being loaded, the control is

in the privileged mode. If the user is allowed to login in the same mode, any user will be “root” or “administrator” (super-user).

• When the booting is almost complete, which is with the privileged right. But this login program, after verifying your password, gives you a shell by creating another process which intentionally drops the super-user privileges and assume the privileges of this user. Login program is trusted by the kernel. If that is hacked or replaced, you can get a root shell from any login.

Page 42: IT2204: Systems Administration I 8b).Booting (Supplementary Notes)

Q & A