]> git.ipfire.org Git - thirdparty/util-linux.git/blob - disk-utils/sfdisk.8
scriptreplay: add --stream to the man page
[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 "June 2015" "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. It
29 runs in interactive mode if executed on terminal (stdin refers to a terminal).
30
31 Since version 2.26
32 .B sfdisk
33 supports MBR (DOS), GPT, SUN and SGI disk labels, but no longer provides any
34 functionality for CHS (Cylinder-Head-Sector) addressing. CHS has
35 never been important for Linux, and this addressing concept does not make any
36 sense for new devices.
37 .sp
38 .B sfdisk
39 (since version 2.26)
40 .B aligns the start and end of partitions
41 to block-device I/O limits when relative sizes are specified, when the default
42 values are used or when multiplicative suffixes (e.g. MiB) are used for sizes.
43 It is possible that partition size will be optimized (reduced or enlarged) due
44 to alignment if the start offset is specified exactly in sectors and partition
45 size relative or by multiplicative suffixes.
46
47 The recommended way is not to specify start offsets at all and specify
48 partition size in MiB, GiB (or so). In this case sfdisk align all partitions
49 to block-device I/O limits (or when I/O limits are too small then to megabyte
50 boundary to keep disk layout portable). If this default behaviour is unwanted
51 (usually for very small partitions) then specify offsets and sizes in
52 sectors. In this case sfdisk entirely follows specified numbers without any
53 optimization.
54 .sp
55 .B sfdisk
56 does not create the standard system partitions for SGI and SUN disk labels like
57 .BR fdisk (8)
58 does.
59 It is necessary to explicitly create all partitions including whole-disk system
60 partitions.
61
62 .B sfdisk
63 uses BLKRRPART (reread partition table) ioctl to make sure that the device is
64 not used by system or another tools (see also --no-reread). It's possible that
65 this feature or another sfdisk activity races with \fBudevd\fR. The recommended way
66 how to avoid possible collisions is to use exclusive flock for the whole-disk
67 device to serialize device access. The exclusive lock will cause udevd to skip
68 the event handling on the device. For example:
69 .RS
70 .sp
71 .nf
72 .B "flock /dev/sdc sfdisk /dev/sdc"
73 .fi
74 .sp
75 .RE
76 Note, this semantic is not currently supported by udevd for MD and DM devices.
77
78 .SH COMMANDS
79 The commands are mutually exclusive.
80 .TP
81 .RB [ \-N " \fIpartition-number\fR] " \fIdevice\fR
82 The default \fBsfdisk\fR command is to read the specification for the desired
83 partitioning of \fIdevice\fR from standard input, and then create a partition
84 table according to the specification. See below for the description of the
85 input format. If standard input is a terminal, then \fBsfdisk\fR starts an
86 interactive session.
87 .sp
88 If the option \fB\-N\fR is specified, then the changes are applied to
89 the partition addressed by \fIpartition-number\fR. The unspecified fields
90 of the partition are not modified.
91 .sp
92 Note that it's possible to address an unused partition with \fB\-N\fR.
93 For example, an MBR always contains 4 partitions, but the number of used
94 partitions may be smaller. In this case \fBsfdisk\fR follows the default
95 values from the partition table and does not use built-in defaults for the
96 unused partition given with \fB\-N\fR. See also \fB\-\-append\fR.
97 .TP
98 .BR \-A , " \-\-activate \fIdevice " [ \fIpartition-number...]
99 Switch on the bootable flag for the specified partitions and switch off the
100 bootable flag on all unspecified partitions. The special placeholder '-'
101 may be used instead of the partition numbers to switch off the bootable flag
102 on all partitions.
103
104 The activation command is supported for MBR and PMBR only. If GPT label is detected
105 than sfdisk prints warning and automatically enter PMBR.
106
107 If no \fIpartition-number\fR is specified, then list the partitions with an
108 enabled flag.
109 .TP
110 .BR "\-\-delete \fIdevice " [ \fIpartition-number ...]
111 Delete all or the specified partitions.
112 .TP
113 .BR \-d , " \-\-dump " \fIdevice\fR
114 Dump the partitions of a device in a format that is usable as input to \fBsfdisk\fR.
115 See the section \fBBACKING UP THE PARTITION TABLE\fR.
116 .TP
117 .BR \-g , " \-\-show\-geometry " [ \fIdevice ...]
118 List the geometry of all or the specified devices. For backward
119 compatibility the deprecated option \fB\-\-show\-pt\-geometry\fR have the same
120 meaning as this one.
121 .TP
122 .BR \-J , " \-\-json " \fIdevice\fR
123 Dump the partitions of a device in JSON format. Note that \fBsfdisk\fR is
124 not able to use JSON as input format.
125 .TP
126 .BR \-l , " \-\-list " [ \fIdevice ...]
127 List the partitions of all or the specified devices. This command can be used
128 together with \fB\-\-verify\fR.
129 .TP
130 .BR \-F , " \-\-list-free " [ \fIdevice ...]
131 List the free unpartitioned areas on all or the specified devices.
132 .TP
133 .BR "\-\-part\-attrs \fIdevice partition-number " [ \fIattributes ]
134 Change the GPT partition attribute bits. If \fIattributes\fR is not specified,
135 then print the current partition settings. The \fIattributes\fR argument is a
136 comma- or space-delimited list of bits. The currently supported attribute
137 bits are: RequiredPartition, NoBlockIOProtocol, LegacyBIOSBootable
138 and GUID-specific bits in the range from 48 to 63. For example, the string
139 "RequiredPartition,50,51" sets three bits.
140 .TP
141 .BR "\-\-part\-label \fIdevice partition-number " [ \fIlabel ]
142 Change the GPT partition name (label). If \fIlabel\fR is not specified,
143 then print the current partition label.
144 .TP
145 .BR "\-\-part\-type \fIdevice partition-number " [ \fItype ]
146 Change the partition type. If \fItype\fR is not specified, then print the
147 current partition type. The \fItype\fR argument is hexadecimal for MBR,
148 or a GUID for GPT. For backward compatibility the options \fB\-c\fR and
149 \fB\-\-id\fR have the same meaning as this one.
150 .TP
151 .BR "\-\-part\-uuid \fIdevice partition-number " [ \fIuuid ]
152 Change the GPT partition UUID. If \fIuuid\fR is not specified,
153 then print the current partition UUID.
154 .TP
155 .BR \-r , " \-\-reorder " \fIdevice
156 Renumber the partitions, ordering them by their start offset.
157 .TP
158 .BR \-s , " \-\-show\-size " [ \fIdevice ...]
159 List the sizes of all or the specified devices in units of 1024 byte size.
160 This command is DEPRECATED in favour of
161 .BR blockdev (8).
162 .TP
163 .BR \-T , " \-\-list\-types"
164 Print all supported types for the current disk label or the label specified by
165 \fB\-\-label\fR.
166 .TP
167 .BR \-V , " \-\-verify " [ \fIdevice ...]
168 Test whether the partition table and partitions seem correct.
169
170 .SH OPTIONS
171 .TP
172 .BR \-a , " \-\-append"
173 Don't create a new partition table, but only append the specified partitions.
174 .TP
175 .BR \-b , " \-\-backup"
176 Back up the current partition table sectors before starting the partitioning.
177 The default backup file name is ~/sfdisk-<device>-<offset>.bak; to use another
178 name see option \fB\-O\fR, \fB\-\-backup\-file\fR.
179 .TP
180 .BR \-\-color [ =\fIwhen ]
181 Colorize the output. The optional argument \fIwhen\fP
182 can be \fBauto\fR, \fBnever\fR or \fBalways\fR. If the \fIwhen\fR argument is omitted,
183 it defaults to \fBauto\fR. The colors can be disabled; for the current built-in default
184 see the \fB\-\-help\fR output. See also the \fBCOLORS\fR section.
185 .TP
186 .BR \-f , " \-\-force"
187 Disable all consistency checking.
188 .TP
189 .B \-\-Linux
190 Deprecated and ignored option. Partitioning that is compatible with
191 Linux (and other modern operating systems) is the default.
192 .TP
193 .BR \-n , " \-\-no\-act"
194 Do everything except writing to the device.
195 .TP
196 .B \-\-no\-reread
197 Do not check through the re-read-partition-table ioctl whether the device is in use.
198 .TP
199 .B \-\-no\-tell\-kernel
200 Don't tell the kernel about partition changes. This option is recommended together
201 with \fB\-\-no\-reread\fR to modify a partition on used disk. The modified partition
202 should not be used (e.g. mounted).
203 .TP
204 .BR \-O , " \-\-backup\-file " \fIpath
205 Override the default backup file name. Note that the device name and offset
206 are always appended to the file name.
207 .TP
208 .BR \-\-move-data [ =\fIpath ]
209 Move data after partition relocation, for example when moving the beginning
210 of a partition to another place on the disk. The size of the partition has
211 to remain the same, the new and old location may overlap. This option requires
212 option \fB\-N\fR in order to be processed on one specific partition only.
213
214 The optional \fIpath\fR specifies log file name. The log file contains information
215 about all read/write operations on the partition data. The word "@default" as
216 a \fIpath\fR forces sfdisk to use ~/sfdisk-<devname>.move for the log. The log is
217 optional since v2.35.
218
219 Note that this operation is risky and not atomic. \fBDon't forget to backup your data!\fR
220
221 See also \fB\-\-move\-use\-fsync\fR.
222
223 In the example below, the first command creates a 100MiB free area before
224 the first partition and moves the data it contains (e.g. a filesystem),
225 the next command creates a new partition from the free space (at offset 2048),
226 and the last command reorders partitions to match disk order
227 (the original sdc1 will become sdc2).
228 .RS
229 .sp
230 .B "echo '+100M,' | sfdisk --move-data /dev/sdc -N 1"
231 .br
232 .B "echo '2048,' | sfdisk /dev/sdc --append
233 .br
234 .B sfdisk /dev/sdc --reorder
235 .sp
236 .RE
237
238 .TP
239 .BR \-\-move\-use\-fsync
240 Use fsync system call after each write when move dara to a new location by
241 \fB\-\-move\-data\fR.
242 .TP
243 .BR \-o , " \-\-output " \fIlist
244 Specify which output columns to print. Use
245 .B \-\-help
246 to get a list of all supported columns.
247 .sp
248 The default list of columns may be extended if \fIlist\fP is
249 specified in the format \fI+list\fP (e.g. \fB-o +UUID\fP).
250 .TP
251 .BR \-q , " \-\-quiet"
252 Suppress extra info messages.
253 .TP
254 .BR \-u , " \-\-unit S"
255 Deprecated option. Only the sector unit is supported. This option is not
256 supported when using the --show-size command.
257 .TP
258 .BR \-X , " \-\-label " \fItype
259 Specify the disk label type (e.g. \fBdos\fR, \fBgpt\fR, ...). If this option
260 is not given, then \fBsfdisk\fR defaults to the existing label, but if there
261 is no label on the device yet, then the type defaults to \fBdos\fR. The default
262 or the current label may be overwritten by the "label: <name>" script header
263 line. The option \fB\-\-label\fR does not force \fBsfdisk\fR to create empty
264 disk label (see the \fBEMPTY DISK LABEL\fR section below).
265 .TP
266 .BR \-Y , " \-\-label\-nested " \fItype
267 Force editing of a nested disk label. The primary disk label has to exist already.
268 This option allows to edit for example a hybrid/protective MBR on devices with GPT.
269
270 .TP
271 .BR -w , " \-\-wipe "\fIwhen
272 Wipe filesystem, RAID and partition-table signatures from the device, in order
273 to avoid possible collisions. The argument \fIwhen\fR can be \fBauto\fR,
274 \fBnever\fR or \fBalways\fR. When this option is not given, the default is
275 \fBauto\fR, in which case signatures are wiped only when in interactive mode;
276 except the old partition-table signatures which are always wiped before create
277 a new partition-table if the argument \fIwhen\fR is not \fBnever\fR. In all
278 cases detected signatures are reported by warning messages before a new
279 partition table is created. See also
280 .BR wipefs (8)
281 command.
282
283 .TP
284 .BR -W , " \-\-wipe-partitions "\fIwhen
285 Wipe filesystem, RAID and partition-table signatures from a newly created
286 partitions, in order to avoid possible collisions. The argument \fIwhen\fR can
287 be \fBauto\fR, \fBnever\fR or \fBalways\fR. When this option is not given, the
288 default is \fBauto\fR, in which case signatures are wiped only when in
289 interactive mode and after confirmation by user. In all cases detected
290 signatures are reported by warning messages after a new partition is created.
291 See also
292 .BR wipefs (8)
293 command.
294
295 .TP
296 .BR \-v , " \-\-version"
297 Display version information and exit.
298 .TP
299 .BR \-h , " \-\-help"
300 Display help text and exit.
301
302 .SH "INPUT FORMATS"
303 .B sfdisk
304 supports two input formats and generic header lines.
305
306 .B Header lines
307 .RS
308 The optional header lines specify generic information that apply to the partition
309 table. The header-line format is:
310 .RS
311 .sp
312 .B "<name>: <value>"
313 .sp
314 .RE
315 The currently recognized headers are:
316 .RS
317 .TP
318 .B unit
319 Specify the partitioning unit. The only supported unit is \fBsectors\fR.
320 .TP
321 .B label
322 Specify the partition table type. For example \fBdos\fR or \fBgpt\fR.
323 .TP
324 .B label-id
325 Specify the partition table identifier. It should be a hexadecimal number
326 (with a 0x prefix) for MBR and a UUID for GPT.
327 .TP
328 .B first-lba
329 Specify the first usable sector for GPT partitions.
330 .TP
331 .B last-lba
332 Specify the last usable sector for GPT partitions.
333 .TP
334 .B table-length
335 Specify the maximal number of GPT partitions.
336 .TP
337 .B grain
338 Specify minimal size in bytes used to calculate partitions alignment. The
339 default is 1MiB and it's strongly recommended to use the default. Do not
340 modify this variable if you're not sure.
341 .TP
342 .B sector-size
343 Specify sector size. This header is informative only and it is not used when
344 sfdisk creates a new partition table, in this case the real device specific
345 value is always used and sector size from the dump is ignored.
346 .RE
347 .sp
348 Note that it is only possible to use header lines before the first partition
349 is specified in the input.
350 .RE
351
352 .B Unnamed-fields format
353 .RS
354 .RS
355 .sp
356 .I start size type bootable
357 .sp
358 .RE
359 where each line fills one partition descriptor.
360 .sp
361 Fields are separated by whitespace, comma or semicolon possibly
362 followed by whitespace; initial and trailing whitespace is ignored.
363 Numbers can be octal, decimal or hexadecimal; decimal is the default.
364 When a field is absent, empty or specified as '-' a default value is
365 used. But when the \fB-N\fR option (change a single partition) is
366 given, the default for each field is its previous value.
367 .sp
368 The default value of
369 .I start
370 is the first non-assigned sector aligned according to device I/O limits.
371 The default start offset for the first partition is 1 MiB. The offset may
372 be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB,
373 EiB, ZiB and YiB) then the number is interpreted as offset in bytes.
374 .sp
375 The default value of
376 .I size
377 indicates "as much as possible"; i.e. until the next partition or
378 end-of-device. A numerical argument is by default interpreted as a
379 number of sectors, however if the size is followed by one of the
380 multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB)
381 then the number is interpreted as the size of the partition in bytes
382 and it is then aligned according to the device I/O limits. A '+' can
383 be used instead of a number to enlarge the partition as much as
384 possible. Note '+' is equivalent to the default behaviour for a new
385 partition; existing partitions will be resized as required.
386 .sp
387 The partition
388 .I type
389 is given in hex for MBR (DOS), without the 0x prefix, a GUID string for GPT, or
390 a shortcut:
391 .RS
392 .TP
393 .B L
394 Linux; means 83 for MBR and 0FC63DAF-8483-4772-8E79-3D69D8477DE4 for GPT.
395 .TP
396 .B S
397 swap area; means 82 for MBR and 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F for GPT
398 .TP
399 .B E
400 extended partition; means 5 for MBR
401 .TP
402 .B H
403 home partition; means 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPT
404 .TP
405 .B X
406 linux extended partition; means 85 for MBR.
407 .TP
408 .B U
409 EFI System partition, means EF for MBR and C12A7328-F81F-11D2-BA4B-00A0C93EC93B for GPT
410 .TP
411 .B R
412 Linux RAID; means FD for MBR and A19D880F-05FC-4D3B-A006-743F0F84911E for GPT
413 .TP
414 .B V
415 LVM; means 8E for MBR and E6D6D379-F507-44C2-A23C-238F2A3DF928 for GPT
416 .RE
417 .PP
418 The default
419 .I type
420 value is
421 .I L
422
423 .I bootable
424 is specified as [\fB*\fR|\fB-\fR], with as default not-bootable. The
425 value of this field is irrelevant for Linux - when Linux runs it has
426 been booted already - but it might play a role for certain boot
427 loaders and for other operating systems.
428 .RE
429
430 .B Named-fields format
431 .RS
432 This format is more readable, robust, extensible and allows to specify additional
433 information (e.g. a UUID). It is recommended to use this format to keep your scripts
434 more readable.
435 .RS
436 .sp
437 .RI [ "device \fB:" ] " name" [\fB= value "], ..."
438 .sp
439 .RE
440 The
441 .I device
442 field is optional. \fBsfdisk\fR extracts the partition number from the
443 device name. It allows to specify the partitions in random order.
444 This functionality is mostly used by \fB\-\-dump\fR.
445 Don't use it if you are not sure.
446
447 The
448 .I value
449 can be between quotation marks (e.g. name="This is partition name").
450 The currently supported fields are:
451 .RS
452 .TP
453 .BI start= number
454 The first non-assigned sector aligned according to device I/O limits. The default
455 start offset for the first partition is 1 MiB. The offset may be followed by
456 the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then
457 the number is interpreted as offset in bytes.
458 .TP
459 .BI size= number
460 Specify the partition size in sectors. The number may be followed by the multiplicative
461 suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB), then it's interpreted as size
462 in bytes and the size is aligned according to device I/O limits.
463 .TP
464 .B bootable
465 Mark the partition as bootable.
466 .TP
467 .BI attrs= string
468 Partition attributes, usually GPT partition attribute bits. See
469 \fB\-\-part\-attrs\fR for more details about the GPT-bits string format.
470 .TP
471 .BI uuid= string
472 GPT partition UUID.
473 .TP
474 .BI name= string
475 GPT partition name.
476 .TP
477 .BI type= code
478 A hexadecimal number (without 0x) for an MBR partition, a GUID for a GPT partition,
479 or a shortcut as for unnamed-fields format.
480 For backward compatibility the \fBId=\fR field has the same meaning.
481 .RE
482 .RE
483
484 .SH "EMPTY DISK LABEL"
485 .B sfdisk
486 does not create partition table without partitions by default. The lines with
487 partitions are expected in the script by default. The empty partition table has
488 to be explicitly requested by "label: <name>" script header line without any
489 partitions lines. For example:
490 .RS
491 .sp
492 .B "echo 'label: gpt' | sfdisk /dev/sdb"
493 .sp
494 .RE
495 creates empty GPT partition table. Note that the \fB\-\-append\fR disables this feature.
496
497 .SH "BACKING UP THE PARTITION TABLE"
498 It is recommended to save the layout of your devices.
499 .B sfdisk
500 supports two ways.
501 .sp
502 Use the \fB\-\-dump\fR option to save a description of the device layout
503 to a text file. The dump format is suitable for later \fBsfdisk\fR input.
504 For example:
505 .RS
506 .sp
507 .B "sfdisk --dump /dev/sda > sda.dump"
508 .sp
509 .RE
510 This can later be restored by:
511 .RS
512 .sp
513 .B "sfdisk /dev/sda < sda.dump"
514 .RE
515
516 If you want to do a full (binary) backup of all sectors where the
517 partition table is stored,
518 then use the \fB\-\-backup\fR option. It writes the sectors to
519 ~/sfdisk-<device>-<offset>.bak files. The default name of the backup file can
520 be changed with the \fB\-\-backup\-file\fR option. The backup files
521 contain only raw data from the \fIdevice\fR.
522 Note that the same concept of backup files is used by
523 .BR wipefs (8).
524 For example:
525 .RS
526 .sp
527 .B "sfdisk --backup /dev/sda"
528 .sp
529 .RE
530 The GPT header can later be restored by:
531 .RS
532 .sp
533 .nf
534 .B "dd if=~/sfdisk-sda-0x00000200.bak of=/dev/sda \e"
535 .B " seek=$((0x00000200)) bs=1 conv=notrunc"
536 .fi
537 .sp
538 .RE
539 Note that \fBsfdisk\fR since version 2.26 no longer provides the \fB\-I\fR option to
540 restore sectors.
541 .BR dd (1)
542 provides all necessary functionality.
543
544 .SH COLORS
545 Implicit coloring can be disabled by an empty file \fI/etc/terminal-colors.d/sfdisk.disable\fR.
546
547 See
548 .BR terminal-colors.d (5)
549 for more details about colorization configuration. The logical color names
550 supported by
551 .B sfdisk
552 are:
553 .TP
554 .B header
555 The header of the output tables.
556 .TP
557 .B warn
558 The warning messages.
559 .TP
560 .B welcome
561 The welcome message.
562
563 .SH NOTES
564 Since version 2.26 \fBsfdisk\fR no longer provides the \fB\-R\fR or
565 \fB\-\-re\-read\fR option to force the kernel to reread the partition table.
566 Use \fBblockdev \-\-rereadpt\fR instead.
567 .PP
568 Since version 2.26 \fBsfdisk\fR does not provide the \fB\-\-DOS\fR, \fB\-\-IBM\fR, \fB\-\-DOS\-extended\fR,
569 \fB\-\-unhide\fR, \fB\-\-show\-extended\fR, \fB\-\-cylinders\fR, \fB\-\-heads\fR, \fB\-\-sectors\fR,
570 \fB\-\-inside\-outer\fR, \fB\-\-not\-inside\-outer\fR options.
571
572 .SH ENVIRONMENT
573 .IP SFDISK_DEBUG=all
574 enables sfdisk debug output.
575 .IP LIBFDISK_DEBUG=all
576 enables libfdisk debug output.
577 .IP LIBBLKID_DEBUG=all
578 enables libblkid debug output.
579 .IP LIBSMARTCOLS_DEBUG=all
580 enables libsmartcols debug output.
581
582 .SH "SEE ALSO"
583 .BR fdisk (8),
584 .BR cfdisk (8),
585 .BR parted (8),
586 .BR partprobe (8),
587 .BR partx (8)
588
589 .SH AUTHOR
590 Karel Zak <kzak@redhat.com>
591 .PP
592 The current sfdisk implementation is based on the original sfdisk
593 from Andries E. Brouwer.
594
595 .SH AVAILABILITY
596 The sfdisk command is part of the util-linux package and is available from
597 https://www.kernel.org/pub/linux/utils/util-linux/.