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
282
283              echo '2048,' | sfdisk /dev/sdc --append
284
285              sfdisk /dev/sdc --reorder
286
287       --move-use-fsync
288           Use the fsync(2) system call after each write when moving data to a
289           new location by --move-data.
290
291       -o, --output list
292           Specify which output columns to print. Use --help to get a list of
293           all supported columns.
294
295           The default list of columns may be extended if list is specified in
296           the format +list (e.g., -o +UUID).
297
298       -q, --quiet
299           Suppress extra info messages.
300
301       -u, --unit S
302           Deprecated option. Only the sector unit is supported. This option
303           is not supported when using the --show-size command.
304
305       -X, --label type
306           Specify the disk label type (e.g., dos, gpt, ...). If this option
307           is not given, then sfdisk defaults to the existing label, but if
308           there is no label on the device yet, then the type defaults to dos.
309           The default or the current label may be overwritten by the "label:
310           <name>" script header line. The option --label does not force
311           sfdisk to create empty disk label (see the EMPTY DISK LABEL section
312           below).
313
314       -Y, --label-nested type
315           Force editing of a nested disk label. The primary disk label has to
316           exist already. This option allows editing for example a
317           hybrid/protective MBR on devices with GPT.
318
319       -w, --wipe when
320           Wipe filesystem, RAID and partition-table signatures from the
321           device, in order to avoid possible collisions. The argument when
322           can be auto, never or always. When this option is not given, the
323           default is auto, in which case signatures are wiped only when in
324           interactive mode; except the old partition-table signatures which
325           are always wiped before create a new partition-table if the
326           argument when is not never. The auto mode also does not wipe the
327           first sector (boot sector), it is necessary to use the always mode
328           to wipe this area. In all cases detected signatures are reported by
329           warning messages before a new partition table is created. See also
330           the wipefs(8) command.
331
332       -W, --wipe-partitions when
333           Wipe filesystem, RAID and partition-table signatures from a newly
334           created partition, in order to avoid possible collisions. The
335           argument when can be auto, never or always. When this option is not
336           given, the default is auto, in which case signatures are wiped only
337           when in interactive mode and after confirmation by user. In all
338           cases detected signatures are reported by warning messages after a
339           new partition is created. See also wipefs(8) command.
340
341       -v, --version
342           Display version information and exit.
343
344       -h, --help
345           Display help text and exit.
346

INPUT FORMATS

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

EMPTY DISK LABEL

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

BACKING UP THE PARTITION TABLE

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

COLORS

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

ENVIRONMENT

616       SFDISK_DEBUG=all
617           enables sfdisk debug output.
618
619       LIBFDISK_DEBUG=all
620           enables libfdisk debug output.
621
622       LIBBLKID_DEBUG=all
623           enables libblkid debug output.
624
625       LIBSMARTCOLS_DEBUG=all
626           enables libsmartcols debug output.
627
628       LOCK_BLOCK_DEVICE=<mode>
629           use exclusive BSD lock. The mode is "1" or "0". See --lock for more
630           details.
631

NOTES

633       Since version 2.26 sfdisk no longer provides the -R or --re-read option
634       to force the kernel to reread the partition table. Use blockdev
635       --rereadpt instead.
636
637       Since version 2.26 sfdisk does not provide the --DOS, --IBM,
638       --DOS-extended, --unhide, --show-extended, --cylinders, --heads,
639       --sectors, --inside-outer, --not-inside-outer options.
640

EXAMPLES

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

AUTHORS

669       Karel Zak <kzak@redhat.com>
670
671       The current sfdisk implementation is based on the original sfdisk from
672       Andries E. Brouwer.
673

SEE ALSO

675       fdisk(8), cfdisk(8), parted(8), partprobe(8), partx(8)
676

REPORTING BUGS

678       For bug reports, use the issue tracker at
679       https://github.com/util-linux/util-linux/issues.
680

AVAILABILITY

682       The sfdisk command is part of the util-linux package which can be
683       downloaded from Linux Kernel Archive
684       <https://www.kernel.org/pub/linux/utils/util-linux/>.
685
686
687
688util-linux 2.39.2                 2023-06-21                         SFDISK(8)
Impressum