fdisk
fdisk is a dialog-driven command-line utility primarily used in Unix-like operating systems, including Linux, to create, manipulate, and manage disk partition tables on block devices such as hard disk drives.[1] It supports multiple partition table formats, including the modern GUID Partition Table (GPT), the traditional Master Boot Record (MBR or DOS-type), as well as Sun, SGI, and BSD types, allowing for flexible partitioning schemes like up to four primary partitions in MBR or unlimited partitions (typically 128) in GPT.[1] By default, it aligns partitions to optimize performance on devices with 4K sectors and records changes in the device's sector 0 upon explicit saving.[1] Originally developed in the early 1980s by Andries E. Brouwer and others as part of early Unix tools, fdisk has evolved into a core component of the util-linux package and is included by default in most Linux distributions for system administration tasks.[2][1] Its interactive interface enables users to list existing partitions (via the-l option), add new ones (e.g., primary or logical), delete partitions, and modify attributes like sizes and types, though it does not handle filesystem formatting—that requires separate tools like mkfs.[2][1] Changes are held in memory until the user commits them with the w command, providing a safeguard against errors during disk operations.[2]
While a similar utility named FDISK exists in MS-DOS and early Windows versions for basic partitioning and master boot record management, the Unix/Linux fdisk differs significantly, offering advanced support for contemporary storage standards and device naming conventions like /dev/sda1.[3] Current maintenance of the Linux fdisk, part of util-linux version 2.41 (as of November 2025), is handled by developers including Karel Zak, ensuring compatibility with evolving hardware like SSDs and large-capacity drives.[1][4]
Overview
Purpose and Functionality
fdisk is a command-line utility designed for reporting and editing disk partition tables on block devices such as hard disk drives.[1] Implementations exist across various operating systems, with the Unix-like version (as in Linux) supporting multiple partition table formats including the Master Boot Record (MBR), GUID Partition Table (GPT), Sun, SGI, and BSD types, while DOS and Windows use an analogous tool called FDISK primarily for MBR.[1][3] This enables system administrators and users to view the layout of existing partitions on a disk device, facilitating efficient management of storage resources in Unix-like systems and similar environments. The core functionalities of fdisk revolve around creating, deleting, and modifying partitions without altering the underlying data. It supports the creation of primary partitions (up to four per disk in MBR), extended partitions to extend this limit through logical partitions, and the assignment of partition types to indicate intended file systems such as FAT, NTFS, or ext.[1] By interacting directly with the partition table located in the first sector(s) of the disk, fdisk defines critical parameters including partition boundaries (start and end sectors), sizes, and types, ensuring the operating system can recognize and access the divided storage areas.[1] Notably, fdisk operates solely on the partition table and does not perform formatting or install file systems, leaving those tasks to separate utilities like mkfs or format.[1] Key limitations of fdisk stem from the partitioning scheme employed; for the MBR scheme, it restricts disks to a maximum of four primary partitions unless extended partitions are used for additional logical ones, and early implementations relied on cylinder-head-sector (CHS) addressing that could lead to inaccuracies on larger drives.[1] While traditional versions of fdisk were limited to MBR, modern Unix-like implementations such as Linux fdisk (part of util-linux since version 2.26 as of 2015) support GPT, which overcomes MBR constraints for larger disks (beyond 2 TiB) and more partitions (typically up to 128).[1][5]Key Concepts
Disk partitioning involves dividing a physical storage disk into multiple logical sections known as partitions, allowing separate areas for different operating systems, file systems, or data storage purposes. This organization enables efficient management of disk space and supports multiboot configurations by isolating data and system files.[6] In the Master Boot Record (MBR) scheme, partitions are categorized as primary, extended, or logical. Primary partitions, limited to four per disk, are the main divisions and can be marked as bootable to load an operating system. An extended partition acts as a container to overcome the four-partition limit, housing logical partitions as subdivisions within it. Logical partitions provide additional flexibility for organizing data without directly counting toward the primary limit.[7] The MBR, located in the first sector of the disk, consists of boot code in the initial 446 bytes, followed by a 64-byte partition table and a 2-byte boot signature. The partition table holds up to four 16-byte entries, each describing a partition's boot status, starting and ending positions, type code, and size. For instance, the type code 0x07 indicates an NTFS file system partition.[7][8]| Offset | Size (bytes) | Field Description |
|---|---|---|
| 0x00 | 1 | Boot indicator (0x00 non-bootable, 0x80 bootable) |
| 0x01 | 1 | Starting head |
| 0x02 | 1 | Starting sector and cylinder (lower 6 bits sector, upper 2 bits high cylinder) |
| 0x03 | 1 | Starting cylinder (lower 8 bits) |
| 0x04 | 1 | Partition type code (e.g., 0x07 for NTFS) |
| 0x05 | 1 | Ending head |
| 0x06 | 1 | Ending sector and cylinder (lower 6 bits sector, upper 2 bits high cylinder) |
| 0x07 | 1 | Ending cylinder (lower 8 bits) |
| 0x08 | 4 | Starting sector (LBA, relative to disk start) |
| 0x0C | 4 | Number of sectors in partition |
History
Origins in DOS
Thefdisk utility was introduced in March 1983 alongside IBM PC DOS 2.0 (also known as PC DOS 2.0), marking the first disk partitioning tool designed for hard disks on IBM PC compatibles.[11][12] Developed jointly by Microsoft and IBM, it enabled users to prepare fixed disks for DOS file storage, coinciding with the IBM PC/XT model's launch as the first PC to include a hard drive as standard.[13][14] Initially, fdisk supported the FAT12 file system and provided basic operations for creating and deleting primary partitions, relying on Cylinder-Head-Sector (CHS) addressing to define partition boundaries within the 10 MB limit of early hard drives.[15][16]
In August 1984, PC DOS 3.0 updated fdisk to add support for the FAT16 file system, allowing partitions up to 32 MB on larger disks while maintaining backward compatibility with FAT12 volumes.[14] This enhancement addressed the growing capacity of hard drives, though early implementations had limitations in interoperability with later DOS versions for larger volumes. The command's syntax included options like FDISK /STATUS for displaying current partition information without entering the interactive menu.[17][18]
By 1987, enhancements in MS-DOS 3.31—particularly in the Compaq variant—introduced extended partitions to overcome the four-partition limit of the Master Boot Record (MBR) and the FAT16B variant, which supported partitions over 32 MB through larger cluster sizes.[19][20] These features, integrated into fdisk, allowed for more flexible disk organization on drives up to 504 MB.[21] As hard disk drives became ubiquitous in PCs during the mid-1980s, fdisk established itself as the standard tool for partitioning, enabling bootable hard disk setups that supplanted floppy-only booting.[11] It was included in all subsequent releases of MS-DOS, PC DOS, and DR-DOS, with later ports emerging for Unix-like systems.[14]
Adoption and Evolution in Unix-like Systems
The fdisk utility, originally developed for DOS environments, was adapted for Unix-like systems beginning with its implementation for the Mach operating system kernel, where it was written by Robert Baron to manage disk partitions in a Unix-compatible manner.[22] This version introduced a command-line interface suitable for Unix-style operations, emphasizing interactive editing of partition tables. Subsequently, Julian Elischer ported fdisk to 386BSD around the time of that system's 1992 release, enabling partition management on early PC-based BSD variants and laying groundwork for broader adoption in free Unix-like distributions.[22] These early ports focused on compatibility with Master Boot Record (MBR) schemes inherited from DOS, while adapting the tool to Unix conventions like non-interactive scripting and integration with kernel disk drivers. In Linux, fdisk was integrated into the util-linux package, with initial development contributions from Andries E. Brouwer and A. V. Le Blanc dating to 1992–1993, providing essential MBR-only partitioning support for the emerging kernel.[1] The tool evolved through community maintenance, addressing limitations such as the 2 TB addressable limit of MBR partitions by incorporating detection for alternative schemes. A significant milestone came in 2007 with util-linux version 2.13, where maintainer Karel Zak enhanced fdisk with GPT detection and improved probing via libblkid for more accurate disk geometry and filesystem identification, though full GPT editing support arrived later in version 2.23 (2014).[23] These updates improved portability across large-capacity drives but retained MBR focus for legacy compatibility. The OpenBSD project undertook a complete rewrite of fdisk in 1997 by Tobias Weingartner, prioritizing security hardening, code portability, and robustness against malformed inputs to align with the system's emphasis on proactive auditing. This version influenced subsequent adaptations in NetBSD and FreeBSD, which adopted similar interactive and non-interactive modes for MBR and extended partition handling. Apple incorporated a fork of this OpenBSD-derived fdisk into Darwin (the core of macOS) starting around 2002, retaining it for legacy MBR editing on Intel-based systems while prioritizing GUID Partition Table (GPT) for native volumes. Over time, fdisk's role in modern Unix-like systems has shifted toward compatibility maintenance, as the 2 TB MBR limitation prompted widespread adoption of GPT for larger disks; tools like parted or gdisk are now recommended for new setups, but fdisk persists for editing legacy MBR partitions and hybrid schemes.[24] This evolution reflects broader trends in Unix-like storage management, balancing backward compatibility with support for exabyte-scale addressing in GPT.[25]Usage
Command Syntax and Options
Thefdisk command is typically invoked using the syntax fdisk [options] [device], where device specifies the target disk, such as /dev/sda on Linux systems, and omitting certain options causes the program to enter interactive mode by default for partition manipulation.[1] If no device is provided, fdisk lists available devices or prompts for one.[1]
Several key options enable non-interactive usage without entering the full dialog: the -l or --list option displays the partition table for the specified device(s) and exits immediately, useful for querying disk layout; -s or --getsz outputs the size of a partition in 512-byte sectors (though this is deprecated in favor of blockdev); -u or --units[=unit] controls display units, defaulting to sectors but allowing cylinders for legacy compatibility; and -v or --version prints version details and exits.[1] These options are common across Unix-like implementations for basic querying tasks.[26]
Non-interactive scripting is supported by piping commands to fdisk via standard input, simulating interactive prompts to delete, create, or set partition types with parameters like start and end sectors; for instance, sequences such as echo -e "d\n1\nw" | fdisk /dev/sda can delete the first partition non-interactively.[2] This approach allows batch operations but requires precise knowledge of prompt responses, and for more robust scripting, the companion sfdisk tool extends these capabilities with explicit flags like --delete, --new, and --type.[27]
The utility performs error handling by issuing warnings for invalid inputs, such as attempts to create overlapping partitions or specify sectors beyond the disk's capacity, and it conducts consistency checks on partition tables in DOS compatibility mode to prevent corruption.[1] Options may vary slightly between implementations—for example, additional flags in BSD variants—but the core command-line syntax remains POSIX-like and standardized in Unix-like systems since the 1990s, ensuring broad portability. This non-interactive mode provides a bridge to full interactive operations for advanced partitioning.
Interactive Operations
When invoked without scripting options, fdisk enters an interactive, menu-driven mode that allows users to manage disk partitions through a series of prompts.[1] For example, runningfdisk /dev/sda on a Unix-like system launches the interface and displays a command prompt such as "Command (m for help):".[1] This mode is designed for manual operation, guiding users through tasks like creating or modifying partitions on the specified device.[26]
Core commands in the interactive interface include p to print the current partition table, n to add a new partition, d to delete an existing partition by number, t to change a partition's type (such as setting code 83 for a Linux filesystem), w to write the modified table to disk and exit, and q to quit without saving changes.[1] In Unix-like implementations, these are single-letter commands entered at the prompt, while DOS and Windows versions use a numbered menu for selections, such as option 1 to create a primary partition or option 4 to display information.[21] Resizing a partition typically involves deleting it with d (or the equivalent menu option) and recreating it with adjusted parameters using n.[1]
A common workflow for creating a primary partition begins by entering n at the prompt, followed by p to select primary, 1 for the first slot, accepting the default start sector by pressing Enter, and specifying the end with a size like +10G for 10 gigabytes.[26] The user can then verify the layout with p, optionally set the type using t (e.g., t then 1 then 83), and commit changes with w.[1] For scripting preferences, fdisk supports non-interactive mode via command-line options to automate these steps without entering the menu.[1]
Safety features in interactive mode buffer all modifications in memory until w is explicitly issued, preventing accidental overwrites; selecting q discards any unsaved changes.[1] Users are encouraged to use p repeatedly for verification before writing, as the tool issues warnings about potential data loss or existing signatures on the disk.[1]
Implementations
DOS and Compatible Systems
In MS-DOS and compatible systems, the fdisk utility operates as a menu-driven program invoked via the command line with an optional drive letter specifier, such asFDISK C:, to target a specific fixed disk.[21] Upon execution, it presents a primary menu with five numbered options: 1 for creating a DOS partition or logical drive, 2 for setting the active partition, 3 for deleting a partition or logical drive, 4 for displaying partition information, and 5 for selecting the current fixed disk drive when multiple drives are present.[28] Internally, fdisk numbers drives starting from 1 rather than using letters, reserving A: and B: for floppy drives and assigning C: to the primary partition on the first hard drive.[29] This implementation supports partitioning up to a 2 TB limit per disk, constrained by the 32-bit Logical Block Addressing (LBA) scheme in the Master Boot Record (MBR) format, which addresses a maximum of 2^32 sectors at 512 bytes each.[24][30]
Fdisk in DOS environments handles File Allocation Table (FAT) filesystem variants through predefined partition type codes, assigning hexadecimal identifiers such as 01 for FAT12, 04 or 06 for FAT16 (depending on size), and 0B or 0C for FAT32 with LBA support.[31] When creating a primary DOS partition, fdisk automatically configures the partition table entry to enable boot sector setup, marking it as active if selected and preparing it for subsequent formatting with tools like FORMAT.COM to write the appropriate FAT boot sector.[32] This process ensures compatibility with DOS's native filesystems, though it requires manual intervention for extended partitions containing logical drives.
Compatible systems like FreeDOS provide an open-source fdisk implementation that extends DOS functionality, including full support for FAT32 partitions added in its early development around 1998 to align with emerging large-drive needs.[33][34] Similarly, DR-DOS variants enhance fdisk with features such as improved multi-boot configuration options, allowing better handling of dual-OS setups through refined partition activation and boot sector management in its user guide-documented utilities.[35]
Key limitations include the absence of GUID Partition Table (GPT) support, as DOS fdisk exclusively uses the MBR scheme for compatibility with legacy BIOS environments.[36] Early versions prior to 1994 relied solely on Cylinder-Head-Sector (CHS) addressing, lacking LBA extensions that were introduced later to handle larger drives.[37] In MS-DOS 6.x releases, fdisk often misreports or ignores space beyond approximately 8 GB on larger drives due to BIOS translation limitations and incomplete INT13h extensions, capping visible capacity at around 8.4 GB unless patched.[38][39]
Despite these constraints, DOS fdisk remains in use within bootable DOS environments for maintaining legacy hardware, such as in embedded systems or retro computing setups requiring MBR partitioning without modern OS dependencies.[40][41] The last major update to the core fdisk utility occurred with Windows 98 in 1998, incorporating FAT32 awareness and large-drive fixes up to the 137 GB barrier via subsequent hotfixes.[42][43]
Linux
In Linux, the fdisk utility is distributed as part of the util-linux package, a collection of system tools maintained by the Linux kernel community since its inception in the early 1990s.[4] The current implementation, as of util-linux version 2.41.2 released in 2025, supports both Master Boot Record (MBR) and GUID Partition Table (GPT) partition tables, with MBR allowing up to four primary partitions and extended partitions containing logical ones, while GPT supports up to 128 partitions by default, while operating on block devices such as /dev/sda or /dev/sdb.[44][1] A significant rewrite occurred in 2006, when the util-linux project was forked as util-linux-ng by developers Karel Zak and Davidlohr Bueso, leading to improved modularity and the introduction of the libfdisk library for handling partition tables.[45] This library enables scripting capabilities, allowing fdisk to integrate with automated tools for non-interactive partitioning. Complementing fdisk, the sfdisk utility serves as a companion for batch operations, such as dumping or restoring partition tables in a scriptable format. Recent enhancements include color-coded output for warnings and table elements, introduced in util-linux 2.24 and refined in subsequent versions for better readability in terminals.[46][1] The 2006 rewrite laid the groundwork for better disk handling, with util-linux 2.26 (released in 2015) making sector-based sizing the default, replacing legacy cylinder-head-sector (CHS) calculations to improve accuracy on modern hardware. This change, building on sector size distinctions added in version 2.17, enables reliable support for large disks up to the MBR limit of 2 TB using 512-byte sectors or much larger with GPT. Key options include -c for compatibility modes (such as DOS CHS emulation via -c=dos), and the ability to display or specify sizes in bytes for precise control, alongside DOS-compatible mode to ensure interoperability with Windows systems by aligning partitions to traditional boundaries.[5][1][2] As of 2025, fdisk remains actively maintained within util-linux 2.41.2, with ongoing updates for stability and integration. It is suitable for both MBR and GPT partitioning, though specialized tools like gdisk offer advanced features for GPT setups. The tool is commonly embedded in installation environments, such as the Debian installer, where it facilitates initial disk setup through interactive prompts like 'n' for new partitions.[44][47]BSD and macOS Derivatives
The fdisk utility in BSD systems traces its origins to a port from the Mach Operating System to 386BSD in the early 1990s.[48][49] This implementation was adapted for use in FreeBSD and NetBSD, where it primarily handles editing of Master Boot Record (MBR) partition tables on disk devices.[48][49] In OpenBSD, fdisk maintains a minimalist design focused on essential partition table management, supporting both MBR and GUID Partition Table (GPT) formats while prioritizing secure operations such as bounds checking during edits.[50] Common features across BSD variants include the-f option to force geometry detection or load from a configuration file, and -u to update the existing slice table interactively without data loss.[48] In FreeBSD, fdisk interacts with the GEOM modular disk transformation framework, which can generate benign warnings during operations; these are suppressed using the -q flag to ensure clean output.[48] However, fdisk in FreeBSD lacks native GPT support and is recommended to be used alongside gpart(8) for modern GPT-based partitioning.[48][51]
The macOS implementation of fdisk, inherited from its BSD roots, is located at /usr/sbin/fdisk and extends support to the Apple Partition Map (APM) format via the -A flag, allowing manipulation of legacy partitioning schemes alongside MBR.[52] It remains available for compatibility with DOS and Windows bootloaders on hybrid setups, even as APFS has become the default file system since macOS 10.13, rendering traditional fdisk operations legacy for native macOS volumes.[52][53]