$linuxjunkies
>

sfdisk(8)

A scriptable disk partition editor for creating, modifying, and deleting disk partitions.

UbuntuDebianFedoraArch

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

FlagWhat it does
-l, --listList the partition table of a device in a readable format
-d, --dumpDump the partition table in a format suitable for input to sfdisk (for backup/restore)
-i, --inputRead partition specification from stdin or a file instead of command line
-F, --free-spaceShow unpartitioned space on the device
-s, --sizePrint partition size in sectors
-L, --LinuxCreate a Linux native partition (type 83)
-S, --SunCreate a Sun partition
-X, --gptConvert MBR partition table to GPT format
-N, --partnoOperate on a specific partition number
--forceForce operations without confirmation, even if dangerous
--no-rereadDo not attempt to reread the partition table after modification
-q, --quietSuppress warning messages and prompts

Examples

List all partitions on /dev/sda in a human-readable format

sfdisk -l /dev/sda

Back up the partition table of /dev/sda to a file for safe keeping

sfdisk -d /dev/sda > sda_backup.txt

Restore partition table from backup file to /dev/sda

sfdisk /dev/sda < sda_backup.txt

Show unallocated (free) space on /dev/sda

sfdisk -F /dev/sda

Create a Linux partition starting at sector 0 with size 1000 sectors on /dev/sdb

echo '0,1000,L' | sfdisk /dev/sdb

Show the size of partition 1 on /dev/sda in sectors

sfdisk -N 1 -s /dev/sda

Delete partition 3 from /dev/sda

sfdisk --delete /dev/sda -N 3

Convert MBR partition table on /dev/sda to GPT format

sfdisk -X /dev/sda

Related commands