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