sfdisk(8)
A scriptable disk partition editor for creating, modifying, and deleting disk partitions.
Synopsis
sfdisk [options] [device]Description
sfdisk is a partition table manipulator that reads and modifies partition tables in a scriptable way. Unlike interactive tools like fdisk, sfdisk accepts partition specifications from stdin or command-line arguments, making it ideal for automation and scripting. It supports both MBR and GPT partition tables.
sfdisk can list existing partitions, back up partition tables, restore them, and create new partitions by accepting input in a simple text format. Changes are applied directly to the disk device and take effect immediately, though the kernel may need to reread the partition table.
Common options
| Flag | What it does |
|---|---|
-l, --list | List the partition table of a device in a readable format |
-d, --dump | Dump the partition table in a format suitable for input to sfdisk (for backup/restore) |
-i, --input | Read partition specification from stdin or a file instead of command line |
-F, --free-space | Show unpartitioned space on the device |
-s, --size | Print partition size in sectors |
-L, --Linux | Create a Linux native partition (type 83) |
-S, --Sun | Create a Sun partition |
-X, --gpt | Convert MBR partition table to GPT format |
-N, --partno | Operate on a specific partition number |
--force | Force operations without confirmation, even if dangerous |
--no-reread | Do not attempt to reread the partition table after modification |
-q, --quiet | Suppress warning messages and prompts |
Examples
List all partitions on /dev/sda in a human-readable format
sfdisk -l /dev/sdaBack up the partition table of /dev/sda to a file for safe keeping
sfdisk -d /dev/sda > sda_backup.txtRestore partition table from backup file to /dev/sda
sfdisk /dev/sda < sda_backup.txtShow unallocated (free) space on /dev/sda
sfdisk -F /dev/sdaCreate a Linux partition starting at sector 0 with size 1000 sectors on /dev/sdb
echo '0,1000,L' | sfdisk /dev/sdbShow the size of partition 1 on /dev/sda in sectors
sfdisk -N 1 -s /dev/sdaDelete partition 3 from /dev/sda
sfdisk --delete /dev/sda -N 3Convert MBR partition table on /dev/sda to GPT format
sfdisk -X /dev/sda