cfdisk - Linux
Overview
cfdisk is a Linux command used for disk partitioning. Unlike its counterpart fdisk
, cfdisk provides a user-friendly, curses-based interface to create, manage, and delete disk partitions. This tool is commonly used in system setup environments, disk management tasks, and is particularly useful during the installation of Linux distributions.
Syntax
The basic syntax for cfdisk is:
cfdisk [options] [device]
Where [device]
is the storage device (e.g., /dev/sda
) you want to partition. If no device is specified, cfdisk will attempt to use the default device.
Options/Flags
- -z, –zero: Start with zeroing out the partition table, useful for starting fresh on a new disk.
- -h, –help: Display help message and exit.
- -V, –version: Output version information and exit.
- -l, –list: List known partition types and exit.
Usage for Formatting Options
- –color [when]: Use colors or not. The
[when]
can be ‘auto’ (default), ‘never’, or ‘always’.
Examples
-
Starting cfdisk on a specific device:
cfdisk /dev/sdb
This command opens the cfdisk interface for the
/dev/sdb
device. -
Zeroing out the partition table before starting:
cfdisk -z /dev/sdb
Useful for completely wiping the partition table of the device
/dev/sdb
before starting a fresh partitioning session. -
Checking version of cfdisk:
cfdisk -V
Common Issues
- Device is busy: Make sure no partitions on the device are mounted or being used by the system.
- Permission Denied:
cfdisk
requires root privileges; run withsudo
if not running as root.
Solutions
- Use
umount
to unmount any mounted partitions. - Use
sudo cfdisk
to start the command with administrator privileges.
Integration
cfdisk can be integrated with other system commands for script-based setups or complex partition layouts. For example, after partitioning with cfdisk, one might want to format partitions with mkfs
type commands and then mount them:
cfdisk /dev/sdb
mkfs.ext4 /dev/sdb1
mount /dev/sdb1 /mnt
This allows for automated setup scripts that handle disk preparation and mounting as part of system installation processes.
Related Commands
- fdisk: Another disk partitioning tool more oriented towards script usage.
- parted: A partitioning tool that supports more disk label types.
- gparted: A graphical partition editor, useful for those who prefer a GUI.
For more detailed and device-specific information, refer to the official documentation on cfdisk
or the manual page accessible through man cfdisk
.