Total Pageviews

Sunday, August 30, 2015

Preparing a disk for use

Before a disk can be used by a computer it must undergo three separate processes. It is only the last of these (high level formatting) which creates the file system specific to an operating system  e.g. the FAT 16 or FAT 32 systems used by Windows and MSDOS or the NTFS file system used by Windows XP.
  1. Low level formatting
  2. Partitioning
  3. High level formatting (Creation of a file system)
  4. What a disk looks like after it has been fully prepared

Hard Disk Mechanics

Throughout this lesson you may find the following diagram of the internal workings of a hard disk useful:

Low level formatting

Hard disks are laid out in blocks.
the number of blocks on a disk is calculated by the formula
heads X sectors X tracks.
Each block will usually hold 512 bytes of information.
The laying out of this track and sector information together with finding and marking any bad areas of the disk is called low level formatting. This will be done at the factory before the disk is sold.
If we review the image below from our earlier lesson. The low level format is that time at which the tacks and sectors are laid out:


Partitioning

Before a disk can be used by a computer a partition table must be created on the disk. This tells the computers BIOS whether the disk should be used as a single disk of whether it should be split into two or more logical disks. The partition table also tells the BIOS which part of the disk an operation system boot sector can be found on.
New disks have to be partitioned manually before they can be used. The most common tool used to partition disks is an MSDOS utility called FDISK.
Because there are restrictions that are placed on some file system types, in particular. the maximum size of FAT16 partitions is 2.1Gigabytes, the FDISK program will only create partitions of up to 2.1 Gigabytes if FAT16 file systems are to be used, even though the file system itself is not laid out at this point. When the program starts, FDISK will ask if large partitions are required, if you answer 'Y' to this then the partitions will be created and marked to be used for FAT32 file systems, and the size restriction will not be applied.
All hard drives can hold up to 4 partitions these partitions are described is a simple textual table which is called the partition table. This partition table is held in the Master Boot Area of a hard drive (usually sector 0, track 0 side 0). This table will contain up to 4 entries (1 for each partition). Only 1 of the four partitions can be marked as active. Only the active partition can be used to load an operating system. While up to 4 partitions can be used it is more usual for a disk to contain only 1 or 2 partitions with the other partitions just being left empty.
A partition table for a 14578 sector disk will  could something like this:
Partition Number Active (Y/N) Start Sector End Sector Partition Type
1 Y 1 12002 PRIMARY DOS
2 N 12003 14577 EXTENDED DOS
3        
4        
Windows Operating systems support only two kinds of partition, PRIMARY DOS and EXTENDED DOS. Primary DOS partitions hold individual file systems and are used to load operating systems (such as Windows XP). Extended Dos partitions are used to hold up top three logical drives. These logical drives each can hold their own file system and act as if they are "mini partitions". Extended partitions and logical drives cannot be made active and cannot be used to load and operating system. Only primary DOS partitions can be made active/bootable.

Formatting

Sometimes called high level formatting. Formatting a disk lays out a file system. The file system format selected  will make a disk usable by any operating system the supports the file system being used. MSDOS and WINDOW 9X  and Windows XP all  use what are called File Allocation Table (FAT) file systems. There are two types of FAT systems FAT 16 and FAT32 each of which will have benefits under different circumstances. Windows XP, however, works best with NTFS, which has some similarities to the internal working of FAT file systems, but has a more advanced structure (dynamic linked list) for allocating clusters and which also allows for additional file attributes, properties and security.
A completed file system

File allocation tables file systems 

