Jump to content

Disk partitioning

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 80.191.138.129 (talk) at 10:04, 17 October 2010 (Virtual hard disks? No way I believe that without a source...). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

GParted is a popular utility used for disk partitioning

Disk partitioning is the act of dividing a hard disk drive into multiple logical storage units referred to as partitions, to treat one physical disk drive as if it were multiple disks. Partitions are also termed "slices" for operating systems based on BSD and Solaris. A partition editor software program can be used to create, resize, delete, and manipulate these partitions on the hard disk.

Benefits of multiple partitions

Creating more than one partition has the following advantages:

  • Separation of the operating system (OS) and program files from user files. This allows image backups (or clones) to be made of only the operating system and installed software.
  • Having an area for operating system virtual memory swapping/paging.
  • Keeping frequently used programs and data near each other.
  • Having cache and log files separate from other files. These can change size dynamically and rapidly, potentially making a file system full.
  • Use of multi-boot setups, which allow users to have more than one operating system on a single computer. For example, one could install Linux, Mac OS X, Microsoft Windows or others on different partitions of the same hard disk and have a choice of booting into any compatible operating system at power-up.
  • Protecting or isolating files, to make it easier to recover a corrupted file system or operating system installation. If one partition is corrupted, none of the other file systems are affected, and the drive's data may still be salvageable. Having a separate partition for read-only data also reduces the chances of the file system on this partition becoming corrupted.
  • Raising overall computer performance on systems where smaller file systems are more efficient. For instance, large hard drives with only one NTFS file system typically have a very large sequentially accessed Master File Table (MFT) and it generally takes more time to read this MFT than the smaller MFTs of smaller partitions.
  • "Short Stroking", which aims to minimize performance-eating head repositioning delays by reducing the number of tracks used per hard drive.[1] The basic idea is that you make one partition approx. 20-25% of the total size of the drive. This partition is expected to: occupy the outer tracks of the hard drive, and offer more than double the throughput — less than half the access time. If you limit capacity with short stroking, the minimum throughput stays much closer to the maximum.
  • For example a 1 TB disk might have an access time of 12 ms at 200 IOPS (at a limited queue depth) with an average throughput of 100 MB/s. When it is partitioned to 100 GB (and the rest left unallocated) you might end up with an access time of 6 ms at 300 IOPS (with a bigger queue depth) with an average throughput of 200 MB/s..

PC partition types

This section describes the master boot record (MBR) partitioning scheme, as used in DOS, Microsoft Windows and Linux on PC compatible computer systems. For examples of partitioning schemes used in other operating systems, see GUID Partition Table, Slice (disk), or BSD disklabel.

The total data storage space of a PC hard disk can be divided into at most four primary partitions, or alternatively three primary partitions and an "extended partition". These partitions are described by 16-byte entries that constitute the Partition Table, located in the master boot record.

The partition type is identified by a 1-byte code found in its partition table entry. Some of these codes (such as 0x05 and 0x0F) may be used to indicate the presence of an extended partition. Most are used by an operating system's bootloader (that examines partition tables) to decide if a partition contains a file system that can be used to mount / access for reading or writing data.

Once a specific partition's type has been identified, additional information about its purpose and probable contents may be found (see: list of partition types). For example, some partition type codes are used to hide a partition's contents from various operating systems. However, if an OS or some partitioning tool has been programmed to also examine the boot sectors of any partition, then its file system may no longer remain hidden. (Note: There are no officially assigned partition types; thus, more than one kind of file system may lay claim to the same code value.) Additionally, partition types and boot indicators can be easily modified using applications such as MBRWizard if required.

Primary partition

A primary partition contains one file system. In DOS and earlier versions of Microsoft Windows systems, the system partition was required to be the first partition. Windows operating systems must be located in a primary partition. Other operating systems do not have this peculiar requirement. However, other factors, such as a PC's BIOS (see Boot sequence on standard PC) may also impart specific requirements as to which partition must contain the primary OS.

The partition type code for a primary partition can either correspond to a file system contained within (e.g. 0x07 means either an NTFS or an OS/2 HPFS file system) or indicate that the partition has a special use (e.g. code 0x82 usually indicates a Linux swap partition). The FAT16 and FAT32 file systems have made use of a number of partition type codes due to the limits of various DOS and Windows OS versions. Though a Linux operating system may recognize a number of different file systems (ext4, ext3, ext2, ReiserFS, etc.), they have all consistently used the same partition type code: 0x83 (Linux native file system).

Extended partition

