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