FAT systems group together the blocks of a disk into work units called clusters. Each cluster will be a group of one or more disk blocks. As each block will be 512 bytes, the capacity of the cluster will be 512 X the number of blocks per cluster.
The cluster is the basic unit of storage. Each file stored on a FAT formatted disk will take up at least one cluster. No two files can ever be stored in the same cluster.
This means that a FAT disk which is using 30 blocks per cluster will have clusters that take up 15 Kilobytes of disk space. Any file stored on this disk will therefore take up at least 15K no matter how small the file is. If a FAT disk is using 60 blocks per cluster then the cluster will take up 30K and each file on this disk will use up 30K of disk space no matter how small the file is. This means that the more blocks per cluster  that are used, the more space small files take up.
The result of this is that is that is the contents of a 90% full one gigabytes disk is copied on to a two gigabyte disk, the new disk will often end up 60 - 70 % full!
Because of this problem there are currently two FAT file-system types FAT 16 and FAT 32.
Pretty much all file systems use some derivative of the FAT system. The two main tables employed by all operating systems are:
1) The Free list, which keeps track of all the clusters and which has a Boolean flag indicating which of the clusters are currently in use and which are available for storage of new material.
2) The File Allocation Table (FAT) The file allocation table is like a directory structure which keeps track of the names and Cluster used to store each file. Basic FAT system keep only the name of the first cluster used to store a file. The first cluster must, therefore,  be read through to its end where a "continued at" pointer will point to the next cluster used. More advanced file systems, such as NTFS, use more advanced FAT tables, which allow the OS to keep tack of all clusters used by a file so that the file can be directly accessed at any point, without the need to read though all prior clusters first. This makes it easier to allocate new file store contiguously and helps prevent problems such as file cluster fragmentation. File cluster fragmentation is where the clusters used to store a file are stored in non continuous clusters. This results in much slower file access. Fragmentation a far bigger problem on older FAT file systems than it is when NTFS is used.

FAT 16

FAT 16 file systems use a 16 bit number to index the file allocation table. The largest 16 bit number is 65536. This means that a FAT 16 disk can have no more than 65536 clusters, no mater how big the disk is. Bigger disks simply use more blocks per cluster. This means that very often bigger disks will not hold that much more than smaller disks because each file, no matter how small will be using more space. The maximum size of a windows 95 FAT16 disk has been restricted to 2.1 Gigabytes because of this problem.

FAT 32 

FAT 32 disks use 32 bit numbers to index their file allocation table. This means that fewer blocks per cluster can be used. This means that small files will take up much less space. Large file will however load slightly slower as they will be split into more clusters as each cluster will hold less information.

Benefits of FAT 16 vs. FAT 32

FAT 16 disk can be used by a wide range of operating systems, e.g. Windows NT, Linux , Windows 95, MSDOS etc. FAT 32 can only be used by Windows 98, Windows 2000 and some service releases of Windows 95.
FAT 32 disks can be larger the 2.1 Gigabytes. FAT 16 disks must be smaller than 2.1 Gigabytes (or 3.5 Gigabytes if used with Windows NT)
Small files take up less room on FAT 32 disks. FAT 32 disks can therefore hold more information.
Large files tend to load slightly faster from FAT 16 disks than FAT 32 disks.
FDISK can create up to four partitions per disks. This means that the largest disk that can be used with FAT16 is 8.4G (4 X 2.1 G). To use disk larger than this FAT32 must be used.

What a disk looks like after it has been fully prepared

After it has been prepared a hard disk can be thought of as a logical list of blocks/sectors. The Master boot record (MBR) will be in the Master Boot Area (MBA) which is usually sector 0, side 0 track 0.
The MBR consists of the partition table+ a bootstrap program.
The bootstrap program is normally placed in the MBR when a disk is formatted or an operating system is installed, the bootstrap program is loaded and run by the BIOS when the computer starts up. The bootstrap program will be specific to a version of an operating system (OS). The bootstrap program will, therefore, look for the specific kernel and user interface files for its OS (within the active partition). When the kernel and user interface files are found they are loaded into memory in order to complete the boot process.
In the case of some more modern operating systems, such as Windows XP, the bootstrap program will look for and load a more complex boot loader rather than an operating system (e.g., ntloader.sys). When this new boot-loader had been loaded into memory the user can be given the option of loading (booting) a range of kernels for any partition, active or not. In this case the partition used to load the bootstrap program is usually referred to as the system partition or system disk. and the partition used to load the selected OS Kernel is usually referred to as the Boot Partition or boot disk.
Consider the following diagram which represents a representative 21 sector (10.5K Hard Disk).

If we assume a working file system with a bootable operating system has been install then this diagram shows the following:
Area A is the MBA which contains the MBR. The MBR is the partition table + the Bootstrap program
Area B contains the file system tables  (The Free list and the File allocation table)
Area C, (which is all the clusters from 1 through 4) is used to store files. The total storage space on this 10.5K disk is therefore only 8K (clusters 1 through 4). This area is used to hold all files including the operating system kernel and user interface files.

No comments:

Post a Comment