]> git.ipfire.org Git - thirdparty/util-linux.git/blame - disk-utils/sfdisk.8
fdisk: add 'F' command to list free unpartitioned space
[thirdparty/util-linux.git] / disk-utils / sfdisk.8
CommitLineData
5aac7429
KZ
1.\" sfdisk.8 -- man page for sfdisk
2.\" Copyright (C) 2014 Karel Zak <kzak@redhat.com>
fd6b7a7f 3.\"
5aac7429
KZ
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
12.\"
7f576918 13.TH SFDISK 8 "June 2015" "util-linux" "System Administration"
fd6b7a7f 14.SH NAME
5aac7429 15sfdisk \- display or manipulate a disk partition table
fd6b7a7f 16.SH SYNOPSIS
b61dfcf5 17.B sfdisk
f49ccec2
BS
18[options]
19.I device
20.RB [ \-N
21.IR partition-number ]
5aac7429
KZ
22.sp
23.B sfdisk
f49ccec2
BS
24[options]
25.I command
fd6b7a7f
KZ
26.SH DESCRIPTION
27.B sfdisk
689d83de 28is a script-oriented tool for partitioning any block device.
fd6b7a7f 29
d5206b96 30Since version 2.26
5dbff4c0 31.B sfdisk
5aac7429
KZ
32supports MBR (DOS), GPT, SUN and SGI disk labels, but no longer provides any
33functionality for CHS (Cylinder-Head-Sector) addressing. CHS has
34never been important for Linux, and this addressing concept does not make any
35sense for new devices.
689d83de 36.sp
b69719b6 37.B sfdisk
7f576918 38(since version 2.26) aligns the start and end of partitions to
689d83de
BS
39block-device I/O limits when relative sizes are specified, or when the
40default values are used.
41.sp
a8a4887b 42.B sfdisk
689d83de
BS
43does not create the standard system partitions for SGI and SUN disk labels like
44.BR fdisk (8)
45does.
a8a4887b
KZ
46It is necessary to explicitly create all partitions including whole-disk system
47partitions.
48
5aac7429
KZ
49.SH COMMANDS
50The commands are mutually exclusive.
fd6b7a7f 51.TP
f49ccec2 52.RB [ \-N " \fIpartition-number\fR] " \fIdevice\fR
689d83de 53The default \fBsfdisk\fR command is to read the specification for the desired
5aac7429 54partitioning of \fIdevice\fR from standard input, and then create a partition
689d83de
BS
55table according to the specification. See below for the description of the
56input format. If standard input is a terminal, then \fBsfdisk\fR starts an
57interactive session.
58.sp
59If the option \fB\-N\fR is specified, then the changes are applied to
7f576918 60the partition addressed by \fIpartition-number\fR. The unspecified fields
d754d554
KZ
61of the partition are not modified.
62.sp
7f576918
BS
63Note that it's possible to address an unused partition with \fB\-N\fR.
64For example, an MBR always contains 4 partitions, but the number of used
65partitions may be smaller. In this case \fBsfdisk\fR follows the default
66values from the partition table and does not use built-in defaults for the
67unused partition given with \fB\-N\fR. See also \fB\---append\fR.
fd6b7a7f 68.TP
703ab082 69.BR \-A , " \-\-activate \fIdevice\fR [" \fIpartition-number\fR...]
689d83de
BS
70Switch on the bootable flag. If no \fIpartition-number\fR is specified,
71then all partitions with an enabled flag are listed.
9a79aa6e 72.TP
9a79aa6e 73.BR \-d , " \-\-dump " \fIdevice\fR
7f576918 74Dump the partitions of a device in a format that is usable as input to \fBsfdisk\fR.
689d83de 75See the section \fBBACKING UP THE PARTITION TABLE\fR.
9a79aa6e 76.TP
b06c1ca6 77.BR \-g , " \-\-show\-geometry " [ \fIdevice ...]
689d83de 78List the geometry of all or the specified devices.
7f576918 79.TP
a592b4b5 80.BR \-J , " \-\-json " \fIdevice\fR
7f576918
BS
81Dump the partitions of a device in JSON format. Note that \fBsfdisk\fR is
82not able to use JSON as input format.
9a79aa6e 83.TP
689d83de
BS
84.BR \-l , " \-\-list " [ \fIdevice ...]
85List the partitions of all or the specified devices. This command can be used
9a79aa6e
KZ
86together with \fB\-\-verify\fR.
87.TP
b06c1ca6 88.BR \-\-part\-attrs " \fIdevice partno [" \fIattrs ]
689d83de
BS
89Change the GPT partition attribute bits. If \fIattrs\fR is not specified,
90then print the current partition settings. The \fIattrs\fR argument is a
91comma- or space-delimited list of bits. The currently supported attribute
92bits are: RequiredPartiton, NoBlockIOProtocol, LegacyBIOSBootable
93and GUID-specific bits in the range from 48 to 63. For example, the string
bc9e8547
KZ
94"RequiredPartiton,50,51" sets three bits.
95.TP
b06c1ca6 96.BR \-\-part\-label " \fIdevice partno [" \fIlabel ]
80840c16 97Change the GPT partition name (label). If \fIlabel\fR is not specified,
689d83de 98then print the current partition label.
e36fb07a 99.TP
b06c1ca6 100.BR \-\-part\-type " \fIdevice partno [" \fItype ]
689d83de
BS
101Change the partition type. If \fItype\fR is not specified, then print the
102current partition type. The \fItype\fR argument is hexadecimal for MBR,
103or a GUID for GPT. For backward compatibility the options \fB\-c\fR and
104\fB\-\-id\fR have the same meaning.
e36fb07a 105.TP
b06c1ca6 106.BR \-\-part\-uuid " \fIdevice partno [" \fIuuid ]
689d83de
BS
107Change the GPT partition UUID. If \fIuuid\fR is not specified,
108then print the current partition UUID.
e36fb07a 109.TP
b06c1ca6 110.BR \-s , " \-\-show\-size " [ \fIdevice ...]
689d83de 111List the sizes of all or the specified devices.
9a79aa6e 112.TP
b06c1ca6 113.BR \-T , " \-\-list\-types"
689d83de 114Print all supported types for the current disk label or the label specified by
9a79aa6e 115\fB\-\-label\fR.
3a5bdedf 116.TP
3f43f5d0 117.BR \-V , " \-\-verify " [ \fIdevice ...]
689d83de 118Test whether the partition table and partitions seem correct.
5aac7429
KZ
119
120.SH OPTIONS
fd6b7a7f 121.TP
703ab082 122.BR \-a , " \-\-append"
689d83de 123Don't create a new partition table, but only append the specified partitions.
fd6b7a7f 124.TP
5aac7429 125.BR \-b , " \-\-backup"
689d83de
BS
126Back up the current partition table sectors before starting the partitioning.
127The default backup file name is ~/sfdisk-<device>-<offset>.bak; to use another
7f576918 128name see option \fB\-O\fR, \fB\-\-backup\-file\fR.
f74478a6 129.TP
7f576918 130.BR \-\-color [ \fI=when ]
da25898b
KZ
131Colorize the output. The optional argument \fIwhen\fP
132can be \fBauto\fR, \fBnever\fR or \fBalways\fR. If the \fIwhen\fR argument is omitted,
7f576918
BS
133it defaults to \fBauto\fR. The colors can be disabled; for the current built-in default
134see the \fB\-\-help\fR output. See also the \fBCOLORS\fR section.
da25898b 135.TP
5aac7429
KZ
136.BR \-f , " \-\-force"
137Disable all consistency checking.
f74478a6 138.TP
80840c16
BS
139.BR \-\-Linux
140Deprecated and ignored option. Partitioning that is compatible with
7f576918 141Linux (and other modern operating systems) is the default.
80840c16
BS
142.TP
143.BR \-n , " \-\-no\-act"
144Do everything except writing to the device.
145.TP
146.B \-\-no\-reread
147Do not check through the re-read-partition-table ioctl whether the device is in use.
148.TP
149.BR \-O , " \-\-backup\-file " \fIpath\fR
150Override the default backup file name. Note that the device name and offset
151are always appended to the file name.
152.TP
689d83de 153.BR \-o , " \-\-output " \fIlist
01f9286c
KZ
154Specify which output columns to print. Use
155.B \-\-help
156to get a list of all supported columns.
689d83de 157.sp
01f9286c
KZ
158The default list of columns may be extended if \fIlist\fP is
159specified in the format \fI+list\fP (e.g. \fB-o +UUID\fP).
160.TP
5aac7429
KZ
161.BR \-q , " \-\-quiet"
162Suppress extra info messages.
f74478a6 163.TP
689d83de
BS
164.BR \-u , " \-\-unit S"
165Deprecated option. Only the sector unit is supported.
f74478a6 166.TP
689d83de
BS
167.BR \-X , " \-\-label " \fItype
168Specify the disk label type (e.g. \fBdos\fR, \fBgpt\fR, ...). If this option
169is not given, then \fBsfdisk\fR defaults to the existing label, but if there
170is no label on the device yet, then the type defaults to \fBdos\fR.
01f9286c 171.TP
b06c1ca6 172.BR \-Y , " \-\-label\-nested " \fItype
689d83de
BS
173Force editing of a nested disk label. The primary disk label has to exist already.
174This option allows to edit for example a hybrid/protective MBR on devices with GPT.
175.TP
176.BR \-v , " \-\-version"
177Display version information and exit.
e1422de3 178.TP
5aac7429
KZ
179.BR \-h , " \-\-help"
180Display help text and exit.
fd6b7a7f 181
9a79aa6e
KZ
182.SH "INPUT FORMATS"
183.B sfdisk
184supports two input formats and generic header lines.
185
186.B Header lines
187.RS
689d83de
BS
188The optional header lines specify generic information that apply to the partition
189table. The header-line format is:
190.RS
191.sp
9a79aa6e 192.B "<name>: <value>"
689d83de
BS
193.sp
194.RE
9a79aa6e
KZ
195The currently recognized headers are:
196.RS
197.TP
198.B unit
689d83de 199Specify the partitioning unit. The only supported unit is \fBsectors\fR.
9a79aa6e
KZ
200.TP
201.B label
689d83de 202Specify the partition table type. For example \fBdos\fR or \fBgpt\fR.
9a79aa6e
KZ
203.TP
204.B label-id
689d83de
BS
205Specify the partition table identifier. It should be a hexadecimal number
206(with a 0x prefix) for MBR and a UUID for GPT.
9a79aa6e
KZ
207.RE
208.sp
689d83de 209Note that it is only possible to use header lines before the first partition
9a79aa6e
KZ
210is specified in the input.
211.RE
212
689d83de
BS
213.B Unnamed-fields format
214.RS
9a79aa6e 215.RS
689d83de
BS
216.sp
217.I start size type bootable
218.sp
219.RE
9a79aa6e 220where each line fills one partition descriptor.
689d83de 221.sp
80840c16 222Fields are separated by whitespace, or by comma or semicolon possibly followed by
9a79aa6e 223whitespace; initial and trailing whitespace is ignored. Numbers can be octal,
689d83de
BS
224decimal or hexadecimal; decimal is the default. When a field is absent or empty,
225a default value is used. But when the \fB-N\fR option (change a single partition)
226is given, the default for each field is its previous value.
227.sp
9a79aa6e
KZ
228The default value of
229.I start
689d83de 230is the first non-assigned sector aligned according to device I/O limits.
ce9f568c 231The default start offset for the first partition is 1 MiB. The offset may
80840c16 232be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB,
ce9f568c 233EiB, ZiB and YiB) then the number is interpreted as offset in bytes.
689d83de 234.sp
9a79aa6e
KZ
235The default value of
236.I size
689d83de 237is as much as possible (until the next partition or end-of-device). A '+' can be
9a79aa6e
KZ
238used instead of a number for size, which also means as much as possible. The
239size may be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB,
240EiB, ZiB and YiB), then the number is interpreted as size of the partition in
241bytes and then the size is aligned according to the device I/O limits.
242The default is to interpret the number as number of sectors.
689d83de
BS
243.sp
244The partition
9a79aa6e 245.I type
689d83de
BS
246is given in hex for MBR (DOS), without the 0x prefix, a GUID string for GPT, or
247a shortcut:
9a79aa6e
KZ
248.RS
249.TP
689d83de 250.B L
9a79aa6e
KZ
251Linux; means 83 for MBR and 0FC63DAF-8483-4772-8E79-3D69D8477DE4 for GPT.
252.TP
689d83de 253.B S
9a79aa6e
KZ
254swap area; means 82 for MBR and 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F for GPT
255.TP
256.B E
257extended partition; means 5 for MBR
258.TP
259.B H
260home partition; means 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPT
261.TP
262.B X
263linux extended partition; means 85 for MBR.
264.RE
265
689d83de
BS
266.I bootable
267is specified as [\fB*\fR|\fB-\fR], with as default not-bootable. (The value of
268this field is irrelevant for Linux - when Linux runs it has been booted already -
269but might play a role for certain boot loaders and for other operating systems.)
9a79aa6e
KZ
270.RE
271
689d83de 272.B Named-fields format
9a79aa6e 273.RS
689d83de 274This format is more readable, robust, extendible and allows to specify additional
80840c16 275information (e.g. a UUID). It is recommended to use this format to keep your scripts
9a79aa6e 276more readable.
689d83de
BS
277.RS
278.sp
279.RI [ "device \fB:" ] " name" [\fB= value "], ..."
280.sp
281.RE
282The
9a79aa6e 283.I device
689d83de
BS
284field is optional. \fBsfdisk\fRextracts the partition number from the
285device name. It allows to specify the partitions in random order.
97325257 286This functionality is mostly used by \fB\-\-dump\fR.
689d83de 287Don't use it if you are not sure.
9a79aa6e
KZ
288
289The
290.I value
689d83de
BS
291can be between quotation marks (e.g. name="This is partition name").
292The currently supported fields are:
9a79aa6e
KZ
293.RS
294.TP
689d83de
BS
295.BI start= number
296The first non-assigned sector aligned according to device I/O limits. The default
ce9f568c
KZ
297start offset for the first partition is 1 MiB. The offset may be followed by
298the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then
299the number is interpreted as offset in bytes.
9a79aa6e 300.TP
689d83de
BS
301.BI size= number
302Specify the partition size in sectors. The number may be followed by the multiplicative
9a79aa6e
KZ
303suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB), then it's interpreted as size
304in bytes and the size is aligned according to device I/O limits.
305.TP
689d83de
BS
306.B bootable
307Mark the partition as bootable.
9a79aa6e 308.TP
689d83de
BS
309.BI attrs= string
310Partition attributes, usually GPT partition attribute bits. See
b06c1ca6 311\fB\-\-part\-attrs\fR for more details about the GPT-bits string format.
9a79aa6e 312.TP
689d83de 313.BI uuid= string
9a79aa6e
KZ
314GPT partition UUID.
315.TP
689d83de 316.BI name= string
9a79aa6e
KZ
317GPT partition name.
318.TP
689d83de
BS
319.BI type= code
320A hexadecimal number (without 0x) for an MBR partition, or a GUID for a GPT partition.
321For backward compatibility the \fBId=\fR field has the same meaning.
9a79aa6e
KZ
322.RE
323.RE
324
689d83de
BS
325.SH "BACKING UP THE PARTITION TABLE"
326It is recommended to save the layout of your devices.
9a79aa6e
KZ
327.B sfdisk
328supports two ways.
689d83de
BS
329.sp
330Use the \fB\-\-dump\fR option to save a description of the device layout
331to a text file. The dump format is suitable for later \fBsfdisk\fR input.
332For example:
9a79aa6e
KZ
333.RS
334.sp
335.B "sfdisk --dump /dev/sda > sda.dump"
336.sp
337.RE
689d83de 338This can later be restored by:
9a79aa6e
KZ
339.RS
340.sp
341.B "sfdisk /dev/sda < sda.dump"
342.RE
343
689d83de
BS
344If you want to do a full (binary) backup of all sectors where the
345partition table is stored,
346then use the \fB\-\-backup\fR option. It writes the sectors to
347~/sfdisk-<device>-<offset>.bak files. The default name of the backup file can
348be changed with the \fB\-\-backup\-file\fR option. The backup files
349contain only raw data from the \fIdevice\fR.
350Note that the same concept of backup files is used by
351.BR wipefs (8).
352For example:
9a79aa6e
KZ
353.RS
354.sp
355.B "sfdisk --backup /dev/sda"
356.sp
357.RE
689d83de 358The GPT header can later be restored by:
9a79aa6e
KZ
359.RS
360.sp
4bb82a45 361.B dd if=~/sfdisk-sda-0x00000200.bak of=/dev/sda seek=$((0x00000200)) bs=1 conv=notrunc
9a79aa6e
KZ
362.sp
363.RE
689d83de
BS
364Note that \fBsfdisk\fR since version 2.26 no longer provides the \fB\-I\fR option to
365restore sectors.
9a79aa6e
KZ
366.B dd (1)
367provides all necessary functionality.
368
da25898b
KZ
369.SH COLORS
370Implicit coloring can be disabled by an empty file \fI/etc/terminal-colors.d/sfdisk.disable\fR.
371
372See
373.BR terminal-colors.d (5)
374for more details about colorization configuration. The logical color names
375supported by
376.B sfdisk
377are:
378.TP
379.B header
380The header of the output tables.
381.TP
382.B warn
383The warning messages.
384.TP
385.B welcome
386The welcome message.
387
9a79aa6e 388.SH NOTES
689d83de 389Since version 2.26 \fBsfdisk\fR no longer provides the \fB\-R\fR or
b06c1ca6 390\fB\-\-re\-read\fR option to force the kernel to reread the partition table.
689d83de 391Use \fBblockdev \-\-rereadpt\fR instead.
9a79aa6e 392.PP
b06c1ca6
WP
393Since version 2.26 \fBsfdisk\fR does not provide the \fB\-\-DOS\fR, \fB\-\-IBM\fR, \fB\-\-DOS\-extended\fR,
394\fB\-\-unhide\fR, \fB\-\-show\-extended\fR, \fB\-\-cylinders\fR, \fB\-\-heads\fR, \fB\-\-sectors\fR,
395\fB\-\-inside\-outer\fR, \fB\-\-not\-inside\-outer\fR options.
9a79aa6e 396
68e422ec 397.SH ENVIRONMENT
47dd6918
KZ
398.IP SFDISK_DEBUG=all
399enables sfdisk debug output.
68e422ec
KZ
400.IP LIBFDISK_DEBUG=all
401enables libfdisk debug output.
402.IP LIBBLKID_DEBUG=all
403enables libblkid debug output.
404.IP LIBSMARTCOLS_DEBUG=all
405enables libsmartcols debug output.
406
612721db 407.SH "SEE ALSO"
612721db 408.BR fdisk (8),
5aac7429 409.BR cfdisk (8),
c64061c9
VD
410.BR parted (8),
411.BR partprobe (8),
5aac7429 412.BR partx(8)
689d83de 413
5aac7429
KZ
414.SH AUTHOR
415Karel Zak <kzak@redhat.com>
416.PP
417The current sfdisk implementation is based on the original sfdisk
418from Andries E. Brouwer.
419
86d62711 420.SH AVAILABILITY
601d12fb
KZ
421The sfdisk command is part of the util-linux package and is available from
422ftp://ftp.kernel.org/pub/linux/utils/util-linux/.