Disk Drive Concepts

Disk Drive Concepts

When you read about disk drives, you run into some terms and concepts unique to the world of hard disks. The following sections explain some of these concepts.

The physical organization of the disk is expressed in terms of cylinders, heads, and sectors. A hard disk consists of several platters of magnetic material. In physical terms, you can think of cylinder, head, and sector as follows:

• A cylinder is a set of matching tracks on both sides of all the platters in the disk drive, where each track is one of a series of concentric rings on one side of a disk platter.

• The total number of heads is the number of sides of all the magnetic platters.

• A sector is a pie-shaped wedge on the platter. Each cylinder is divided into sectors.

Any location on the disk can be expressed in terms of the cylinder, the head, and the sector. Identifying a disk location in terms of cylinder (C), head (H), and sector (S) is known as CHS addressing.

The physical geometry of a hard disk usually is expressed in terms of cylinders, heads, and sectors (CHS). A disk may have a geometry of CHS = 8,894/15/63, which means that the disk has 8,894 cylinders, 15 heads, and 63 sectors. Usually, each sector can store 512 bytes (or half a kilobyte) of data. Thus, the capacity of this disk is (8,894x15x63)=2 kilobytes, or 4,202,415 kilobytes (about 4,103MB).

 Note PC hard disk controllers include a read-only memory (ROM) basic input/output system (BIOS) on the controller. By convention (and for compatibility with the original IBM PC architecture), the BIOS uses CHS addressing to access the hard disk. The disk BIOS, however, uses a 10-bit value as the cylinder address. Because 10 bits can hold numbers between 0 and 1,023, the BIOS can address, at most, 1,024 cylinders. Nowadays, the BIOS supports what are called Int 13h (that's interrupt number 13 in hexadecimal) extensions that use logical block address to get around the 1,024 cylinder limitation.

Many large disks have more than 1,024 cylinders. To accommodate the 1,024-cylinder limit, the disk controllers as well as newer BIOS use what is known as logical block address (LBA) to handle disks with more than 1,024 cylinders.

Instead of thinking of in terms of cylinder, head, and sector-CHS addresses-for each block, the idea behind LBA is to address each 512-byte block sequentially and not think of any artificial limit on the number of cylinders. In fact, with LBA, you do not have to think of a physical cylinder, head, sector model for the hard disk; a disk can simply be some storage medium organized into same-size blocks and the blocks are numbered sequentially.

Master Boot Record (MBR)

The first sector of the hard disk (cylinder 0, head 0, sector 1) is called the master boot record (MBR). This 512-byte storage area contains important information about the disk, such as the partition table, and a small amount of code that the PC's BIOS loads and runs when you boot the PC.

The small program in the MBR reads the partition table; determines which partition is active (that's just an attribute of a partition), reads the active partition's first sector, or boot sector, and runs whatever program resides in that boot sector. The program in a partition's boot sector usually loads whatever operating system is installed on that partition.

When you install a boot loader such as GRUB on the hard disk, the GRUB program resides on the hard disk's MBR or the boot sector of the partition on which the Linux root directory (/) is located.

Partitions

Partitions are a way of dividing up a hard disk and treating each part separately. By dividing your PC's hard disk into partitions, you can install different operating systems in different partitions. Even if you use the entire disk for Linux, you need, at minimum, a partition Linux can use as swap space-an extension of memory, so that you can have more virtual memory than the physical memory on your system. The Red Hat Linux installer creates three partitions: a swap partition, a small (100MB) partition for /boot file system that holds the Linux kernel files, and the remaining disk space is assigned to a large partition that holds the main Linux file system (/).

Although you can set up a Linux system with a swap paritition and a single large partition for the entire Linux file system, there are circumstances in which you may want to place specific parts of the file system in their own partitions to limit their growth or for performance reasons. When you place a file system such as /var in a partition by itself, that file system cannot grow beyond the physical size of the partition and fill up the entire file system.

In practice, most production Linux installations use quite a few partitions. Here's a typical example of the file systems that could be placed in their own disk partitions:

• swap-Used as virtual memory (typically twice the amount of physical memory or at least 64MB)

• /-Is the root file system and provides the mount points for all other file systems. When there are no other partitions, the root partition also holds the entire Linux file system.

• /boot-A primary partition to hold the Linux kernel files (typically around 100MB). In cases where the BIOS can only access the first 1,024 cylinders, you can place this small /boot partition within the first 1,024 cylinders (this constraint does not affect new PCs that access disks using logical block address).

• /var-Contains the spool directories for mail and print scheduler as well as error logs. The Web server and anonymous FTP directories are also in /var. You could place this in its own partition to ensure that the entire file system does not get filled up by too many error messages (in case something goes wrong).

• /usr-Contains most executable files (binaries)

• /tmp-Holds temporary files for many programs. Any process and any user can write to this directory, so it is wise to keep /tmp in a different partition than /.

• /home-Contains the home directories of the users. Placing /home in a separate partition ensures that users do not inadvertently fill up the whole file system and bring the system down.

 Insider Insight The master boot record contains the partition table, starting at byte number 446 (or 0x1be, which means 1be in hexadecimal). The partition table can have up to four 16-byte entries at bytes 446, 462, 478, 494, respectively, followed by a signature in the two bytes with offset 510 and 511. The signature has the hexadecimal value 0x55 in byte 510 and 0xaa in byte 511. Each 16-byte value in the partition table defines a partition. Each partition is specified by a starting and ending cylinder number. The partition entry also includes a type that identifies the operating system that creates the partition. The concept of partitions is a convention that all PC-based operating systems, ranging from MS-DOS to Linux, follow.

In MS-DOS, you use the FDISK program to manipulate the partitions. In Windows XP/2000, use the DISKPART program (located in the \WINDOWS\SYSTEM32 directory) to work with disk partitions. Linux includes a program with the same name-fdisk (lowercase)-to alter the disk partitions. In addition to fdisk, Linux includes another disk-partitioning program called sfdisk.

The partitions described in the partition table in the MBR are the primary partitions. Because there is room for only four entries, there can be at most four primary partitions on a hard disk. However, a primary partition can be marked as an extended partition and then the first sector of that extended partition will contain another partition table that subdivides the extended partition. The partitions in the extended primary partition are called logical partitions.

Linux Device Names for Disks

In Linux, each device is represented by a device file in the /dev directory. The device name for the hard disk depends on the type of disk controller. For IDE and EIDE drives, the device name is /dev/hda for the first disk, /dev/hdb for the second disk, and so on.

On an EIDE interface, if you have a hard disk on the primary interface and a CD-ROM drive as the first device on the secondary interface, the device names are /dev/hda for the hard disk drive and /dev/hdc for the CD-ROM drive.

The Linux disk drivers treat each disk partition as a separate device. The first primary partition in the first IDE disk is /dev/hda1, the second partition is /dev/hda2, the third one is /dev/hda3, and so on. The first logical partition is /dev/hda5, the second one /dev/hda6, and so on. Similarly, the device names for the partitions on the second IDE drive are /dev/hdb1, /dev/hdb2, and so on.

The SCSI disk devices are named /dev/sda, /dev/sdb, and so on. If a SCSI device is a hard disk, its partitions are named by appending the partition number to the device name. Thus, the partitions of the first SCSI hard disk are named /dev/sda1, /dev/sda2, /dev/sda3, and so on.

 BackCover
 Red Hat Linux 9 Professional Secrets
 Introduction
 Part I: Setting Up Red Hat Linux
 Part II: Exploring Red Hat Linux
 Part III: Internetworking with Red Hat Linux
 Part IV: Managing Red Hat Linux
 Part V: Programming Red Hat Linux
 List of Figures
 List of Tables
 List of Code Examples
 List of Sidebars