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 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 another tools (see also --no-
45       reread).  It's possible that this feature or  another  sfdisk  activity
46       races with udevd.  The recommended way how to avoid possible collisions
47       is to use exclusive flock for the whole-disk device to serialize device
48       access.  The exclusive lock will cause udevd to skip the event handling
49       on the device.  For example:
50
51              flock /dev/sdc sfdisk /dev/sdc
52
53       Note, this semantic is not currently supported by udevd for MD  and  DM
54       devices.
55
56

COMMANDS

58       The commands are mutually exclusive.
59
60       [-N partition-number] device
61              The  default sfdisk command is to read the specification for the
62              desired partitioning of device from  standard  input,  and  then
63              create  a  partition  table according to the specification.  See
64              below for the description of  the  input  format.   If  standard
65              input is a terminal, then sfdisk starts an interactive session.
66
67              If  the  option -N is specified, then the changes are applied to
68              the partition addressed by  partition-number.   The  unspecified
69              fields of the partition are not modified.
70
71              Note  that it's possible to address an unused partition with -N.
72              For example, an MBR always contains 4 partitions, but the number
73              of  used partitions may be smaller.  In this case sfdisk follows
74              the default values from the partition table  and  does  not  use
75              built-in  defaults  for the unused partition given with -N.  See
76              also --append.
77
78       -A, --activate device [partition-number...]
79              Switch on the bootable flag for  the  specified  partitions  and
80              switch  off the bootable flag on all unspecified partitions. The
81              special placeholder '-' may be used  instead  of  the  partition
82              numbers to switch off the bootable flag on all partitions.
83
84              The  activation  command is supported for MBR and PMBR only.  If
85              GPT label is detected than sfdisk prints warning  and  automati‐
86              cally enter PMBR.
87
88              If  no  partition-number  is specified, then list the partitions
89              with an enabled flag.
90
91       --delete device [partition-number...]
92              Delete all or the specified partitions.
93
94       -d, --dump device
95              Dump the partitions of a device in a format that  is  usable  as
96              input  to  sfdisk.  See the section BACKING UP THE PARTITION TA‐
97              BLE.
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
106              sfdisk is not able to use JSON as input format.
107
108       -l, --list [device...]
109              List  the partitions of all or the specified devices.  This com‐
110              mand can be used together with --verify.
111
112       -F, --list-free [device...]
113              List the free  unpartitioned  areas  on  all  or  the  specified
114              devices.
115
116       --part-attrs device partition-number [attributes]
117              Change  the  GPT partition attribute bits.  If attributes is not
118              specified, then  print  the  current  partition  settings.   The
119              attributes argument is a comma- or space-delimited list of bits.
120              The currently supported attribute bits  are:  RequiredPartition,
121              NoBlockIOProtocol,  LegacyBIOSBootable and GUID-specific bits in
122              the range from 48 to 63.  For example, the string  "RequiredPar‐
123              tition,50,51" sets three bits.
124
125       --part-label device partition-number [label]
126              Change  the  GPT partition name (label).  If label is not speci‐
127              fied, then print the current partition label.
128
129       --part-type device partition-number [type]
130              Change the partition type.  If type is not specified, then print
131              the  current  partition  type.  The type argument is hexadecimal
132              for MBR, or a GUID for  GPT.   For  backward  compatibility  the
133              options -c and --id have the same meaning as this one.
134
135       --part-uuid device partition-number [uuid]
136              Change  the  GPT partition UUID.  If uuid is not specified, then
137              print the current partition UUID.
138
139       -r, --reorder device
140              Renumber the partitions, ordering them by their start offset.
141
142       -s, --show-size [device...]
143              List the sizes of all or the specified devices in units of  1024
144              byte size.  This command is DEPRECATED in favour of blockdev(8).
145
146       -T, --list-types
147              Print  all  supported  types  for  the current disk label or the
148              label specified by --label.
149
150       -V, --verify [device...]
151              Test whether the partition table and partitions seem correct.
152
153

OPTIONS

