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