LinuxCommandLibrary

cfdisk

Partition a disk

TLDR

Start the partition manipulator with a specific device

$ cfdisk [/dev/sdX]
copy

Create a new partition table for a specific device and manage it
$ cfdisk [[-z|--zero]] [/dev/sdX]
copy

SYNOPSIS

cfdisk [options] device

PARAMETERS

-h, --help
    Displays a help message and exits the program.

-V, --version
    Outputs version information and exits.

-Z, --zero
    Fills the partition table with zeros, effectively destroying all existing partition information. Use with extreme caution as this will lead to data loss.

-L, --color[=WHEN]
    Colorizes the output. WHEN can be 'always', 'auto', or 'never'.

-t, --type TYPE
    Specifies the partition table type to use (e.g., 'dos' for MBR, 'gpt' for GUID Partition Table, 'sgi', 'sun', 'mac', 'bsd').

-s, --specify DISK_SIZE
    Specifies the disk size in bytes. Useful for loop devices or when the size cannot be automatically detected.

DESCRIPTION

cfdisk is a powerful utility used for manipulating disk partition tables in a user-friendly, menu-driven interface. Unlike its command-line counterpart fdisk, cfdisk leverages the
curses library to provide a visual, interactive experience, making partition management more intuitive for many users.

It allows system administrators and users to create, delete, resize, and modify partitions on block devices (like hard drives or SSDs). cfdisk primarily supports MBR (DOS) and GPT (GUID Partition Table) partitioning schemes, automatically detecting the existing type or allowing the user to specify it. Changes made within cfdisk are not written to the disk immediately; they are staged and only applied when the user explicitly chooses the 'Write' option, providing a safety net against accidental modifications.

While cfdisk excels at managing partition table entries, it does not format partitions or manage file systems directly. Users must use separate tools like mkfs to create file systems after partitioning and resize2fs (for extN file systems) if they need to resize existing file systems. Access to cfdisk requires root privileges due to its direct interaction with disk devices.

CAVEATS

Using cfdisk incorrectly can lead to severe data loss. Always back up important data before making any changes to disk partitions.

Changes are committed to disk only when you explicitly select the 'Write' option from the interactive menu. Until then, changes are temporary and in-memory.

cfdisk operates on raw disk devices, not individual partitions. Ensure that any partitions on the target device are unmounted before proceeding.

While cfdisk can create/delete/resize partition table entries, it does not manage file systems. Resizing a partition often requires separate file system utilities (e.g., resize2fs) to adjust the file system to the new partition size. Failure to do so can lead to data corruption or inaccessible partitions.

INTERACTIVE INTERFACE

Upon launching cfdisk with a device (e.g., cfdisk /dev/sda), it presents a full-screen, menu-driven interface. Users navigate using arrow keys (Up/Down for partitions, Left/Right for menu options) and press Enter to select. Common actions include:

New: Create a new partition.
Delete: Remove an existing partition.
Resize: Change the size of a partition.
Type: Change the partition type ID.
Bootable: Toggle the bootable flag for MBR partitions.
Write: Commit all pending changes to the disk (critical step!).
Quit: Exit cfdisk without saving changes (if 'Write' wasn't used).

The interface provides immediate visual feedback on partition layout and available disk space.

PARTITION TABLE SUPPORT

cfdisk primarily supports two widely used partition table types:

MBR (Master Boot Record) / DOS: The older, traditional partitioning scheme, commonly used on disks up to 2TB. It supports up to four primary partitions, or three primary and one extended partition containing logical partitions.

GPT (GUID Partition Table): A newer, more robust partitioning scheme, designed for larger disks (beyond 2TB) and supporting virtually unlimited partitions. GPT is increasingly common on modern systems.

cfdisk usually auto-detects the partition table type, but the --type option allows explicit selection.

HISTORY

cfdisk is part of the util-linux project, a collection of essential system utilities for Linux. It was developed as a more user-friendly alternative to the traditional fdisk command, specifically designed to leverage the ncurses library for an interactive, pseudo-graphical interface. This approach made partition management less prone to syntax errors and more accessible to users. Its development has focused on providing a stable and robust tool for fundamental disk partitioning tasks across various Linux distributions.

SEE ALSO

fdisk(8), parted(8), gdisk(8), mkfs(8), resize2fs(8), lsblk(8), mount(8)

Copied to clipboard