fdisk(8)
fdisk is a command-line utility for creating, deleting, and managing disk partitions on Linux systems.
Synopsis
fdisk [OPTION]... DEVICEDescription
fdisk is a partition table manipulator that allows you to view, create, delete, and modify partitions on hard drives and other block devices. It supports both MBR (Master Boot Record) and GPT partition tables, though modern systems often prefer gdisk or parted for GPT disks.
Always back up your data before using fdisk, as incorrect partition changes can result in data loss. fdisk requires root privileges to modify partitions.
Common options
| Flag | What it does |
|---|---|
-l | list all partitions on all drives without entering interactive mode |
-u | display units in sectors instead of cylinders |
-s | print the size of DEVICE in blocks |
-c | toggle DOS-compatible mode (affects how cylinders are reported) |
-H | specify number of heads for low-level disk geometry |
-S | specify number of sectors per track for low-level disk geometry |
-C | specify number of cylinders for low-level disk geometry |
Examples
list all partitions and disks on the system without modifying anything
sudo fdisk -ldisplay partition table and details for the /dev/sda disk only
sudo fdisk -l /dev/sdaenter interactive mode to modify partitions on /dev/sdb; use 'm' for help
sudo fdisk /dev/sdbdisplay the total size of the /dev/sda disk in blocks
sudo fdisk -s /dev/sdacreate a new 500MB primary partition on /dev/sdc via non-interactive script
echo -e 'n\np\n1\n\n+500M\nw' | sudo fdisk /dev/sdcenter interactive prompt; type 'd' to delete, 'n' to create, 'p' to print, 't' to change type, 'w' to write changes
sudo fdisk /dev/sda