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