Linux "sfdisk" Command Line Options and Examples
display or manipulate a disk partition table

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 func‐ tionality for CHS (Cylinder-Head-Sector) addressing.


Usage:

sfdisk [options] device [-N partition-number]


    sfdisk [options] command






Command Line Options:

-a
Don't create a new partition table, but only append the specified partitions.
sfdisk -a ...
-b
Back up the current partition table sectors before starting the partitioning. The default backup filename is ~/sfdisk-<device>-<offset>.bak; to use another name see option -O, --backup-file.
sfdisk -b ...
--color[
Colorize the output. The optional argument when can be auto, never or always. If the when argument isomitted, it defaults to auto. The colors can be disabled; for the current built-in default see the
sfdisk --color[ ...
--help
output. See also the COLORS section.
sfdisk --help ...
-f
Disable all consistency checking.
sfdisk -f ...
--Linux
Deprecated and ignored option. Partitioning that is compatible with Linux (and other modern operatingsystems) is the default.
sfdisk --Linux ...
-n
Do everything except writing to the device.
sfdisk -n ...
--no-reread
Do not check through the re-read-partition-table ioctl whether the device is in use.
sfdisk --no-reread ...
--no-tell-kernel
Don't tell the kernel about partition changes. This option is recommended together with --no-reread tomodify a partition on used disk. The modified partition should not be used (e.g. mounted).
sfdisk --no-tell-kernel ...
-O
Override the default backup file name. Note that the device name and offset are always appended to thefile name.
sfdisk -O ...
--move-data[
Move data after partition relocation, for example when moving the beginning of a partition to anotherplace on the disk. The size of the partition has to remain the same, the new and old location mayoverlap. This option requires option -N in order to be processed on one specific partition only.The path overrides the default log file name (the default is ~/sfdisk-<devname>.move). The log filecontains 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 movesthe 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 willbecome sdc2).echo '+100M,' | sfdisk --move-data /dev/sdc -N 1echo '2048,' | sfdisk /dev/sdc --appendsfdisk /dev/sdc --reorder
sfdisk --move-data[ ...
-o
Specify which output columns to print. Use --help to get a list of all supported columns.The default list of columns may be extended if list is specified in the format +list (e.g. -o +UUID).
sfdisk -o ...
-q
Suppress extra info messages.
sfdisk -q ...
-u
Deprecated option. Only the sector unit is supported. This option is not supported when using the
sfdisk -u ...
-X
Specify the disk label type (e.g. dos, gpt, ...). If this option is not given, then sfdisk defaults tothe existing label, but if there is no label on the device yet, then the type defaults to dos. Thedefault or the current label may be overwritten by the "label: <name>" script header line. The option
sfdisk -X ...
--label
does not force sfdisk to create empty disk label (see the EMPTY DISK LABEL section below).
sfdisk --label ...
-Y
Force editing of a nested disk label. The primary disk label has to exist already. This option allowsto edit for example a hybrid/protective MBR on devices with GPT.
sfdisk -Y ...
-w
Wipe filesystem, RAID and partition-table signatures from the device, in order to avoid possible colli‐sions. The argument when can be auto, never or always. When this option is not given, the default isauto, in which case signatures are wiped only when in interactive mode; except the old partition-tablesignatures which are always wiped before create a new partition-table if the argument when is notnever. In all cases detected signatures are reported by warning messages before a new partition tableis created. See also wipefs(8) command.
sfdisk -w ...
-W
Wipe filesystem, RAID and partition-table signatures from a newly created partitions, in order to avoidpossible collisions. The argument when can be auto, never or always. When this option is not given,the default is auto, in which case signatures are wiped only when in interactive mode and after confir‐mation by user. In all cases detected signatures are reported by warning messages after a new parti‐tion is created. See also wipefs(8) command.
sfdisk -W ...
-v
Display version information and exit.
sfdisk -v ...
-h
Display help text and exit.INPUT FORMATSsfdisk supports two input formats and generic header lines.Header linesThe optional header lines specify generic information that apply to the partition table. The header-line format is:<name>: <value>The currently recognized headers are:unit Specify the partitioning unit. The only supported unit is sectors.label Specify the partition table type. For example dos or gpt.label-idSpecify the partition table identifier. It should be a hexadecimal number (with a 0xprefix) for MBR and a UUID for GPT.Note that it is only possible to use header lines before the first partition is specified in the input.Unnamed-fields formatstart size type bootablewhere each line fills one partition descriptor.Fields are separated by whitespace, comma or semicolon possibly followed by whitespace; initial andtrailing 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 multi‐plicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then the number is interpreted as offsetin 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 isfollowed by one of the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then thenumber is interpreted as the size of the partition in bytes and it is then aligned according to thedevice 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 beresized as required.The partition type is given in hex for MBR (DOS), without the 0x prefix, a GUID string for GPT, or ashortcut:L Linux; means 83 for MBR and 0FC63DAF-8483-4772-8E79-3D69D8477DE4 for GPT.S swap area; means 82 for MBR and 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F for GPTE extended partition; means 5 for MBRH home partition; means 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPTX linux extended partition; means 85 for MBR.U EFI System partition, means EF for MBR and C12A7328-F81F-11D2-BA4B-00A0C93EC93B for GPTThe default type value is Lbootable is specified as [*|-], with as default not-bootable. The value of this field is irrelevantfor Linux - when Linux runs it has been booted already - but ir might play a role for certain bootloaders and for other operating systems.Named-fields formatThis format is more readable, robust, extensible and allows to specify additional information (e.g. aUUID). It is recommended to use this format to keep your scripts more readable.[device :] name[=value], ...The device field is optional. sfdisk extracts the partition number from the device name. It allows tospecify the partitions in random order. This functionality is mostly used by --dump. Don't use it ifyou are not sure.The value can be between quotation marks (e.g. name="This is partition name"). The currently supportedfields are:start=numberThe first non-assigned sector aligned according to device I/O limits. The default startoffset for the first partition is 1 MiB. The offset may be followed by the multiplicativesuffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then the number is interpreted asoffset in bytes.size=numberSpecify the partition size in sectors. The number may be followed by the multiplicativesuffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB), then it's interpreted as size inbytes and the size is aligned according to device I/O limits.bootableMark the partition as bootable.attrs=stringPartition attributes, usually GPT partition attribute bits. See --part-attrs for moredetails about the GPT-bits string format.uuid=stringGPT partition UUID.name=stringGPT partition name.type=codeA hexadecimal number (without 0x) for an MBR partition, or a GUID for a GPT partition.For backward compatibility the Id= field has the same meaning.EMPTY DISK LABELsfdisk does not create partition table without partitions by default. The lines with partitions are expectedin the script by default. The empty partition table has to be explicitly requested by "label: <name>" scriptheader line without any partitions lines. For example:echo 'label: gpt' | sfdisk /dev/sdbcreates empty GPT partition table. Note that the --append disables this feature.BACKING UP THE PARTITION TABLEIt 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 suitablefor later sfdisk input. For example:sfdisk --dump /dev/sda > sda.dumpThis can later be restored by:sfdisk /dev/sda < sda.dumpIf you want to do a full (binary) backup of all sectors where the partition table is stored, then use the
sfdisk -h ...
--cylinders
ENVIRONMENTSFDISK_DEBUG=allenables sfdisk debug output.LIBFDISK_DEBUG=allenables libfdisk debug output.LIBBLKID_DEBUG=allenables libblkid debug output.LIBSMARTCOLS_DEBUG=allenables libsmartcols debug output.
sfdisk --cylinders ...