cfdisk

disk managementlinux
The cfdisk command is one of the most frequently used commands in Linux/Unix-like operating systems. cfdisk Display or manipulate a disk partition table with a curses interface

Quick Reference

Command Name:

cfdisk

Category:

disk management

Platform:

linux

Basic Usage:

cfdisk [options] [arguments]

Common Use Cases

  • 1

    Disk partitioning

    Create and modify disk partitions interactively

  • 2

    System installation

    Prepare disks for operating system installation

  • 3

    Storage management

    Manage disk space allocation and partition layout

  • 4

    Dual boot setup

    Configure partitions for multiple operating systems

Syntax

cfdisk [options] [device]

Options

Option Description
-h, --help Display help text and exit
-V, --version Display version information and exit
-L, --color[=when] Colorize output (auto, always, or never)
-r, --read-only Open device in read-only mode
-s, --sector-size size Specify sector size of the device
-z, --zero Start with an empty partition table
--label type Specify the partition table type (dos, gpt, etc.)

Examples

How to Use These Examples

The examples below show common ways to use the cfdisk command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

Basic Examples:

Launch cfdisk for the first disk
cfdisk /dev/sda
Start cfdisk for a specific device with partition table display
cfdisk /dev/nvme0n1
Launch in read-only mode (safe for inspection)
cfdisk -r /dev/sdb
Display device size in bytes rather than units
cfdisk -s /dev/sdc

Advanced Examples:

Force creation of a new DOS partition table
cfdisk --zero /dev/sdd
Use a specific disk label type (e.g., gpt)
cfdisk -z --label gpt /dev/sde
Start with a specific device size
cfdisk --sector-size 4096 /dev/sdf
Create a logical volume partition table
cfdisk /dev/mapper/vg-lv
Use colorization for better readability
TERM=linux cfdisk --color=always /dev/sda

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Key Features:

cfdisk is a curses-based disk partition editor with the following capabilities:

  • Interactive, menu-driven interface for disk partitioning
  • Support for various partition table types including DOS (MBR) and GPT
  • Ability to create, delete, resize, and modify partitions
  • Change partition types for different filesystems and operating systems
  • Toggle bootable flags for OS booting
  • Display detailed information about partitions and disks

Interface Navigation:

  • Arrow keys: Navigate between partitions and options
  • Tab: Move between the partition list and the command menu
  • Enter: Select an operation or confirm changes
  • q: Quit the program (you'll be prompted to write changes)

Common Operations:

  • New: Create a new partition in free space
  • Delete: Remove a selected partition
  • Type: Change the partition type/filesystem
  • Bootable: Toggle the bootable flag (for MBR)
  • Resize: Change partition size (if available)
  • Write: Save changes to disk (this is permanent!)
  • Quit: Exit without saving changes

Important Notes:

  • Changes are not written to disk until you explicitly select the Write command
  • Always backup important data before modifying partition tables
  • Running cfdisk with root privileges is required to make changes
  • Partitions that are currently mounted cannot be modified
  • After writing changes, you may need to run 'partprobe' to make the kernel aware of the changes
  • For new partitions, you'll need to create filesystems (e.g., with mkfs) after creating the partition

Alternatives:

  • fdisk: Command-line based, more script-friendly
  • parted: More advanced features like partition resizing
  • gdisk: GPT-focused partitioning tool
  • gparted: Graphical partition editor with similar capabilities

Common Use Cases

Disk partitioning

Create and modify disk partitions interactively

System installation

Prepare disks for operating system installation

Storage management

Manage disk space allocation and partition layout

Dual boot setup

Configure partitions for multiple operating systems

Storage optimization

Optimize disk layout for performance and organization

Related Commands

These commands are frequently used alongside cfdisk or serve similar purposes:

Use Cases

1

Disk partitioning

Create and modify disk partitions interactively

2

System installation

Prepare disks for operating system installation

3

Storage management

Manage disk space allocation and partition layout

4

Dual boot setup

Configure partitions for multiple operating systems

5

Storage optimization

Optimize disk layout for performance and organization

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the cfdisk command works in different scenarios.

$ cfdisk
View All Commands