1SFDISK(8)                    System Administration                   SFDISK(8)
2
3
4

NAME

6       sfdisk - display or manipulate a disk partition table
7

SYNOPSIS

9       sfdisk [options] device [-N partition-number]
10
11       sfdisk [options] command
12

DESCRIPTION

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       systemd-udevd(8). The recommended way how to avoid possible collisions
52       is to use --lock option. The exclusive lock will cause systemd-udevd to
53       skip the event 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

COMMANDS

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       --backup-pt-sectors device
93           Back up the current partition table sectors in binary format and
94           exit. See the BACKING UP THE PARTITION TABLE section.
95
96       --delete device [partition-number...]
97           Delete all or the specified partitions.
98
99       -d, --dump device
100           Dump the partitions of a device in a format that is usable as input
101           to sfdisk. See the BACKING UP THE PARTITION TABLE section.
102
103       -g, --show-geometry [device...]
104           List the geometry of all or the specified devices. For backward
105           compatibility the deprecated option --show-pt-geometry have the
106           same meaning as this one.
107
108       -J, --json device
109           Dump the partitions of a device in JSON format. Note that sfdisk is
110           not able to use JSON as input format.
111
112       -l, --list [device...]
113           List the partitions of all or the specified devices. This command
114           can be used together with --verify.
115
116       -F, --list-free [device...]
117           List the free unpartitioned areas on all or the specified devices.
118
119       --part-attrs device partition-number [attributes]
120           Change the GPT partition attribute bits. If attributes is not
121           specified, then print the current partition settings. The
122           attributes argument is a comma- or space-delimited list of bits
123           numbers or bit names. For example, the string
124           "RequiredPartition,50,51" sets three bits. The currently supported
125           attribute bits are:
126
127           Bit 0 (RequiredPartition)
128               If this bit is set, the partition is required for the platform
129               to function. The creator of the partition indicates that
130               deletion or modification of the contents can result in loss of
131               platform features or failure for the platform to boot or
132               operate. The system cannot function normally if this partition
133               is removed, and it should be considered part of the hardware of
134               the system.
135
136           Bit 1 (NoBlockIOProtocol)
137               EFI firmware should ignore the content of the partition and not
138               try to read from it.
139
140           Bit 2 (LegacyBIOSBootable)
141               The partition may be bootable by legacy BIOS firmware.
142
143           Bits 3-47
144               Undefined and must be zero. Reserved for expansion by future
145               versions of the UEFI specification.
146
147           Bits 48-63
148               Reserved for GUID specific use. The use of these bits will vary
149               depending on the partition type. For example Microsoft uses bit
150               60 to indicate read-only, 61 for shadow copy of another
151               partition, 62 for hidden partitions and 63 to disable
152               automount.
153
154       --part-label device partition-number [label]
155           Change the GPT partition name (label). If label is not specified,
156           then print the current partition label.
157
158       --part-type device partition-number [type]
159           Change the partition type. If type is not specified, then print the
160           current partition type.
161
162           The type argument is hexadecimal for MBR, GUID for GPT, type alias
163           (e.g. "linux") or type shortcut (e.g. 'L'). For backward
164           compatibility the options -c and --id have the same meaning as this
165           one.
166
167       --part-uuid device partition-number [uuid]
168           Change the GPT partition UUID. If uuid is not specified, then print
169           the current partition UUID.
170
171       --disk-id device [id]
172           Change the disk identifier. If id is not specified, then print the
173           current identifier. The identifier is UUID for GPT or unsigned
174           integer for MBR.
175
176       -r, --reorder device
177           Renumber the partitions, ordering them by their start offset.
178
179       -s, --show-size [device...]
180           List the sizes of all or the specified devices in units of 1024
181           byte size. This command is DEPRECATED in favour of blockdev(8).
182
183       -T, --list-types
184           Print all supported types for the current disk label or the label
185           specified by --label.
186
187       -V, --verify [device...]
188           Test whether the partition table and partitions seem correct.
189
190       --relocate oper device
191           Relocate partition table header. This command is currently
192           supported for GPT header only. The argument oper can be:
193
194           gpt-bak-std
195               Move GPT backup header to the standard location at the end of
196               the device.
197
198           gpt-bak-mini
199               Move GPT backup header behind the last partition. Note that
200               UEFI standard requires the backup header at the end of the
201               device and partitioning tools can automatically relocate the
202               header to follow the standard.
203