A hard disk may contain only one extended partition; the extended partition can be subdivided into multiple logical partitions. In DOS/Windows systems, each logical partition may then be assigned an additional drive letter. Linux operating systems can be installed into (and run from) logical partitions, whereas Windows operating systems are restricted to primary partitions.

See extended boot record for information on the structure of an extended partition.

Partitioning schemes

DOS, Windows, and OS/2

With DOS, Microsoft Windows, and OS/2, a common practice is to use one primary partition for the active file system that will contain the operating system, the page/swap file, and all utilities, applications, and user data. On most Windows consumer computers, the drive letter C: is routinely assigned to this primary partition. Other partitions may exist on the hard disk that may or may not be visible as drives, such as recovery partitions or partitions with diagnostic tools or data. (Microsoft drive letters do not correspond to partitions in a one-to-one fashion, so there may be more or less drive letters than partitions.)

Proponents of multiple partitions assert that a benefit of having multiple partitions is the ability to store data files on a partition separate from one containing the system files. If the system partition then become corrupted for any reason, irreplaceable user files stored on the independent partition would be able to be more easily retrieved (or recovered), not having been corrupted along with the system files. Another operating system (loaded from a LiveCD or USB, for example) could access the files on the (presumably) uncorrupted independent data partition without having to worry about the corrupted system partition at all.

Further, when data files are kept in a separate partition, if an operating system needs to be re-installed / restored (due to malware infiltration, for example), this can be done without risking damage to the data files (that in a single-partition system are stored along with the operating system files).

Windows 2000, Windows XP, Windows Vista, and Windows 7 include an inbuilt 'Disk Management' program which allows for the creation, deletion and movement of Windows (but not other types of) partitions. The Windows 7/Vista Disk Manager is not compatible with Windows 2000 or XP, nor, for the most part, other operating systems.

Other examples of partition management programs for Windows are Acronis Disk Director, Norton Ghost, and Perfect Disk. In some instances specialized recovery programs are supplied with retail consumer computers.

Unix, Linux and Mac OS X

On Unix-based and Unix-like operating systems such as Linux and Mac OS X, it is possible to use multiple partitions on a disk device. Each partition can be used for a file system or as a swap partition.

Multiple partitions also allow directories such as /tmp, /usr, /var, or home directory space to be allocated their own file system. Such a scheme has a number of potential advantages:

  • If one file system gets corrupted, the data outside that filesystem/partition stay intact, minimizing data loss.
  • Specific file systems can be mounted read-only, or with the execution of setuid files disabled (thus enhancing security).
  • Performance may be enhanced due to less disk head travel.
  • A program which produces too much output (such as a system logging daemon) fills up only a single filesystem, therefore does not fill up more critical filesystems. (Often systems will not function correctly if / or /tmp fills up.)

However, the disadvantage of subdividing the drive into fixed-size partitions is that a file system in one partition may become full, even though other file systems still have plenty of usable space.

A good partitioning scheme requires the user to predict how much space each partition will need, which may be a difficult task; especially for new users. Logical volume management (LVM), often used in servers, increases flexibility by allowing data in volumes to expand into separate physical disks (which can be added when needed). Another option is to resize existing partitions when necessary. LVM allows this easily by resizing (shrinking) a filesystem, reducing the size of the logical volume containing that filesystem, allocating that freed space to another logical volume, and expanding (resizing) this other filesystem.

Typical Linux desktop systems use two partitions: one holding a file system mounted on "/" (the root directory) and a swap partition. (However, an almost unlimited number of partitions can be accommodated by Linux operating systems.)

By default, Mac OS X systems also use a single partition for the entire filesystem, but use a swap file inside the file system (like Windows) rather than a swap partition.

Multi-boot and mixed-boot systems

A GRUB startup menu showing Ubuntu Linux (with three different boot modes) and Windows Vista options

Multi-boot systems are computers where the user can boot into one of two or more distinct operating systems (OS) stored in separate partitions on a hard drive. In such systems, a menu at startup gives a choice of which OS to boot/start (and only one OS at a time is loaded).

This is distinct from virtual operating systems, in which one operating system is run as a self-contained virtual "program" within another already-running operating system. (An example is a Linux OS "virtual machine" running from within a Windows OS).

Multi-boot systems are typically mixed-boot systems, with different OSes installed, although multiple copies of the same OS can be installed for safety, testing, and redundancy. A mixture of Windows, Mac OSX (facilitated by the switch to the x86 processor architecture), and Linux OSs (such as Ubuntu) on the same computer can therefore be accommodated.

