LinuxCommandLibrary

fdisk

Manage disk partitions

TLDR

List partitions

$ sudo fdisk [[-l|--list]]
copy

Start the partition manipulator
$ sudo fdisk [/dev/sdX]
copy

Once partitioning a disk, create a partition
$ <n>
copy

Once partitioning a disk, select a partition to delete
$ <d>
copy

Once partitioning a disk, view the partition table
$ <p>
copy

Once partitioning a disk, write the changes made
$ <w>
copy

Once partitioning a disk, discard the changes made
$ <q>
copy

Once partitioning a disk, open a help menu
$ <m>
copy

SYNOPSIS

fdisk [options] device

PARAMETERS

-b sectorsize
    Specify the sector size (usually 512). Rarely needed.

-c
    Disable DOS-compatible mode. Needed for large drives with older systems.

-l
    List the partition tables for the specified devices and then exit.

-o offset
    Start at offset bytes.

-s device
    Display the size of device in blocks.

-u sectors
    When listing partitions, give sizes in sectors instead of cylinders.

-v
    Display version information.

device
    The device to be partitioned (e.g., /dev/sda, /dev/nvme0n1).

DESCRIPTION

The fdisk command is a powerful and widely used utility for creating, modifying, and deleting partitions on a hard drive or other storage device. It allows users to manage the partition table, which dictates how the storage space is organized and accessible by the operating system.

fdisk supports various partitioning schemes, including the older Master Boot Record (MBR) and the newer GUID Partition Table (GPT). The specific options and behaviors of fdisk can vary slightly depending on the partitioning scheme in use. Common operations include creating new partitions, deleting existing partitions, changing partition types (e.g., making a partition bootable), and viewing partition information.

Improper use of fdisk can lead to data loss, so it's crucial to understand the command's options and implications before making any changes. It's generally recommended to back up important data before using fdisk to modify partitions.

CAVEATS

Using fdisk incorrectly can lead to data loss. Always back up important data before making any changes to partition tables. Be especially careful when modifying partitions on a system disk that contains the operating system.

INTERACTIVE MODE

fdisk typically operates in an interactive mode. After specifying the device, you enter a command prompt where you can enter single-character commands to create, delete, or modify partitions. Type 'm' to view the available commands.

PARTITION TYPES

When creating partitions, fdisk requires you to specify a partition type code. These codes define the intended use of the partition (e.g., Linux filesystem, swap space). A list of available codes is available in the interactive mode.

MBR VS. GPT

Older systems use MBR which has a 2TB limit and can only contain 4 primary partitions. Newer systems use GPT which doesn't have these limitations. fdisk can use both schemes. gdisk is the GPT variant from the fdisk family.

HISTORY

fdisk has been a fundamental disk partitioning tool in Unix-like operating systems for decades. It originally supported the MBR partitioning scheme and has been updated to support GPT. Its development has focused on providing a command-line interface for managing disk partitions, making it a core tool for system administrators and advanced users.

SEE ALSO

parted(8), gdisk(8), sfdisk(8), mkfs(8), mount(8)

Copied to clipboard