OPTIONS

205       -a, --append
206           Don’t create a new partition table, but only append the specified
207           partitions.
208
209           Note that unused partition maybe be re-used in this case although
210           it is not the last partition in the partition table. See also -N to
211           specify entry in the partition table.
212
213       -b, --backup
214           Back up the current partition table sectors before starting the
215           partitioning. The default backup file name is
216           ~/sfdisk-<device>-<offset>.bak; to use another name see option -O,
217           --backup-file. See section BACKING UP THE PARTITION TABLE for more
218           details.
219
220       --color[=when]
221           Colorize the output. The optional argument when can be auto, never
222           or always. If the when argument is omitted, it defaults to auto.
223           The colors can be disabled; for the current built-in default see
224           the --help output. See also the COLORS section.
225
226       -f, --force
227           Disable all consistency checking.
228
229       --Linux
230           Deprecated and ignored option. Partitioning that is compatible with
231           Linux (and other modern operating systems) is the default.
232
233       --lock[=mode]
234           Use exclusive BSD lock for device or file it operates. The optional
235           argument mode can be yes, no (or 1 and 0) or nonblock. If the mode
236           argument is omitted, it defaults to yes. This option overwrites
237           environment variable $LOCK_BLOCK_DEVICE. The default is not to use
238           any lock at all, but it’s recommended to avoid collisions with
239           systemd-udevd(8) or other tools.
240
241       -n, --no-act
242           Do everything except writing to the device.
243
244       --no-reread
245           Do not check through the re-read-partition-table ioctl whether the
246           device is in use.
247
248       --no-tell-kernel
249           Don’t tell the kernel about partition changes. This option is
250           recommended together with --no-reread to modify a partition on used
251           disk. The modified partition should not be used (e.g., mounted).
252
253       -O, --backup-file path
254           Override the default backup file name. Note that the device name
255           and offset are always appended to the file name.
256
257       --move-data[=path]
258           Move data after partition relocation, for example when moving the
259           beginning of a partition to another place on the disk. The size of
260           the partition has to remain the same, the new and old location may
261           overlap. This option requires option -N in order to be processed on
262           one specific partition only.
263
264           The optional path specifies log file name. The log file contains
265           information about all read/write operations on the partition data.
266           The word "@default" as a path forces sfdisk to use
267           ~/sfdisk-<devname>.move for the log. The log is optional since
268           v2.35.
269
270           Note that this operation is risky and not atomic. Don’t forget to
271           backup your data!
272
273           See also --move-use-fsync.
274
275           In the example below, the first command creates a 100MiB free area
276           before the first partition and moves the data it contains (e.g., a
277           filesystem), the next command creates a new partition from the free
278           space (at offset 2048), and the last command reorders partitions to
279           match disk order (the original sdc1 will become sdc2).
280
281           echo '+100M,' | sfdisk --move-data /dev/sdc -N 1 echo '2048,' |
282           sfdisk /dev/sdc --append sfdisk /dev/sdc --reorder
283
284       --move-use-fsync
285           Use the fsync(2) system call after each write when moving data to a
286           new location by --move-data.
287
288       -o, --output list
289           Specify which output columns to print. Use --help to get a list of
290           all supported columns.
291
292           The default list of columns may be extended if list is specified in
293           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 option
300           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 option
304           is not given, then sfdisk defaults to the existing label, but if
305           there is no label on the device yet, then the type defaults to dos.
306           The default or the current label may be overwritten by the "label:
307           <name>" script header line. The option --label does not force
308           sfdisk to create empty disk label (see the EMPTY DISK LABEL section
309           below).
310
311       -Y, --label-nested type
312           Force editing of a nested disk label. The primary disk label has to
313           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 when
319           can be auto, never or always. When this option is not given, the
320           default is auto, in which case signatures are wiped only when in
321           interactive mode; except the old partition-table signatures which
322           are always wiped before create a new partition-table if the
323           argument when is not never. The auto mode also does not wipe the
324           first sector (boot sector), it is necessary to use the always mode
325           to wipe this area. In all cases detected signatures are reported by
326           warning messages before a new partition table is created. See also
327           the wipefs(8) command.
328
329       -W, --wipe-partitions when
330           Wipe filesystem, RAID and partition-table signatures from a newly
331           created partition, in order to avoid possible collisions. The
332           argument when can be auto, never or always. When this option is not
333           given, the default is auto, in which case signatures are wiped only
334           when in interactive mode and after confirmation by user. In all
335           cases detected signatures are reported by warning messages after a
336           new partition is created. See also wipefs(8) command.
337
338       -v, --version
339           Display version information and exit.
340
341       -h, --help
342           Display help text and exit.
343

