Misplaced Pages

Disk partitioning

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

This is an old revision of this page, as edited by Wzwz (talk | contribs) at 21:43, 25 January 2006 (See also). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Revision as of 21:43, 25 January 2006 by Wzwz (talk | contribs) (See also)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In computer engineering, hard disk drive partitioning is the creation of logical divisions upon a hard disk that allows one to apply operating system-specific logical formatting.

Disk partitioning is a simple technique which can be viewed as a precursor of logical volume management.

Purpose

Partitioning allows one to have multiple file systems on a single hard disk. There are many reasons to do this including:

  • Technical limitations (e.g. old versions of the Microsoft FAT filesystem that can't address more than a certain amount of hard drive space; old PC BIOSes that prevent booting operating systems located past a hard drive's 1024th cylinder)
  • If one partition becomes corrupt, only that partition suffers and not your whole hard drive.
  • On some OSes (e.g. Linux) the swap file is normally a partition of its own. When it is, systems with a dual boot configuration can make several OSes use the same swap partition and therefore save disk space.
  • To prevent overgrown log or other files from making the whole computer unusable, they are put on their own partition. Then only one partition will run out of space.
  • Often, two operating systems cannot coexist on the same partition, or use different "native" disk formats. The drive is partitioned into different logical disks for different OSes.
  • Most filesystems write files to disk in groups of fixed-size clusters whose size is directly proportional to the size of the partition the filesystem is on. If a file's size is not a multiple of the cluster size, the last cluster in the file's group of clusters will have unused space that can't be used by other files. So, filesystems that use clusters will cause files to take up more space on disk than they do in memory, and larger partitions means larger cluster sizes and therefore more wasted space. Therefore, using several small partitions instead of one large partition can save space.
  • Each partition may be customized to different requirements. For example, if you have a partition which is seldomly written to, you can mount it read-only. If you want to have very many small files, you should use a partition that has a filesystem with many inodes.
  • On multi-user systems running Unix, you may want to prevent users from doing hardlink attacks. To achieve this, the /home and /tmp directories should be separated from the system files in e.g. /var and /etc.

Implementations

Numerous partitioning schemes have appeared over the years, for almost all computer architectures in existence. Many of them are relatively transparent and allow convenient manipulation of disk partitions; some however are obsolete in design and are accompanied by numerous quirks.

IBM PC (or clone)

History

The partition table, as used in the IBM PC architecture, was first devised in 1982, when hard drives were coming into use. In 1987 with DOS 3.3, an expansion of this format emerged that provided for extended partitions which can contain logical partions.

Specifics

The partition table is located in the master boot record on the disk. The master boot record is the first sector on a disk. The partition table consists of 64 bytes. There are 4 partition table entries. Each is 16 bytes in length.

The partition table starts at offset (Hexadecimal) 0x1BE. Each partition table entry is 16 bytes in length so.

Master Boot Record
(offset)
0x0000 to 0x01BD - First 446 bytes
0x01BE to 0x01CD - Partition entry 1
0x01CE to 0x01DD - Partition entry 2
0x01DE to 0x01ED - Partition entry 3
0x01EE to 0x01FD - Partition entry 4
0x01FE to 0x01FF - Boot signature

The two byte master boot record signature at the end tells your computer that this is the boot sector. On some computers the operating system will not boot if the boot signature is not present in the master boot record.

Each partition table entry has the following arrangement...

|==========================================================|
| Byte Count | Description of contents                     |
|==========================================================|
|     1      | Boot indicator (0x00 for off, 0x80 for on)  |
|==========================================================|
|     3      | Starting head, cylinder and sector          |
|==========================================================|
|     1      | Filesystem descriptor                       |
|==========================================================|
|     3      | Ending head, cylinder and sector            |
|==========================================================|
|     4      | Starting sector (relative to disk beginning)|
|==========================================================|
|     4      | Number of sectors in partition              |
|==========================================================|

Sample partition table entry... (please also keep in mind that all bytes are in little endian)

offset: value                  explanation
======: =====                  ===========
0x01BE: 0x80                   bootable flag (0x00 for flag off, 0x80 for on)
0x01BF: 0x00 0x02 0x00         starting head, cylinder and sector
0x01C2: 0x83                   filesystem descriptor
0x01C3: 0x1A 0x5B 0x8C         ending head, cylinder and sector
0x01C6: 0x02 0x00 0x00 0x00    starting sector (relative to beginning of disk)
0x01CA: 0x00 0x35 0x0C 0x00    number of sectors in partition

