Bootstrapping Process

April 25, 2009 at 9:35 PM (Technical Articles)

Hi friends, Today I am discussing something about an operating system. Now a days a small kid also knows how to work with computers. Computers have become a part of our life. Hmmm every one knows computers, mainly we CS students know how it works, how it takes care of users, how it takes care of hardware so many things we know. Wait wait am I right? I think not! I think if I say an Operating system takes care of all these things then my words are more correct isn’t it? Yes without an operating system computer is just a  hardware device, we can say a waste box. It is something like human body  without brain.

OK today i am not going to discuss how exactly Operating system works, how it takes care of hardware and all. I want to discuss a small part of theory in operating system. Then you might be thinking that, I might discuss memory management, process management, security, kernel etc  right?  Not at all !!! I want to discuss the first step taken by your computer as soon as you start it. Ya of course its Booting process.

Before going for Boot process, let me discuss why i have chosen this topic. As  I said long before in my first blog, i love operating systems. One day i was thinking about processes, how a process will run, who will allocate memory for a process? (Ya OS only), how it loads content of a .exe file into RAM, so many stuffs. But the ultimate answer for this is an Operating System. An OS will take care of this, of course we have read it in our Operating System subject.

But one interesting question is, an OS will load an Application’s file into the    RAM (i.e Execution), but “before getting your desktop who will load your OS into the RAM?”. Because OS is nothing but a set of  programs, some one should load that program into RAM, so then you get a nice glassy look which is our desktop. But who will do all these stuffs? Then i started searching regarding this.

Ha there is something called as boot loader, which is again a program that takes care of loading an OS into the RAM. That process we call it as Booting process.Then how this Booting process takes place? What are the difficulties it should cross? These are the topics that i would like to  cover in this blog post.

( Hi I just remind you that we had read something about Bootstrap loaders in System software subject when we were in 5th sem BE, is it 5th sem? hope I am right. So you can go through that also.)

Booting Process.

Definition: The process of loading an OS into RAM ( Primary memory) is called Booting process.

When you install an Operating System into your system (Windows is taken as an example in this blog, so when i say an OS, its nothing but Windows) it loads Operating System files into the specified drive in your hard disk, most of the time it is “C” drive, hmmm in my system now it is  “F” drive. So every time when you start your system, operating system should load into RAM. That is taken care by Boot loader. OK now question arises that which of the OS file is loaded into RAM at the first time?  Somewhere in Internet i got it  CONFIG.SYS file in windows . So your boot loader loads this file into RAM, and hence boot loader is the one which takes care of booting your OS. Then where this  boot loader located? How it works to make Booting process successful? keep on reading.

Boot Loader.

Boot loader is the program usually written in assembly language. The boot loader is located in boot sector of your hard disk. Then what is this boot sector?. As we all know that our hard disk is partitioned into drives, and each drive internally again divided as clusters, each cluster is divided as sectors. So it is something like a site divided as different houses, each house internally is divided into several rooms. And each house has an entrance right? That we call it as entrance room. In the same way your hard disk has a sector called boot sector which is the first sector of the disk. In this boot sector boot loader is stored.

Why the first sector? (I am not sure about this, I searched lot but didn’t get exact reason. Here what I assume.)

As I said boot loader has to load OS into RAM, but boot loader is itself a program and that should be executed first right? So they have made something called boot sector a very first sector, and BIOS is the one which loads this boot loader into RAM, since BIOS is the program that is burnt into ROM it can’t have sophisticated technique so that it can search Boot loader in your hard disk and then load it into RAM. If it is the first sector without any difficulties BIOS can point to loader. So loader is stored in boot sector.

The boot sector is very small amount of memory of size 512KB, this code is loaded onto RAM at the physical address 0000:7C00. Then the BIOS examines the final two bytes of the boot loader which should be 0xAA55h a hexadecimal value , which is called as signature(Boot signature). The signature tells that boot loader is valid one. If BIOS finds this signature then only it loads boot loader otherwise it displays an error message like System Boot Failure. Since Boot sector is of very limited size, the boot loader should be very optimized and should not take more than 512KB . Developer should take care of the size of the boot loader program.

Before loading loader into RAM, BIOS does POST(Power On Self Test) operation (http://en.wikipedia.org/wiki/Power-on_self-test). Once the POST operations are successful then it locates the boot sector then it loads loader into RAM.

How BIOS Loads Loader?

See we started from Operating system, then we pointed Boot loader and now BOIS, cool guys now we are into the deep…

Bios first looks for drive A, (if you have not set any boot device) if any disk is present in drive A, it looks for boot loader in that disk (because of that only when you put floppy into drive your OS won’t boot sometimes). If it does not find any disk in drive A, then it looks for drive C from your hard disk. There  it finds actual loader and loads it.

Once the loader is loaded,  the control is transferred to Loader. The Loader executes and loads operating system files into RAM, so that OS booting will start.

This is very limited explanation given here, my intention was just let you to know what happens before you get your desktop? If you are really interested in operating systems then you will get huge amount of details in internet, you can go through such sites. Studying an OS in this way is really a fun. You will enjoy it, I enjoyed lot.

Ok as i previously said CONFIG.SYS is the first operating system file that is loaded into RAM, but before that a file called IO.SYS is loaded which knows how to communicate with BIOS. IO.SYS has a program called SYSINIT, then  it loads rest of the operating system.

CONFIG.SYS tells which specific Operating system files to be loaded further. And accordingly it loads device drivers and all. There  is one more file called WIN.INI (for Windows , AUTOEXE.BAT for DOS) this WIN.INI tells which applications to run along with boot. After doing this stuff the Operating system waits for first user interaction. Later we all work with Computers. We do what comes in our mind, either its correct or wrong, everything is taken care by OS.

Ok here are some links that gives you an idea on different boot loaders, one of the popular boot loader is GRUB. Everyone heard about this, mainly while installing Linux

(http://en.wikipedia.org/wiki/Comparison_of_boot_loaders)

Boot loader has access to BIOS Interrupts, there are some interrupts routines that boot loader initially calls for set up. INT 0x10 – is for Screen output, INT 0x16- for keyboard input, and here are list of BIOS interrupts :

http://en.wikipedia.org/wiki/BIOS_interrupt_call). These interrupts work in real mode ( I dont know what is real mode of the processor). These interrupt routines are used by most of the boot loaders. This link might give you an idea about real mode of processors :

http://en.wikipedia.org/wiki/Real_mode.

I think the topic is bit confusing, it played around OS, boot loader, BIOS so many stuffs and usually reader will get confused, and he/she will not come to know that which one comes first and which one does what? so here i am giving summary which will explain everything in brief.

Summary:

As soon as you start your computer, BIOS takes the first step. It does the following tasks.

1> Perform POST (Power On Self Test) operations.

2> Selects appropriate boot device. it selects one among these, drive A, Drive C or CDROM.

3> Loads the boot sector onto RAM.

BIOS is self executable and it is burnt in ROM.

Next once BIOS loads boot loader into RAM, boot loader will execute and communicates with BIOS, it makes use of BIOS interrupts and it loads operating system files into RAM. Initially IO.SYS file is loaded, which knows how to communicate with BIOS. Then CONFIG.SYS is loaded, which knows further steps in loading the OS.

After this you will get clear, glassy desktop.

Ok then i hope you all enjoyed the booting process and I hope you will observe booting process next time while booting your system.

If you have any doubts then you can ask me through mail steggi.cs@gmail.com

Permalink 3 Comments