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