155       -a, --append
156              Don't create a new partition table, but only append  the  speci‐
157              fied partitions.
158
159       -b, --backup
160              Back  up the current partition table sectors before starting the
161              partitioning.     The    default    backup    file    name    is
162              ~/sfdisk-<device>-<offset>.bak;  to  use another name see option
163              -O, --backup-file.
164
165       --color[=when]
166              Colorize the output.  The optional argument when  can  be  auto,
167              never  or  always.  If the when argument is omitted, it defaults
168              to auto.  The colors can be disabled; for the  current  built-in
169              default see the --help output.  See also the COLORS section.
170
171       -f, --force
172              Disable all consistency checking.
173
174       --Linux
175              Deprecated  and ignored option.  Partitioning that is compatible
176              with Linux (and other modern operating systems) is the default.
177
178       -n, --no-act
179              Do everything except writing to the device.
180
181       --no-reread
182              Do not check through the re-read-partition-table  ioctl  whether
183              the device is in use.
184
185       --no-tell-kernel
186              Don't  tell  the  kernel about partition changes. This option is
187              recommended together with --no-reread to modify a  partition  on
188              used  disk.  The  modified  partition  should not be used (e.g.,
189              mounted).
190
191       -O, --backup-file path
192              Override the default backup file name.   Note  that  the  device
193              name and offset are always appended to the file name.
194
195       --move-data[=path]
196              Move  data  after  partition relocation, for example when moving
197              the beginning of a partition to another place on the disk.   The
198              size  of  the  partition has to remain the same, the new and old
199              location may overlap.  This option requires option -N  in  order
200              to be processed on one specific partition only.
201
202              The optional path specifies log file name. The log file contains
203              information about all read/write  operations  on  the  partition
204              data.  The  word  "@default"  as  a  path  forces  sfdisk to use
205              ~/sfdisk-<devname>.move for the log.  The log is optional  since
206              v2.35.
207
208              Note  that  this operation is risky and not atomic. Don't forget
209              to backup your data!
210
211              See also --move-use-fsync.
212
213              In the example below, the first command creates  a  100MiB  free
214              area  before  the first partition and moves the data it contains
215              (e.g., a filesystem), the next command creates a  new  partition
216              from  the  free  space  (at  offset  2048), and the last command
217              reorders partitions to match disk order (the original sdc1  will
218              become sdc2).
219
220              echo '+100M,' | sfdisk --move-data /dev/sdc -N 1
221              echo '2048,' | sfdisk /dev/sdc --append
222              sfdisk /dev/sdc --reorder
223
224
225
226       --move-use-fsync
227              Use  fsync  system call after each write when move dara to a new
228              location by --move-data.
229
230       -o, --output list
231              Specify which output columns to print.  Use --help to get a list
232              of all supported columns.
233
234              The default list of columns may be extended if list is specified
235              in the format +list (e.g., -o +UUID).
236
237       -q, --quiet
238              Suppress extra info messages.
239
240       -u, --unit S
241              Deprecated option.  Only the  sector  unit  is  supported.  This
242              option is not supported when using the --show-size command.
243
244       -X, --label type
245              Specify  the  disk  label  type  (e.g., dos, gpt, ...).  If this
246              option is not given, then sfdisk defaults to the existing label,
247              but  if  there  is  no  label  on  the device yet, then the type
248              defaults to dos. The default or the current label may  be  over‐
249              written  by  the  "label: <name>" script header line. The option
250              --label does not force sfdisk to create empty  disk  label  (see
251              the EMPTY DISK LABEL section below).
252
253       -Y, --label-nested type
254              Force  editing  of  a nested disk label.  The primary disk label
255              has to exist already.  This option allows to edit for example  a
256              hybrid/protective MBR on devices with GPT.
257
258
259       -w, --wipe when
260              Wipe  filesystem,  RAID  and partition-table signatures from the
261              device, in order to avoid  possible  collisions.   The  argument
262              when  can  be  auto,  never  or always.  When this option is not
263              given, the default is auto, in which case signatures  are  wiped
264              only  when  in  interactive mode; except the old partition-table
265              signatures which are always wiped before create a new partition-
266              table  if  the argument when is not never. In all cases detected
267              signatures are reported by warning messages before a new  parti‐
268              tion table is created.  See also wipefs(8) command.
269
270
271       -W, --wipe-partitions when
272              Wipe  filesystem,  RAID  and  partition-table  signatures from a
273              newly created partitions, in order to avoid possible collisions.
274              The  argument  when  can  be  auto,  never or always.  When this
275              option is not given, the default is auto, in which  case  signa‐
276              tures  are wiped only when in interactive mode and after confir‐
277              mation by user.  In all cases detected signatures  are  reported
278              by  warning messages after a new partition is created.  See also
279              wipefs(8) command.
280
281
282       -v, --version
283              Display version information and exit.
284
285       -h, --help
286              Display help text and exit.
287
288

INPUT FORMATS

