$linuxjunkies
>

fdisk(8)

fdisk is a command-line utility for creating, deleting, and managing disk partitions on Linux systems.

UbuntuDebianFedoraArch

Synopsis

fdisk [OPTION]... DEVICE

Description

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

FlagWhat it does
-llist all partitions on all drives without entering interactive mode
-udisplay units in sectors instead of cylinders
-sprint the size of DEVICE in blocks
-ctoggle DOS-compatible mode (affects how cylinders are reported)
-Hspecify number of heads for low-level disk geometry
-Sspecify number of sectors per track for low-level disk geometry
-Cspecify number of cylinders for low-level disk geometry

Examples

list all partitions and disks on the system without modifying anything

sudo fdisk -l

display partition table and details for the /dev/sda disk only

sudo fdisk -l /dev/sda

enter interactive mode to modify partitions on /dev/sdb; use 'm' for help

sudo fdisk /dev/sdb

display the total size of the /dev/sda disk in blocks

sudo fdisk -s /dev/sda

create a new 500MB primary partition on /dev/sdc via non-interactive script

echo -e 'n\np\n1\n\n+500M\nw' | sudo fdisk /dev/sdc

enter interactive prompt; type 'd' to delete, 'n' to create, 'p' to print, 't' to change type, 'w' to write changes

sudo fdisk /dev/sda

Related commands