Multi-boot systems require multiple partitions on the hard disk. Each OS requires one or more special types of partitions whose file system may or may not be compatible with the those of other OSs on the hard disk. Tools to manipulate different types of filesystems may be specific for that type of filesystem. In general, Windows-based filesystem and partition tools have historically been used to manipulate partitions with Windows filesystems but not Linux or Mac OS X partitions. Linux-based partition managers can often (but not always) manage both Linux/Mac OS X and Windows partitions.

A particular problem of multi-boot systems is the mutual incompatibility between the bootloaders of different operating systems, which may compete with each other and independently overwrite important settings.

When most computers boot up, an MBR is referenced by the BIOS. This record indicates the partition in which the bootloader to be initially run is located. Each operating system usually attempts to change the MBR so that it points to the partition of the particular bootloader program installed by that OS. In other words, when Windows loads, it changes the MBR to point to the Windows partition in which the Windows bootloader is stored. When Mac OS X loads, it changes the MBR to point to the Mac OS X partition in which the Mac OS X bootloader is stored. When a Linux OS is loaded, it changes the MBR to point to the Linux partition in which the Linux OS bootloader (Grub) is stored.

Although all modern OSs include bootloaders that claim to be able to load other OSs as well as the primary OS, in practice this is not guaranteed. Subtle differences in file systems and ongoing changes to the various operating systems can eventually make the bootloaders of each OS unable to recognize the file systems of the competing OSs (and therefore prevent correct bootloading). One or more OSs may then appear to be "unbootable" on that computer. To rectify this, a new bootloader must be installed and configured and the MBR reset to point to the new bootloader.

A popular way to circumvent this problem is to install a small, independent "boot" partition (must be a primary partition) in which one specific bootloader is permanently stored. The MBR is then permanently set to always refer to the partition of this primary bootloader (and is never allowed to be changed or to refer to the partition of any other bootloader). This primary bootloader (in the boot partition) loads no OS directly. It merely presents a menu of operating system choices, and when one is chosen, its only function is to chainload the particular secondary bootloader of whichever OS is selected. Each secondary bootloader resides in the partition of the OS to which it belongs, and is only used to load its native OS (not any other OS). By utilizing this scheme, incompatibilities between different bootloaders, file systems and operating systems are avoided.[2]

Partition recovery

When a partition is deleted, in general, only its partition table entry is removed from a table; and although the data are no longer accessible, some still remain on the disk until being overwritten. Specialized recovery utilities, (such as TestDisk and gpart), can locate lost file systems and recreate a partition table which includes entries for these recovered file systems. However, some disk utilities may also overwrite a number of beginning sectors of a partition they delete. For example, if Windows Disk Management (Windows 2000/XP, etc.) is used to delete a partition, it will overwrite the first sector (relative sector 0) of the partition before removing it. It may be possible to restore a FAT32 or NTFS partition if a backup boot sector is available.

Compressed disks

Hard disks can be compressed to create additional space. In DOS and early Microsoft Windows, programs such as Stacker (DR-DOS except 6), SuperStor (DR-DOS 6), DoubleSpace, or DriveSpace (Windows 95) were used. This compression was done by creating a very large file on the partition, then storing the disk's data in this file. At startup, device drivers opened this file and assigned it a separate letter. Frequently, to avoid confusion, the original partition and the compressed drive had their letters swapped, so that the compressed disk is C:, and the uncompressed area (often containing system files) is given a higher name. (SuperStor required a separate device driver to be loaded, DEVSWAP.COM).

Versions of Windows using the NT kernel, including the most recent versions, XP and Vista, contain intrinsic disk compression capability. The use of separate disk compression utilities has declined sharply.

See also

References

Further reading

  • Stéphane Martineau, Jens Olsson, Nick Roberts (2002-11-02). "The Alt-OS-Development Partition Specification (AODPS)". 0.4. {{cite journal}}: Cite journal requires |journal= (help)CS1 maint: multiple names: authors list (link)
  • Andries Brouwer (1995–2004). "List of partition identifiers for PCs". {{cite journal}}: Check date values in: |date= (help); Cite journal requires |journal= (help)
  • Andries Brouwer (1999-09-16). "Minimal Partition Table Specification". {{cite journal}}: Cite journal requires |journal= (help)
  • "partitioning primer". Ranish. 1998-08-05. {{cite journal}}: Cite journal requires |journal= (help)
  • Allen Smith. "ATA (EIDE) Drive Capacity and Addressing". {{cite journal}}: Cite journal requires |journal= (help)
  • Microsoft (2005-06-03). "Using GPT Drives". {{cite journal}}: Cite journal requires |journal= (help)
  • "MS-DOS Partitioning Summary". Support. Microsoft.