Home / Alt manpages / cfdisk(8)

  • cfdisk(8)
  • Admin command
  • linux

Safely Inspect and Edit a Disk with cfdisk

You will finish with a cautious workflow for inspecting a disk in cfdisk, making a partitioning plan in memory, and writing 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 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 requires elevated privileges. This guide assumes the device is not mounted or being used by a service.

Warning

Partition-table changes can make data inaccessible. Do not experiment with a production disk, a system disk, or a device containing the only copy of data. 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. They do not alter a disk and do not 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 hardware you intend to change.

Checkpoint: write down the exact target, for example /dev/DEVICE, and compare it with 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 learning the layout or checking a device. This is an ordinary command, although 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. Use the arrow keys to select a partition or free-space entry, and press h for the built-in help. The menu accepts the command keys directly, so pressing Enter is not normally required. Press q to leave without writing.

--read-only protects 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

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

$ sudo cfdisk /dev/DEVICE

Changes made in the interface remain in memory until you choose the write command. That gives you 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 may be omitted. A new partition is Linux type by default.

Use d to delete the selected partition, r to reduce or enlarge it, and t to change its type. Reducing a partition can destroy data, even if the new boundary looks plausible. Deleting a partition removes its table entry and turns the area into free space; it does not provide an undo button for the files that were there.

Use s if partition numbering no longer follows ascending start-sector order. Use u to dump the current in-memory table to an sfdisk-compatible script file. That script can be a useful record of the proposed layout, but it is not a backup of the data in the partitions.

4. Review before the irreversible key

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

The write command is uppercase W, unlike the other command keys. It is deliberately harder to trigger accidentally. cfdisk 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. If you type yes, cfdisk writes the partition table and asks the kernel to re-read it. This is the point of no return for the table change. It does not restore files removed by a resize or 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 that the expected partition paths and sizes are present. Do not format a new partition merely 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 another option:

$ 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 remains busy, schedule a maintenance window and reboot through your normal change process rather than improvising.

6. Handle common traps

If cfdisk opens the wrong-looking table, quit and repeat step 1. The default device is /dev/sda when no device argument is supplied, 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 repair 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, the manpage points to wipefs, which is a separate destructive operation and 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 specifically need partition-table information for the kernel.

Done means

  • You checked the cfdisk path and version and identified the whole-disk device from lsblk.
  • You inspected the existing table read-only before planning a change.
  • You have a current data backup and understand which partition entries may be affected.
  • You reviewed the in-memory layout and know that uppercase W writes it.
  • You verified the post-write partition list and handled a kernel re-read failure through a safe maintenance path.
  • You can abandon an uncertain plan with q before writing anything.