INPUT FORMATS

345       sfdisk supports two input formats and generic header lines.
346
347   Header lines
348       The optional header lines specify generic information that apply to the
349       partition table. The header-line format is:
350
351       <name>: <value>
352
353       The currently recognized headers are:
354
355       unit
356           Specify the partitioning unit. The only supported unit is sectors.
357
358       label
359           Specify the partition table type. For example dos or gpt.
360
361       label-id
362           Specify the partition table identifier. It should be a hexadecimal
363           number (with a 0x prefix) for MBR and a UUID for GPT.
364
365       first-lba
366           Specify the first usable sector for GPT partitions.
367
368       last-lba
369           Specify the last usable sector for GPT partitions.
370
371       table-length
372           Specify the maximal number of GPT partitions.
373
374       grain
375           Specify minimal size in bytes used to calculate partitions
376           alignment. The default is 1MiB and it’s strongly recommended to use
377           the default. Do not modify this variable if you’re not sure.
378
379       sector-size
380           Specify sector size. This header is informative only and it is not
381           used when sfdisk creates a new partition table, in this case the
382           real device specific value is always used and sector size from the
383           dump is ignored.
384
385       Note that it is only possible to use header lines before the first
386       partition is specified in the input.
387
388   Unnamed-fields format
389          start size type bootable
390
391       where each line fills one partition descriptor.
392
393       Fields are separated by whitespace, comma (recommended) or semicolon
394       possibly followed by whitespace; initial and trailing whitespace is
395       ignored. Numbers can be octal, decimal or hexadecimal; decimal is the
396       default. When a field is absent, empty or specified as '-' a default
397       value is used. But when the -N option (change a single partition) is
398       given, the default for each field is its previous value.
399
400       The default value of start is the first non-assigned sector aligned
401       according to device I/O limits. The default start offset for the first
402       partition is 1 MiB. If the offset is followed by the multiplicative
403       suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB), then the number
404       is interpreted as offset in bytes. Since v2.38 when the -N option
405       (change a single partition) is given, a '+' can be used to enlarge
406       partition by move start of the partition if there is a free space
407       before the partition.
408
409       The default value of size indicates "as much as possible"; i.e., until
410       the next partition or end-of-device. A numerical argument is by default
411       interpreted as a number of sectors, however if the size is followed by
412       one of the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB
413       and YiB) then the number is interpreted as the size of the partition in
414       bytes and it is then aligned according to the device I/O limits. A '+'
415       can be used instead of a number to enlarge the partition as much as
416       possible. Note '+' is equivalent to the default behaviour for a new
417       partition; existing partitions will be resized as required.
418
419       The partition type is given in hex for MBR (DOS) where 0x prefix is
420       optional; a GUID string for GPT; a shortcut or an alias. It’s
421       recommended to use two letters for MBR hex codes to avoid collision
422       between deprecated shortcut 'E' and '0E' MBR hex code. For backward
423       compatibility sfdisk tries to interpret type as a shortcut as a first
424       possibility in partitioning scripts although on other places (e.g.
425       --part-type command) it tries shortcuts as the last possibility.
426
427       Since v2.36 libfdisk supports partition type aliases as extension to
428       shortcuts. The alias is a simple human readable word (e.g. "linux").
429
430       Since v2.37 libfdisk supports partition type names on input, ignoring
431       the case of the characters and all non-alphanumeric and non-digit
432       characters in the name (e.g. "Linux /usr x86" is the same as "linux
433       usr-x86").
434
435       Supported shortcuts and aliases:
436
437       L - alias 'linux'
438           Linux; means 83 for MBR and 0FC63DAF-8483-4772-8E79-3D69D8477DE4
439           for GPT.
440
441       S - alias 'swap'
442           swap area; means 82 for MBR and
443           0657FD6D-A4AB-43C4-84E5-0933C84B4F4F for GPT
444
445       Ex - alias 'extended'
446           MBR extended partition; means 05 for MBR. The original shortcut 'E'
447           is deprecated due to collision with 0x0E MBR partition type.
448
449       H - alias 'home'
450           home partition; means 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPT
451
452       U - alias 'uefi'
453           EFI System partition, means EF for MBR and
454           C12A7328-F81F-11D2-BA4B-00A0C93EC93B for GPT
455
456       R - alias 'raid'
457           Linux RAID; means FD for MBR and
458           A19D880F-05FC-4D3B-A006-743F0F84911E for GPT
459
460       V - alias 'lvm'
461           LVM; means 8E for MBR and E6D6D379-F507-44C2-A23C-238F2A3DF928 for
462           GPT
463
464       The default type value is linux.
465
466       The shortcut 'X' for Linux extended partition (85) is deprecated in
467       favour of 'Ex'.
468
469       bootable is specified as [*|-], with as default not-bootable. The value
470       of this field is irrelevant for Linux - when Linux runs it has been
471       booted already - but it might play a role for certain boot loaders and
472       for other operating systems.
473
474   Named-fields format
475       This format is more readable, robust, extensible and allows specifying
476       additional information (e.g., a UUID). It is recommended to use this
477       format to keep your scripts more readable.
478
479          [device :] name[=value], ...
480
481       The device field is optional. sfdisk extracts the partition number from
482       the device name. It allows specifying the partitions in random order.
483       This functionality is mostly used by --dump. Don’t use it if you are
484       not sure.
485
486       The value can be between quotation marks (e.g., name="This is partition
487       name"). The fields start= and size= support '+' and '-' in the same way
488       as Unnamed-fields format.
489
490       The currently supported fields are:
491
492       start=number
493           The first non-assigned sector aligned according to device I/O
494           limits. The default start offset for the first partition is 1 MiB.
495           If the offset is followed by the multiplicative suffixes (KiB, MiB,
496           GiB, TiB, PiB, EiB, ZiB and YiB), then the number is interpreted as
497           offset in bytes.
498
499       size=number
500           Specify the partition size in sectors. The number may be followed
501           by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB
502           and YiB), then it’s interpreted as size in bytes and the size is
503           aligned according to device I/O limits.
504
505       bootable
506           Mark the partition as bootable.
507
508       attrs=string
509           Partition attributes, usually GPT partition attribute bits. See
510           --part-attrs for more details about the GPT-bits string format.
511
512       uuid=string
513           GPT partition UUID.
514
515       name=string
516           GPT partition name.
517
518       type=code
519           A hexadecimal number (without 0x) for an MBR partition, a GUID for
520           a GPT partition, a shortcut as for unnamed-fields format or a type
521           name (e.g. type="Linux /usr (x86)"). See above the section about
522           the unnamed-fields format for more details. For backward
523           compatibility the Id= field has the same meaning.
524

EMPTY DISK LABEL

526       sfdisk does not create partition table without partitions by default.
527       The lines with partitions are expected in the script by default. The
528       empty partition table has to be explicitly requested by "label: <name>"
529       script header line without any partitions lines. For example:
530
531          echo 'label: gpt' | sfdisk /dev/sdb
532
533       creates empty GPT partition table. Note that the --append disables this
534       feature.
535

BACKING UP THE PARTITION TABLE

537       It is recommended to save the layout of your devices. sfdisk supports
538       two ways.
539
540   Dump in sfdisk compatible format
541       Use the --dump command to save a description of the device layout to a
542       text file. The dump format is suitable for later sfdisk input. For
543       example:
544
545          sfdisk --dump /dev/sda > sda.dump
546
547       This can later be restored by:
548
549          sfdisk /dev/sda < sda.dump
550
551   Full binary backup
552       If you want to do a full binary backup of all sectors where the
553       partition table is stored, then use the --backup-pt-sectors command. It
554       writes the sectors to ~/sfdisk-<device>-<offset>.bak files. The default
555       name of the backup file can be changed with the --backup-file option.
556       The backup files contain only raw data from the device. For example:
557
558          sfdisk --backup-pt-sectors /dev/sda
559
560       The GPT header can later be restored by:
561
562          dd if=~/sfdisk-sda-0x00000200.bak of=/dev/sda
563          seek=$((0x00000200)) bs=1 conv=notrunc
564
565       It’s also possible to use the --backup option to create the same backup
566       immediately after startup for other sfdisk commands. For example,
567       backup partition table before deleting all partitions from partition
568       table:
569
570          sfdisk --backup --delete /dev/sda
571
572       The same concept of backup files is used by wipefs(8).
573
574       Note that sfdisk since version 2.26 no longer provides the -I option to
575       restore sectors. dd(1) provides all necessary functionality.
576

COLORS

578       The output colorization is implemented by terminal-colors.d(5)
579       functionality. Implicit coloring can be disabled by an empty file
580
581          /etc/terminal-colors.d/sfdisk.disable
582
583       for the sfdisk command or for all tools by
584
585          /etc/terminal-colors.d/disable
586
587       The user-specific $XDG_CONFIG_HOME/terminal-colors.d or
588       $HOME/.config/terminal-colors.d overrides the global setting.
589
590       Note that the output colorization may be enabled by default, and in
591       this case terminal-colors.d directories do not have to exist yet.
592
593       The logical color names supported by sfdisk are:
594
595       header
596           The header of the output tables.
597
598       warn
599           The warning messages.
600
601       welcome
602           The welcome message.
603

ENVIRONMENT

605       SFDISK_DEBUG=all
606           enables sfdisk debug output.
607
608       LIBFDISK_DEBUG=all
609           enables libfdisk debug output.
610
611       LIBBLKID_DEBUG=all
612           enables libblkid debug output.
613
614       LIBSMARTCOLS_DEBUG=all
615           enables libsmartcols debug output.
616
617       LOCK_BLOCK_DEVICE=<mode>
618           use exclusive BSD lock. The mode is "1" or "0". See --lock for more
619           details.
620

NOTES

622       Since version 2.26 sfdisk no longer provides the -R or --re-read option
623       to force the kernel to reread the partition table. Use blockdev
624       --rereadpt instead.
625
626       Since version 2.26 sfdisk does not provide the --DOS, --IBM,
627       --DOS-extended, --unhide, --show-extended, --cylinders, --heads,
628       --sectors, --inside-outer, --not-inside-outer options.
629

EXAMPLES

631       sfdisk --list --label-nested=mbr /dev/sda
632           Print protective MBR on device with GPT disk label.
633
634       echo -e ',10M,L\n,10M,L\n,,+\n' | sfdisk /dev/sdc
635           Create three Linux partitions, with the default start, the size of
636           the first two partitions is 10MiB, and the last partition fills all
637           available space on the device.
638
639       echo -e 'size=10M, type=L\n size=10M, type=L\n size=+\n' | sfdisk
640       /dev/sdc
641           The same as the previous example, but in named-fields format.
642
643       echo -e 'type=swap' | sfdisk -N 3 /dev/sdc
644           Set type of the 3rd partition to 'swap'.
645
646       sfdisk --part-type /dev/sdc 3 swap
647           The same as the previous example, but without script use.
648
649       sfdisk --delete /dev/sdc 2
650           Delete 2nd partition.
651
652       echo "," | sfdisk -N 3 --move-data /dev/sdc
653           Enlarge 3rd partition in both directions, move start to use free
654           space before the partition and enlarge the size to use all free
655           space after to the partition, and move partition data too.
656

AUTHORS

658       Karel Zak <kzak@redhat.com>
659
660       The current sfdisk implementation is based on the original sfdisk from
661       Andries E. Brouwer.
662

SEE ALSO

664       fdisk(8), cfdisk(8), parted(8), partprobe(8), partx(8)
665

REPORTING BUGS

667       For bug reports, use the issue tracker at
668       https://github.com/util-linux/util-linux/issues.
669

AVAILABILITY

671       The sfdisk command is part of the util-linux package which can be
672       downloaded from Linux Kernel Archive
673       <https://www.kernel.org/pub/linux/utils/util-linux/>.
674
675
676
677util-linux 2.38                   2022-02-17                         SFDISK(8)
Impressum