Sunday, September 11, 2011

Booting

Today let's discuss about booting and what actually happens when a system boots.

During the early days of computers, the boot program is made read only and is put in hardware chips. This boot program is called a bootstrap in computer terminology. The bootstrap initiates all the CPU registers, device controllers and finally loads the operating system into memory. The advantage of this scheme is that, since the bootstrap is read only, no virus can effect it. But the disadvantages outweigh this. First, if we want to add any external hardware,  it's device driver needs to be loaded when the system starts. But, since the bootstrap is read only, we need to change the hardware chips. Also, the operating system must be in a fixed location as specified in the boot strap, if we install the operating system in a different area, then also there is a need to change the chip.


So our computer scientists thought over this and came up with a simple solution. Instead of making ROM's with complete bootstrap program in them, they started making ROM's with tiny bootstrap program's called bootstrap loader. And the main bootstrap program is stored in the disk. Since changing the bootstrap program simply requires a write to the disk, our problem is solved. The bootstrap program on the disk is generally stored in first sector of the hard disk called boot sector.

But... a new problem arrived -- Boot sector virus

Enough of computer terminology, now I will explain in simple terms. BIOS is generally present in non-volatile ROM chips as you know, and this generally initiates the main memory, CPU registers, device controllers and starts the tiny bootstrap loader that is present in it. The BIOS is built at the time of manufacture of a PC and when you start the PC, it is the first software that normally executes, even before the main memory or disk gets initialised. It looks as below


The full bootstrap program as I told earlier, is stored in first sector of harddisk called boot sector. After initialisation of all aspects, the BIOS loads this program to main memory and hands the baton to it for execution. This boot sector in windows computers is called Master Boot Record or simply MBR. MBR contains the full boot code, along with a partition table. This partition table contains the information of partitions along with information whether an Operating system is present in each one or not. If only one OS is present, it is shown or by default it's loaded since there is no need for user to make choice. If more than one OS is present, the user is presented with options to load what ever operating system he wants to be loaded.


Last, about boot sector virus. To prevent boot sector virus, there is an option in BIOS, which makes the bootstrap program on the disk read-only. When ever you think you are not going to install any more OS, check it on and when you want to change your OS, check it off. Happy now...virus problem also solved

Friday, September 9, 2011

Formatting of disk

In the previous post, we have seen that a Hard disk drive or a magnetic disk is a collection of platters covered with magnetic material which are grouped into cylinders. Today let's see how the formatting of disk is done.

Initially when the disk is manufactured in industry, it contains nothing except platters with some magnetic material on them. In the factory itself, low level format or physical format happens. First each platter is divided into sectors and appropriate data structures are written into them to enable the disk controller to read or write data. These data structures contain a header, trailer and a data area where the data is read/written. The header and trailer contain information about how to read/write data, along with a ECC(Error Correcting Code). When ever the data is first written on to the sector, from the bytes present in the blocks of sector, the ECC is calculated and updated. When another read/write happens it's ECC is recalculated and compared with the previous one. If both are different, then the ECC may give two kinds of errors in regard to the corrupted bits

1. Soft error which can be treated by correcting code
2. Hard error which cannot be treated in any way. Normally those bits are ignored and no read/write happens to them. The information about these bits need to be stored in header/trailer to make sure no disk I/O happens to them.


Now the disk is fitted into the computer system and sold to vendor, who tries to install Operating system in it. Here is the place where cylinders come into picture. First he partitions the disk, like one disk for Operating system, the other for user files and so on. Each partition is a group of one or more cylinders. These partitions are nothing but your c: drive, d: drive, e: drive etc., In the next step the Operating system needs to install file system in each of these partitions (NTFS, FAT etc.,). Installing of file systems is called Logical formatting which is similar to physical formatting except here, the data structures related to file system I/O are written into sectors.

If you are a user of Linux, you must have already encountered something like "Swap" space. The swap space is created as a partition but no logical formatting is done to it. It is entirely treated as a sequential array of logical blocks, used when ever needed. Most database systems also tend to use swap spaces since these are free from from file system related overhead.

Also the partitioned disk with a file system is called a Cooked disk and the one with out any file system is called a raw disk.

Sunday, September 4, 2011

Hard Disk Drive

Most of us have hard disks in our computers now which are used as a secondary storage devices. As you know that secondary storage devices have non-volatile memory while Primary storage devices like D-RAM have volatile memory.




Ever wondered what lies inside the plastic case of your HDD and how it works. I will show you how..



The above figure is the internal structure of a typical hard disk drive. The hard disk doesn't contain a single disk but a bulk of them which look like CD's and are called Platters. The surface of each platter is logically divided into tracks which are inturn divided into sectors. The both sides of platter are covered with magnetic material. The information is magnetically stored on these materials. There will also be read-write heads used for reading or writing data. These are attached to a disk arm, that moves all the heads as a unit. All the tracks at one arm position form a cylinder.

Transfer time is the time needed for transferring of data between the hard drive and computer. It has two parts

1. The time needed to move the disk arm to the desired cylinder called seek time and
2. The time needed for the desired sector to rotate under the read-write head called rotational latency

Did you ever come across a term called head crash. Head crach occurs when the read-write head makes contact with the disk surface actually. The read-write head just flies on a thin cushion of air above the platter. Although the platters are covered with a thin protective layer, there may be times, when the head damages the magnetic surface. Head crash is irrepairable and the disk must be replaced.