CHS

The CHS (cylinder, head, sector) area of a partition table entry can be confusing. The easiest way to address these values is in binary...

CHS format:
===========
first 8 bits -> head
next 2 bits  -> first 2 bits of cylinder
next 6 bits  -> sector (remember sectors start at 1)
last 8 bits  -> last 8 bits of cylinder
Example...
00000000 00 000010 00000000 -> starting
starting head     = 0 (00000000)
starting cylinder = 0 (0000000000)
starting sector   = 2 (000010)
00011010 01 011011 10001100 -> ending
ending head     = 26  (00011010)
ending cylinder = 396 (0110001100)
ending sector   = 27  (011011)

Active partition

The Bootable Flag determines the active partition. Only one partition can normally be active at a time. The active marker is used during boot: after the BIOS loads the MBR into memory and executes it, the MBR checks the partition table at its end, and locates the active partition. Then it proceeds to load the boot sector of that partition into memory and runs it. Usually a boot loader such as GRUB or NTLDR is contained in there. Some operating systems require being installed on active partitions. For example, Microsoft Windows 2000 Professional marks its own partition active when it starts up. Thus NTLDR will run next time the system boots, even if the user intended to use another boot loader on a different partition.

Logical partitions

Logical partitions are a way to extend the Master Boot Record's limitation of four partitions. One partition can be designated as an extended partition. This can contain up to 24 logical partitions, whose details are listed in the extended partition's own partition table, the Extended MBR or EMBR. Modern operating systems treat these the same as primary partitions.

Other partitioning implementations

As the IBM PC architecture is extremely common, the partition tables are likely to stay for a while. A recent project of Intel and Microsoft developed for the IA-64 architecture (based around the Itanium or Itanium 2 CPU) called the Extensible Firmware Interface (EFI) has a component called GUID Partition Table (GPT). Microsoft has included GPT support in Windows Server 2003 SP1 and all variants of Windows x64 (which are all based of Windows Server 2003 SP1) for data disks. However GPT disks are not yet supported by the x64 and x86 architectures so GPT disks still cannot be boot disks on these platforms. Its however unlikely this project will ever replace IBM PC partitions as the Itanium processor was not received well by the market.

On January 10, 2006, Apple Computer released the new iMac and MacBook Pro computers which utilize the Extensible Firmware Interface (EFI) and GUID Partition Table (GPT) as the default format for all new Intel-based Macintosh computers.

Partitioning schemes

Microsoft Windows

With Windows the standard partitioning scheme is to create a single partition, the C: drive, where the operating system, data, and programs all reside. It is recommended, however, to create multiple partitions or use multiple hard drives with the operating system stored on one partition and with the rest of the partitions and/or drives allocated to applications and data. If possible, a separate partition for the paging file should be made, contained on a disk not including the operating system although this does mean neither disk is likely to power down. With a little bit of pre-partitioning work, it is easy to achieve a condition where the operating system is not stored on C and the C drive does not even exist. This may have the advantage that certain poorly designed viruses and trojans will not be able to overwrite key system files or take over the system. The "My Documents" folder, a "special folder" home directory, can be mounted to take up the entire free space on a separate partition.

UNIX systems

For UNIX-based and UNIX-like operating systems such as Linux, fancy partitioning creates separate partitions for /, /boot, /home, /tmp, /usr, /var, /opt and swap. This ensures that if one file system gets corrupted, the rest of the data (the other file systems) stay intact, minimizing data loss. This has the disadvantage of subdividing the drive into small, fixed-size partitions, so, for instance, a user can fill up their /home partition and run out of useable hard drive space, even though other partitions still have plenty of free space. A good implementation requires the user to predict how much space each partition will need; sometimes a difficult task. Typical desktop systems use the other convention; a "/" (root) partition containing the entire filesystem and a separate swap partition. A /home partition is useful for desktop uses as it allows a clean reinstall (or a fresh install of another Linux distribution) while leaving data intact.

List of partition utilities

See also

External links


Categories: