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.
15
16       Since  version  2.26  sfdisk  supports MBR (DOS), GPT, SUN and SGI disk
17       labels, but no longer provides any  functionality  for  CHS  (Cylinder-
18       Head-Sector)  addressing.   CHS has never been important for Linux, and
19       this addressing concept does not make any sense for new devices.
20
21       sfdisk (since version 2.26) aligns the start and end of  partitions  to
22       block-device  I/O  limits  when  relative sizes are specified, when the
23       default values are used or when multiplicative suffixes (e.g. MiB)  are
24       used  for  sizes.  It is possible that partition size will be optimized
25       (reduced or enlarged) due to alignment if the start offset is specified
26       exactly  in  sectors  and  partition size relative or by multiplicative
27       suffixes.
28
29       The recommended way is not to specify start offsets at all and  specify
30       partition size in MiB, GiB (or so).  In this case sfdisk align all par‐
31       titions to block-device I/O limits (or when I/O limits  are  too  small
32       then  to  megabyte  boundary  to  keep  disk layout portable).  If this
33       default behaviour is unwanted (usually for very small partitions)  then
34       specify  offsets  and  sizes  in sectors.  In this case sfdisk entirely
35       follows specified numbers without any optimization.
36
37       sfdisk does not create the standard system partitions for SGI  and  SUN
38       disk  labels  like fdisk(8) does.  It is necessary to explicitly create
39       all partitions including whole-disk system partitions.
40
41       sfdisk uses BLKRRPART (reread partition table) ioctl to make sure  that
42       the  device  is  not  used  by  system or another tools (see also --no-
43       reread).  It's possible that this feature or  another  sfdisk  activity
44       races with udevd.  The recommended way how to avoid possible collisions
45       is to use exclusive flock for the whole-disk device to serialize device
46       access.  The exclusive lock will cause udevd to skip the event handling
47       on the device.  For example:
48
49              flock /dev/sdc sfdisk /dev/sdc
50
51       Note, this semantic is not currently supported by udevd for MD  and  DM
52       devices.
53
54

COMMANDS

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              The currently supported attribute bits  are:  RequiredPartition,
119              NoBlockIOProtocol,  LegacyBIOSBootable and GUID-specific bits in
120              the range from 48 to 63.  For example, the string  "RequiredPar‐
121              tition,50,51" sets three bits.
122
123       --part-label device partition-number [label]
124              Change  the  GPT partition name (label).  If label is not speci‐
125              fied, then print the current partition label.
126
127       --part-type device partition-number [type]
128              Change the partition type.  If type is not specified, then print
129              the  current  partition  type.  The type argument is hexadecimal
130              for MBR, or a GUID for  GPT.   For  backward  compatibility  the
131              options -c and --id have the same meaning as this one.
132
133       --part-uuid device partition-number [uuid]
134              Change  the  GPT partition UUID.  If uuid is not specified, then
135              print the current partition UUID.
136
137       -r, --reorder device
138              Renumber the partitions, ordering them by their start offset.
139
140       -s, --show-size [device...]
141              List the sizes of all or the specified devices in units of  1024
142              byte size.  This command is DEPRECATED in favour of blockdev(1).
143
144       -T, --list-types
145              Print  all  supported  types  for  the current disk label or the
146              label specified by --label.
147
148       -V, --verify [device...]
149              Test whether the partition table and partitions seem correct.
150
151

OPTIONS

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

INPUT FORMATS

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

EMPTY DISK LABEL

435       sfdisk  does  not create partition table without partitions by default.
436       The lines with partitions are expected in the script  by  default.  The
437       empty partition table has to be explicitly requested by "label: <name>"
438       script header line without any partitions lines. For example:
439
440              echo 'label: gpt' | sfdisk /dev/sdb
441
442       creates empty GPT partition table. Note that the --append disables this
443       feature.
444
445

BACKING UP THE PARTITION TABLE

447       It  is recommended to save the layout of your devices.  sfdisk supports
448       two ways.
449
450       Use the --dump option to save a description of the device layout  to  a
451       text  file.   The  dump format is suitable for later sfdisk input.  For
452       example:
453
454              sfdisk --dump /dev/sda > sda.dump
455
456       This can later be restored by:
457
458              sfdisk /dev/sda < sda.dump
459
460       If you want to do a full (binary) backup of all sectors where the  par‐
461       tition  table  is  stored, then use the --backup option.  It writes the
462       sectors to ~/sfdisk-<device>-<offset>.bak files.  The default  name  of
463       the  backup  file  can  be  changed with the --backup-file option.  The
464       backup files contain only raw data from the device.  Note that the same
465       concept of backup files is used by wipefs(8).  For example:
466
467              sfdisk --backup /dev/sda
468
469       The GPT header can later be restored by:
470
471              dd  if=~/sfdisk-sda-0x00000200.bak  of=/dev/sda  \
472                seek=$((0x00000200))  bs=1  conv=notrunc
473
474       Note that sfdisk since version 2.26 no longer provides the -I option to
475       restore sectors.  dd(1) provides all necessary functionality.
476
477

COLORS

479       Implicit coloring can be disabled by an empty  file  /etc/terminal-col‐
480       ors.d/sfdisk.disable.
481
482       See terminal-colors.d(5) for more details about colorization configura‐
483       tion. The logical color names supported by sfdisk are:
484
485       header The header of the output tables.
486
487       warn   The warning messages.
488
489       welcome
490              The welcome message.
491
492

NOTES

494       Since version 2.26 sfdisk no longer provides the -R or --re-read option
495       to  force  the  kernel  to  reread  the  partition table.  Use blockdev
496       --rereadpt instead.
497
498       Since  version  2.26  sfdisk  does  not  provide  the   --DOS,   --IBM,
499       --DOS-extended, --unhide, --show-extended, --cylinders, --heads, --sec‐
500       tors, --inside-outer, --not-inside-outer options.
501
502

ENVIRONMENT

504       SFDISK_DEBUG=all
505              enables sfdisk debug output.
506
507       LIBFDISK_DEBUG=all
508              enables libfdisk debug output.
509
510       LIBBLKID_DEBUG=all
511              enables libblkid debug output.
512
513       LIBSMARTCOLS_DEBUG=all
514              enables libsmartcols debug output.
515
516

SEE ALSO

518       fdisk(8), cfdisk(8), parted(8), partprobe(8), partx(8)
519
520

AUTHOR

522       Karel Zak <kzak@redhat.com>
523
524       The current sfdisk implementation is based on the original sfdisk  from
525       Andries E. Brouwer.
526
527

AVAILABILITY

529       The  sfdisk  command is part of the util-linux package and is available
530       from https://www.kernel.org/pub/linux/utils/util-linux/.
531
532
533
534util-linux                         June 2015                         SFDISK(8)
Impressum