290       sfdisk supports two input formats and generic header lines.
291
292       Header lines
293              The optional header lines specify generic information that apply
294              to the partition table.  The header-line format is:
295
296                     <name>: <value>
297
298              The currently recognized headers are:
299
300                     unit   Specify the partitioning unit.  The only supported
301                            unit is sectors.
302
303                     label  Specify the partition table type.  For example dos
304                            or gpt.
305
306                     label-id
307                            Specify the partition table identifier.  It should
308                            be a  hexadecimal number (with a  0x  prefix)  for
309                            MBR and a UUID for GPT.
310
311                     first-lba
312                            Specify  the  first  usable  sector for GPT parti‐
313                            tions.
314
315                     last-lba
316                            Specify the last usable sector for GPT partitions.
317
318                     table-length
319                            Specify the maximal number of GPT partitions.
320
321                     grain  Specify minimal size in bytes  used  to  calculate
322                            partitions  alignment.   The  default  is 1MiB and
323                            it's strongly recommended to use the default.   Do
324                            not modify this variable if you're not sure.
325
326                     sector-size
327                            Specify  sector  size.  This header is informative
328                            only and it is not used when sfdisk creates a  new
329                            partition table, in this case the real device spe‐
330                            cific value is always used and  sector  size  from
331                            the dump is ignored.
332
333              Note  that  it  is  only possible to use header lines before the
334              first partition is specified in the input.
335
336       Unnamed-fields format
337
338                     start size type bootable
339
340              where each line fills one partition descriptor.
341
342              Fields are separated by whitespace, comma or semicolon  possibly
343              followed  by  whitespace;  initial  and  trailing  whitespace is
344              ignored.  Numbers can be octal, decimal or hexadecimal;  decimal
345              is  the  default.  When a field is absent, empty or specified as
346              '-' a default value is used.  But when the -N option  (change  a
347              single  partition)  is  given, the default for each field is its
348              previous value.
349
350              The default value of start  is  the  first  non-assigned  sector
351              aligned  according to device I/O limits.  The default start off‐
352              set for the first partition is 1 MiB.  The offset  may  be  fol‐
353              lowed  by  the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB,
354              EiB, ZiB and YiB) then the number is interpreted  as  offset  in
355              bytes.
356
357              The default value of size indicates "as much as possible"; i.e.,
358              until the next partition or end-of-device.  A numerical argument
359              is by default interpreted as a number of sectors, however if the
360              size is followed by one of  the  multiplicative  suffixes  (KiB,
361              MiB,  GiB, TiB, PiB, EiB, ZiB and YiB) then the number is inter‐
362              preted as the size of the partition in  bytes  and  it  is  then
363              aligned  according  to the device I/O limits.  A '+' can be used
364              instead of a number to enlarge the partition as much  as  possi‐
365              ble.   Note '+' is equivalent to the default behaviour for a new
366              partition; existing partitions will be resized as required.
367
368              The partition type is given in hex for MBR (DOS), without the 0x
369              prefix, a GUID string for GPT, or a shortcut:
370
371                     L      Linux;      means      83      for     MBR     and
372                            0FC63DAF-8483-4772-8E79-3D69D8477DE4 for GPT.
373
374                     S      swap  area;  means  82  for  MBR   and   0657FD6D-
375                            A4AB-43C4-84E5-0933C84B4F4F for GPT
376
377                     E      extended partition; means 5 for MBR
378
379                     H      home                partition;               means
380                            933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPT
381
382                     X      linux extended partition; means 85 for MBR.
383
384                     U      EFI  System  partition,  means  EF  for  MBR   and
385                            C12A7328-F81F-11D2-BA4B-00A0C93EC93B for GPT
386
387                     R      Linux    RAID;    means    FD    for    MBR    and
388                            A19D880F-05FC-4D3B-A006-743F0F84911E for GPT
389
390                     V      LVM;      means      8E      for      MBR      and
391                            E6D6D379-F507-44C2-A23C-238F2A3DF928 for GPT
392
393              The default type value is L
394
395              bootable  is  specified  as [*|-], with as default not-bootable.
396              The value of this field is irrelevant for  Linux  -  when  Linux
397              runs  it  has been booted already - but it might play a role for
398              certain boot loaders and for other operating systems.
399
400       Named-fields format
401              This format is more readable, robust, extensible and  allows  to
402              specify  additional  information  (e.g.,  a UUID).  It is recom‐
403              mended to use this format to keep your scripts more readable.
404
405                     [device :] name[=value], ...
406
407              The device field is optional.   sfdisk  extracts  the  partition
408              number  from  the  device name.  It allows to specify the parti‐
409              tions in random order.  This functionality  is  mostly  used  by
410              --dump.  Don't use it if you are not sure.
411
412              The  value  can  be between quotation marks (e.g., name="This is
413              partition name").  The currently supported fields are:
414
415                     start=number
416                            The first non-assigned sector aligned according to
417                            device  I/O  limits.  The default start offset for
418                            the first partition is 1 MiB. The  offset  may  be
419                            followed by the multiplicative suffixes (KiB, MiB,
420                            GiB, TiB, PiB, EiB, ZiB and YiB) then  the  number
421                            is interpreted as offset in bytes.
422
423                     size=number
424                            Specify the partition size in sectors.  The number
425                            may be followed  by  the  multiplicative  suffixes
426                            (KiB,  MiB, GiB, TiB, PiB, EiB, ZiB and YiB), then
427                            it's interpreted as size in bytes and the size  is
428                            aligned according to device I/O limits.
429
430                     bootable
431                            Mark the partition as bootable.
432
433                     attrs=string
434                            Partition   attributes,   usually   GPT  partition
435                            attribute bits.  See --part-attrs for more details
436                            about the GPT-bits string format.
437
438                     uuid=string
439                            GPT partition UUID.
440
441                     name=string
442                            GPT partition name.
443
444                     type=code
445                            A  hexadecimal number (without 0x) for an MBR par‐
446                            tition, a GUID for a GPT partition, or a  shortcut
447                            as  for  unnamed-fields format.  For backward com‐
448                            patibility the Id= field has the same meaning.
449
450

EMPTY DISK LABEL

452       sfdisk does not create partition table without partitions  by  default.
453       The  lines  with  partitions are expected in the script by default. The
454       empty partition table has to be explicitly requested by "label: <name>"
455       script header line without any partitions lines. For example:
456
457              echo 'label: gpt' | sfdisk /dev/sdb
458
459       creates empty GPT partition table. Note that the --append disables this
460       feature.
461
462

BACKING UP THE PARTITION TABLE

464       It is recommended to save the layout of your devices.  sfdisk  supports
465       two ways.
466
467       Use  the  --dump option to save a description of the device layout to a
468       text file.  The dump format is suitable for later  sfdisk  input.   For
469       example:
470
471              sfdisk --dump /dev/sda > sda.dump
472
473       This can later be restored by:
474
475              sfdisk /dev/sda < sda.dump
476
477       If  you want to do a full (binary) backup of all sectors where the par‐
478       tition table is stored, then use the --backup option.   It  writes  the
479       sectors  to  ~/sfdisk-<device>-<offset>.bak files.  The default name of
480       the backup file can be changed  with  the  --backup-file  option.   The
481       backup files contain only raw data from the device.  Note that the same
482       concept of backup files is used by wipefs(8).  For example:
483
484              sfdisk --backup /dev/sda
485
486       The GPT header can later be restored by:
487
488              dd  if=~/sfdisk-sda-0x00000200.bak  of=/dev/sda  \
489                seek=$((0x00000200))  bs=1  conv=notrunc
490
491       Note that sfdisk since version 2.26 no longer provides the -I option to
492       restore sectors.  dd(1) provides all necessary functionality.
493
494

COLORS

496       Implicit  coloring  can be disabled by an empty file /etc/terminal-col‐
497       ors.d/sfdisk.disable.
498
499       See terminal-colors.d(5) for more details about colorization configura‐
500       tion. The logical color names supported by sfdisk are:
501
502       header The header of the output tables.
503
504       warn   The warning messages.
505
506       welcome
507              The welcome message.
508
509

NOTES

511       Since version 2.26 sfdisk no longer provides the -R or --re-read option
512       to force the kernel  to  reread  the  partition  table.   Use  blockdev
513       --rereadpt instead.
514
515       Since   version   2.26  sfdisk  does  not  provide  the  --DOS,  --IBM,
516       --DOS-extended, --unhide, --show-extended, --cylinders, --heads, --sec‐
517       tors, --inside-outer, --not-inside-outer options.
518
519

ENVIRONMENT

521       SFDISK_DEBUG=all
522              enables sfdisk debug output.
523
524       LIBFDISK_DEBUG=all
525              enables libfdisk debug output.
526
527       LIBBLKID_DEBUG=all
528              enables libblkid debug output.
529
530       LIBSMARTCOLS_DEBUG=all
531              enables libsmartcols debug output.
532
533

SEE ALSO

535       fdisk(8), cfdisk(8), parted(8), partprobe(8), partx(8)
536
537

AUTHOR

539       Karel Zak <kzak@redhat.com>
540
541       The  current sfdisk implementation is based on the original sfdisk from
542       Andries E. Brouwer.
543
544

AVAILABILITY

546       The sfdisk command is part of the util-linux package and  is  available
547       from https://www.kernel.org/pub/linux/utils/util-linux/.
548
549
550
551util-linux                         June 2015                         SFDISK(8)
Impressum