NAME
sfdisk - display or manipulate a disk partition tableSYNOPSIS
sfdisk [options] device [-N partition-number]DESCRIPTION
sfdisk is a script-oriented tool for partitioning any block device. It runs in interactive mode if executed on a terminal (stdin refers to a terminal).COMMANDS
The commands are mutually exclusive.The default sfdisk command is to read
the specification for the desired partitioning of device from standard
input, and then create a partition table according to the specification. See
below for the description of the input format. If standard input is a
terminal, then sfdisk starts an interactive session.
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.
Switch on the bootable flag for the specified
partitions and switch off the bootable flag on all unspecified partitions. The
special placeholder '-' may be used instead of the partition numbers to switch
off the bootable flag on all partitions.
The activation command is supported for MBR and PMBR only. If a GPT label is
detected, then sfdisk prints warning and automatically enters PMBR.
If no partition-number is specified, then list the partitions with an
enabled flag.
Back up the current partition table sectors in
binary format and exit. See the BACKING UP THE PARTITION TABLE
section.
Delete all or the specified partitions.
Dump the partitions of a device in a format
that is usable as input to sfdisk. See the BACKING UP THE PARTITION
TABLE section.
List the geometry of all or the specified
devices. For backward compatibility the deprecated option
--show-pt-geometry have the same meaning as this one.
Dump the partitions of a device in JSON
format. Note that sfdisk is not able to use JSON as input format.
List the partitions of all or the specified
devices. This command can be used together with --verify.
List the free unpartitioned areas on all or
the specified devices.
Change the GPT partition attribute bits. If
attributes is not specified, then print the current partition settings.
The attributes argument is a comma- or space-delimited list of bits
numbers or bit names. For example, the string
"RequiredPartition,50,51" sets three bits. The currently supported
attribute bits are:
Bit 0 (RequiredPartition)
Bit 1 (NoBlockIOProtocol)
Bit 2 (LegacyBIOSBootable)
Bits 3-47
Bits 48-63
If this bit is set, the partition is required
for the platform to function. The creator of the partition indicates that
deletion or modification of the contents can result in loss of platform
features or failure for the platform to boot or operate. The system cannot
function normally if this partition is removed, and it should be considered
part of the hardware of the system.
EFI firmware should ignore the content of the
partition and not try to read from it.
The partition may be bootable by legacy BIOS
firmware.
Undefined and must be zero. Reserved for
expansion by future versions of the UEFI specification.
Reserved for GUID specific use. The use of
these bits will vary depending on the partition type. For example Microsoft
uses bit 60 to indicate read-only, 61 for shadow copy of another partition, 62
for hidden partitions and 63 to disable automount.
Change the GPT partition name (label). If
label is not specified, then print the current partition label.
Change the partition type. If type is
not specified, then print the current partition type.
The type argument is hexadecimal for MBR, GUID for GPT, type alias (e.g.
"linux") or type shortcut (e.g. 'L'). For backward compatibility the
options -c and --id have the same meaning as this one.
Change the GPT partition UUID. If uuid
is not specified, then print the current partition UUID.
Change the disk identifier. If id is
not specified, then print the current identifier. The identifier is UUID for
GPT or unsigned integer for MBR.
Renumber the partitions, ordering them by
their start offset.
List the sizes of all or the specified devices
in units of 1024 byte size. This command is DEPRECATED in favour of
blockdev(8).
Print all supported types for the current disk
label or the label specified by --label.
Test whether the partition table and
partitions seem correct.
Relocate partition table header. This command
is currently supported for GPT header only. The argument oper can be:
gpt-bak-std
gpt-bak-mini
Move GPT backup header to the standard
location at the end of the device.
Move GPT backup header behind the last
partition. Note that UEFI standard requires the backup header at the end of
the device and partitioning tools can automatically relocate the header to
follow the standard.
OPTIONS
-a, --appendDon’t create a new partition table, but
only append the specified partitions.
Note that unused partition maybe be re-used in this case although it is not the
last partition in the partition table. See also -N to specify entry in
the partition table.
Back up the current partition table sectors
before starting the partitioning. The default backup file name is
~/sfdisk-<device>-<offset>.bak; to use another name see
option -O, --backup-file. See section BACKING UP THE
PARTITION TABLE for more details.
Colorize the output. The optional argument
when can be auto, never or always. If the
when argument is omitted, it defaults to auto. The colors can be
disabled; for the current built-in default see the --help output. See
also the COLORS section.
Disable all consistency checking.
Deprecated and ignored option. Partitioning
that is compatible with Linux (and other modern operating systems) is the
default.
Use exclusive BSD lock for device or file it
operates. The optional argument mode can be yes, no (or 1
and 0) or nonblock. If the mode argument is omitted, it defaults
to yes. This option overwrites environment variable
$LOCK_BLOCK_DEVICE. The default is not to use any lock at all, but
it’s recommended to avoid collisions with systemd-udevd(8) or
other tools.
Do everything except writing to the
device.
Do not check through the
re-read-partition-table ioctl whether the device is in use.
Don’t tell the kernel about partition
changes. This option is recommended together with --no-reread to modify
a partition on used disk. The modified partition should not be used (e.g.,
mounted).
Override the default backup file name. Note
that the device name and offset are always appended to the file name.
Move data after partition relocation, for
example when moving the beginning of a partition to another place on the disk.
The size of the partition has to remain the same, the new and old location may
overlap. This option requires option -N in order to be processed on one
specific partition only.
The optional path specifies log file name. The log file contains
information about all read/write operations on the partition data. The word
"@default" as a path forces sfdisk to use
~/sfdisk-<devname>.move for the log. The log is optional since
v2.35.
Note that this operation is risky and not atomic. Don’t forget to
backup your data!
See also --move-use-fsync.
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
Use the fsync(2) system call after each
write when moving data to a new location by --move-data.
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).
Suppress extra info messages.
Deprecated option. Only the sector unit is
supported. This option is not supported when using the --show-size
command.
Specify the disk label type (e.g., dos,
gpt, ...). If this option is not given, then sfdisk defaults to
the existing label, but if there is no label on the device yet, then the type
defaults to dos. The default or the current label may be overwritten by
the "label: <name>" script header line. The option
--label does not force sfdisk to create empty disk label (see
the EMPTY DISK LABEL section below).
Force editing of a nested disk label. The
primary disk label has to exist already. This option allows editing for
example a hybrid/protective MBR on devices with GPT.
Wipe filesystem, RAID and partition-table
signatures from the device, in order to avoid possible 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; except the old partition-table
signatures which are always wiped before create a new partition-table if the
argument when is not never. The auto mode also does not
wipe the first sector (boot sector), it is necessary to use the always
mode to wipe this area. In all cases detected signatures are reported by
warning messages before a new partition table is created. See also the
wipefs(8) command.
Wipe filesystem, RAID and partition-table
signatures from a newly created partition, in order to avoid possible
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
confirmation by user. In all cases detected signatures are reported by warning
messages after a new partition is created. See also wipefs(8)
command.
Display version information and exit.
Display help text and exit.
INPUT FORMATS
sfdisk supports two input formats and generic header lines.Header lines
The optional header lines specify generic information that apply to the partition table. The header-line format is:Specify the partitioning unit. The only
supported unit is sectors.
Specify the partition table type. For example
dos or gpt.
Specify the partition table identifier. It
should be a hexadecimal number (with a 0x prefix) for MBR and a UUID for
GPT.
Specify the first usable sector for GPT
partitions.
Specify the last usable sector for GPT
partitions.
Specify the maximal number of GPT
partitions.
Specify minimal size in bytes used to
calculate partitions alignment. The default is 1MiB and it’s strongly
recommended to use the default. Do not modify this variable if you’re
not sure.
Specify sector size. This header is
informative only and it is not used when sfdisk creates a new partition
table, in this case the real device specific value is always used and sector
size from the dump is ignored.
Unnamed-fields format
Linux; means 83 for MBR and
0FC63DAF-8483-4772-8E79-3D69D8477DE4 for GPT.
swap area; means 82 for MBR and
0657FD6D-A4AB-43C4-84E5-0933C84B4F4F for GPT
MBR extended partition; means 05 for MBR. The
original shortcut 'E' is deprecated due to collision with 0x0E MBR partition
type.
home partition; means
933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPT
EFI System partition, means EF for MBR and
C12A7328-F81F-11D2-BA4B-00A0C93EC93B for GPT
Linux RAID; means FD for MBR and
A19D880F-05FC-4D3B-A006-743F0F84911E for GPT
LVM; means 8E for MBR and
E6D6D379-F507-44C2-A23C-238F2A3DF928 for GPT
Named-fields format
This format is more readable, robust, extensible and allows specifying additional information (e.g., a UUID). It is recommended to use this format to keep your scripts more readable.The first non-assigned sector aligned
according to device I/O limits. The default start offset for the first
partition is 1 MiB. If the offset is followed by the multiplicative suffixes
(KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB), then the number is interpreted as
offset in bytes.
Specify the partition size in sectors. The
number may be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB,
PiB, EiB, ZiB and YiB), then it’s interpreted as size in bytes and the
size is aligned according to device I/O limits.
Mark the partition as bootable.
Partition attributes, usually GPT partition
attribute bits. See --part-attrs for more details about the GPT-bits
string format.
GPT partition UUID.
GPT partition name.
A hexadecimal number (without 0x) for an MBR
partition, a GUID for a GPT partition, a shortcut as for unnamed-fields format
or a type name (e.g. type="Linux /usr (x86)"). See above the section
about the unnamed-fields format for more details. For backward compatibility
the Id= field has the same meaning.
EMPTY DISK LABEL
sfdisk does not create partition table without partitions by default. The lines with partitions are expected in the script by default. The empty partition table has to be explicitly requested by "label: <name>" script header line without any partitions lines. For example:BACKING UP THE PARTITION TABLE
It is recommended to save the layout of your devices. sfdisk supports two ways.Dump in sfdisk compatible format
Use the --dump command to save a description of the device layout to a text file. The dump format is suitable for later sfdisk input. For example:Full binary backup
If you want to do a full binary backup of all sectors where the partition table is stored, then use the --backup-pt-sectors command. 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. For example:COLORS
The output colorization is implemented by terminal-colors.d(5) functionality. Implicit coloring can be disabled by an empty fileThe header of the output tables.
The warning messages.
The welcome message.
ENVIRONMENT
SFDISK_DEBUG=allenables sfdisk debug output.
enables libfdisk debug output.
enables libblkid debug output.
enables libsmartcols debug output.
use exclusive BSD lock. The mode is
"1" or "0". See --lock for more details.
NOTES
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.EXAMPLES
sfdisk --list --label-nested=mbr /dev/sdaPrint protective MBR on device with GPT disk
label.
Create three Linux partitions, with the
default start, the size of the first two partitions is 10MiB, and the last
partition fills all available space on the device.
The same as the previous example, but in
named-fields format.
Set type of the 3rd partition to 'swap'.
The same as the previous example, but without
script use.
Delete 2nd partition.
Enlarge 3rd partition in both directions, move
start to use free space before the partition and enlarge the size to use all
free space after to the partition, and move partition data too.
AUTHORS
Karel <[email protected]>ZakSEE ALSO
fdisk(8), cfdisk(8), parted(8), partprobe(8), partx(8)REPORTING BUGS
For bug reports, use the issue tracker at <https://github.com/util-linux/util-linux/issues>.AVAILABILITY
The sfdisk command is part of the util-linux package which can be downloaded from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>.2022-08-04 | util-linux 2.38.1 |