Home / Alt manpages / cfdisk(8)

  • cfdisk(8)
  • Admin command
  • linux

Safely Inspect and Edit a Disk with cfdisk

One wrong answer at cfdisk's write prompt can turn a working disk unbootable in seconds. It keeps every other change in memory until you deliberately confirm it, so this guide inspects a disk, builds a plan, and writes it only after checking the target and the recovery path.

The local manpage describes util-linux 2.39.3. On this machine, the command found first in PATH is Homebrew util-linux 2.41.3, so check the executable and version on any host where the details actually matter. Allow about fifteen minutes for inspection and a simple change, plus whatever time you need for a backup. You need a terminal and a block device you are authorised to administer. Reading a partition table is normally unprivileged only when the device permissions allow it; changing one usually needs elevated privileges. This guide assumes the device is not mounted or in use by a service.

Warning

Partition-table changes can make data inaccessible. Do not experiment with a production disk, a system disk, or a device holding the only copy of anything. Confirm the device name from more than one source before you write anything.

1. Check the executable and identify the device

Start with read-only commands. None of these alter a disk, and none need sudo:

$ command -v cfdisk
$ cfdisk --version
$ lsblk -o NAME,PATH,SIZE,TYPE,FSTYPE,MOUNTPOINTS

On the reference machine, cfdisk --version reports cfdisk from util-linux 2.41.3; your version and path may differ. The lsblk output is host-specific, so do not copy a path from this article. Choose a whole-disk path such as /dev/sdX or /dev/nvme0n1 only after matching its size and type to the actual hardware you intend to change.

Checkpoint

Write down the exact target, for example /dev/DEVICE, and compare it against the output of lsblk. A partition such as /dev/sdX1 is not the same target as the whole disk /dev/sdX.

2. Open the table without permitting writes

Use --read-only while you are still learning the layout or checking a device. This is an ordinary command, though you may need elevated access if the device cannot be opened by your user:

$ sudo cfdisk --read-only /dev/DEVICE

Replace /dev/DEVICE with the verified path. The interface is curses-based. Arrow keys select a partition or free-space entry, h opens the built-in help, and the menu accepts command keys directly, so pressing Enter is not normally required. Press q to leave without writing.

--read-only stops this invocation from writing the disk, but it is not a substitute for checking the target. Record the label type, partition sizes, free space and any mounted filesystems before planning a change. If the table is unexpectedly empty, stop: it may be the wrong device, an unsupported layout, or a damaged table.

3. Make a change only in memory

Once you have a backup and a specific plan, open the verified device normally:

$ sudo cfdisk /dev/DEVICE

Changes made in the interface stay in memory until you choose the write command. That is a review point, not permission to guess. Select free space and press n to create a partition; cfdisk prompts for a size, a suffix such as GiB uses binary units and the iB can be omitted, and a new partition is Linux type by default.

  • d deletes the selected partition, turning it into free space with no undo for the files that were there.
  • r resizes it, reducing or enlarging it; reducing can destroy data even when the new boundary looks plausible.
  • t changes its type.
  • s renumbers partitions when numbering no longer follows ascending start-sector order.
  • u dumps the current in-memory table to an sfdisk-compatible script file, useful as a record of the proposed layout but not a backup of the data inside the partitions.

4. Review before the irreversible key

Before writing, check every visible entry against your notes: start and end positions, size, type, and the partition you meant to leave untouched. If you are distracted or uncertain, press q; the manual says this exits without writing anything to the disk.

The write command is uppercase W, unlike every other command key, and that is deliberate: it is harder to trigger by accident. cfdisk then asks you to type yes or no before committing the table:

Command (press key): W
Are you sure you want to write the partition table to disk? (yes or no): no

Typing no is a safe rehearsal. Type yes and cfdisk writes the partition table and asks the kernel to re-read it.

Destructive action

This is the point of no return for the table change. It does not restore files removed by a resize, and it does not make an overwritten partition recoverable.

5. Verify the kernel's view after writing

After a confirmed write, leave cfdisk and inspect the result:

$ lsblk -o NAME,PATH,SIZE,TYPE,FSTYPE,MOUNTPOINTS /dev/DEVICE
$ sudo blkid /dev/DEVICE

Compare the new partition list with the plan. Exact lsblk output varies by device and filesystem, so the useful result is simply that the expected partition paths and sizes are present. Do not format a new partition just because it appears in the list; formatting is a separate, destructive operation.

Sometimes the kernel cannot re-read a changed table because partitions are in use. cfdisk documents partprobe and partx as ways to inform the kernel, with a reboot as the fallback:

$ sudo partprobe /dev/DEVICE
$ lsblk -o NAME,PATH,SIZE,TYPE,MOUNTPOINTS /dev/DEVICE

Do not force a reload over mounted or active partitions. Stop the relevant service and unmount only when you understand the operational impact. If the machine stays busy, schedule a maintenance window and reboot through your normal change process rather than improvising.

6. Handle common traps

If cfdisk opens a table that looks wrong, quit and repeat step 1. The default device is /dev/sda when no device argument is given, which is a good reason to always name the target explicitly. If the command cannot open the device, check the path and permissions first: adding sudo cannot fix a misspelled device.

Do not use --zero as a way to clear a disk. It starts cfdisk with an in-memory zeroed table and does not zero the on-disk table, but writing that blank table can still destroy the existing partition layout. For removing an old partition table properly, the manpage points to wipefs, which is a separate destructive operation outside this basic workflow.

cfdisk supports MBR, GPT, SUN and SGI labels in the documented util-linux 2.39.3 interface. It no longer provides CHS addressing or a print command. Use lsblk for a readable inventory and partx when you need partition-table information specifically for the kernel.

Done means

  • Executable and device checked. You confirmed the cfdisk path and version and identified the whole-disk device from lsblk.
  • Table inspected read-only. You looked at the existing table before planning any change.
  • Backup in hand. You have a current data backup and know which partition entries may be affected.
  • Plan reviewed. You checked the in-memory layout and know uppercase W is what actually writes it.
  • Result verified. You checked the post-write partition list and handled any kernel re-read failure through a safe maintenance path.
  • Escape route kept. You can abandon an uncertain plan with q before writing anything.