sfdisk [options] device [-N partition-number]
sfdisk [options] command
sfdisk is a script-oriented tool for partitioning any block device.
Since version 2.26 sfdisk supports MBR (DOS), GPT, SUN and SGI disk labels, but no longer provides any functionality for CHS (Cylinder-Head-Sector) addressing. CHS has never been important for Linux, and this addressing concept does not make any sense for new devices.
sfdisk (since version 2.26) aligns the start and end of partitions to block-device I/O limits when relative sizes are specified, or when the default values are used.
sfdisk does not create the standard system partitions for SGI and SUN disk labels like fdisk(8) does. It is necessary to explicitly create all partitions including whole-disk system partitions.
The commands are mutually exclusive.
If the option -N is specified, then the changes are applied to the partition addressed by partition-number. The unspecified fields of the partition are not modified.
Note that it's possible to address an unused partition with -N. For example, an MBR always contains 4 partitions, but the number of used partitions may be smaller. In this case sfdisk follows the default values from the partition table and does not use built-in defaults for the unused partition given with -N. See also --append.
The path overrides the default log file name (the default is ~/sfdisk-<devname>.move). The log file contains information about all read/write operations on the partition data.
Note that this operation is risky and not atomic. Don't forget to backup your data!
In the example below, the first command creates a 100MiB free area before the first partition and moves the data it contains (e.g. a filesystem), the next command creates a new partition from the free space (at offset 2048), and the last command reorders partitions to match disk order (the original sdc1 will become sdc2).
echo '+100M,' | sfdisk --move-data /dev/sdc -N 1 echo '2048,' | sfdisk /dev/sdc --append sfdisk /dev/sdc --reorder
The default list of columns may be extended if list is specified in the format +list (e.g. -o +UUID).
sfdisk supports two input formats and generic header lines.
Note that it is only possible to use header lines before the first partition is specified in the input.
start size type bootable
Fields are separated by whitespace, comma or semicolon possibly followed by whitespace; initial and trailing whitespace is ignored. Numbers can be octal, decimal or hexadecimal; decimal is the default. When a field is absent, empty or specified as '-' a default value is used. But when the -N option (change a single partition) is given, the default for each field is its previous value.
The default value of start is the first non-assigned sector aligned according to device I/O limits. The default start offset for the first partition is 1 MiB. The offset may be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then the number is interpreted as offset in bytes.
The default value of size indicates "as much as possible"; i.e. until the next partition or end-of-device. A numerical argument is by default interpreted as a number of sectors, however if the size is followed by one of the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then the number is interpreted as the size of the partition in bytes and it is then aligned according to the device I/O limits. A '+' can be used instead of a number to enlarge the partition as much as possible. Note '+' is equivalent to the default behaviour for a new partition; existing partitions will be resized as required.
The partition type is given in hex for MBR (DOS), without the 0x prefix, a GUID string for GPT, or a shortcut:
The default type value is L
bootable is specified as [*|-], with as default not-bootable. The value of this field is irrelevant for Linux - when Linux runs it has been booted already - but ir might play a role for certain boot loaders and for other operating systems.
[device :] name[=value], ...
The value can be between quotation marks (e.g. name="This is partition name"). The currently supported fields are:
It is recommended to save the layout of your devices. sfdisk supports two ways.
Use the --dump option to save a description of the device layout to a text file. The dump format is suitable for later sfdisk input. For example:
sfdisk --dump /dev/sda > sda.dump
sfdisk /dev/sda < sda.dump
If you want to do a full (binary) backup of all sectors where the partition table is stored, then use the --backup option. It writes the sectors to ~/sfdisk-<device>-<offset>.bak files. The default name of the backup file can be changed with the --backup-file option. The backup files contain only raw data from the device. Note that the same concept of backup files is used by wipefs(8). For example:
sfdisk --backup /dev/sda
dd if=~/sfdisk-sda-0x00000200.bak of=/dev/sda \ seek=$((0x00000200)) bs=1 conv=notrunc
Implicit coloring can be disabled by an empty file /etc/terminal-colors.d/sfdisk.disable.
See terminal-colors.d(5) for more details about colorization configuration. The logical color names supported by sfdisk are:
Since version 2.26 sfdisk no longer provides the -R or --re-read option to force the kernel to reread the partition table. Use blockdev --rereadpt instead.
Since version 2.26 sfdisk does not provide the --DOS, --IBM, --DOS-extended, --unhide, --show-extended, --cylinders, --heads, --sectors, --inside-outer, --not-inside-outer options.
fdisk(8), cfdisk(8), parted(8), partprobe(8), partx(8)
Karel Zak <firstname.lastname@example.org>
The current sfdisk implementation is based on the original sfdisk from Andries E. Brouwer.
The sfdisk command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.