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              If  no  partition-number  is specified, then list the partitions
83              with an enabled flag.
84
85       --delete device [partition-number...]
86              Delete all or the specified partitions.
87
88       -d, --dump device
89              Dump the partitions of a device in a format that  is  usable  as
90              input  to  sfdisk.  See the section BACKING UP THE PARTITION TA‐
91              BLE.
92
93       -g, --show-geometry [device...]
94              List the geometry of all or the specified devices. For  backward
95              compatibility  the deprecated option --show-pt-geometry have the
96              same meaning as this one.
97
98       -J, --json device
99              Dump the partitions of a  device  in  JSON  format.   Note  that
100              sfdisk is not able to use JSON as input format.
101
102       -l, --list [device...]
103              List  the partitions of all or the specified devices.  This com‐
104              mand can be used together with --verify.
105
106       -F, --list-free [device...]
107              List the free  unpartitioned  areas  on  all  or  the  specified
108              devices.
109
110       --part-attrs device partition-number [attributes]
111              Change  the  GPT partition attribute bits.  If attributes is not
112              specified, then  print  the  current  partition  settings.   The
113              attributes argument is a comma- or space-delimited list of bits.
114              The currently supported attribute bits  are:  RequiredPartition,
115              NoBlockIOProtocol,  LegacyBIOSBootable and GUID-specific bits in
116              the range from 48 to 63.  For example, the string  "RequiredPar‐
117              tition,50,51" sets three bits.
118
119       --part-label device partition-number [label]
120              Change  the  GPT partition name (label).  If label is not speci‐
121              fied, then print the current partition label.
122
123       --part-type device partition-number [type]
124              Change the partition type.  If type is not specified, then print
125              the  current  partition  type.  The type argument is hexadecimal
126              for MBR, or a GUID for  GPT.   For  backward  compatibility  the
127              options -c and --id have the same meaning as this one.
128
129       --part-uuid device partition-number [uuid]
130              Change  the  GPT partition UUID.  If uuid is not specified, then
131              print the current partition UUID.
132
133       -r, --reorder device
134              Renumber the partitions, ordering them by their start offset.
135
136       -s, --show-size [device...]
137              List the sizes of all or the specified devices in units of  1024
138              byte size.  This command is DEPRECATED in favour of blockdev(1).
139
140       -T, --list-types
141              Print  all  supported  types  for  the current disk label or the
142              label specified by --label.
143
144       -V, --verify [device...]
145              Test whether the partition table and partitions seem correct.
146
147

OPTIONS

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

INPUT FORMATS

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

EMPTY DISK LABEL

416       sfdisk  does  not create partition table without partitions by default.
417       The lines with partitions are expected in the script  by  default.  The
418       empty partition table has to be explicitly requested by "label: <name>"
419       script header line without any partitions lines. For example:
420
421              echo 'label: gpt' | sfdisk /dev/sdb
422
423       creates empty GPT partition table. Note that the --append disables this
424       feature.
425
426

BACKING UP THE PARTITION TABLE

428       It  is recommended to save the layout of your devices.  sfdisk supports
429       two ways.
430
431       Use the --dump option to save a description of the device layout  to  a
432       text  file.   The  dump format is suitable for later sfdisk input.  For
433       example:
434
435              sfdisk --dump /dev/sda > sda.dump
436
437       This can later be restored by:
438
439              sfdisk /dev/sda < sda.dump
440
441       If you want to do a full (binary) backup of all sectors where the  par‐
442       tition  table  is  stored, then use the --backup option.  It writes the
443       sectors to ~/sfdisk-<device>-<offset>.bak files.  The default  name  of
444       the  backup  file  can  be  changed with the --backup-file option.  The
445       backup files contain only raw data from the device.  Note that the same
446       concept of backup files is used by wipefs(8).  For example:
447
448              sfdisk --backup /dev/sda
449
450       The GPT header can later be restored by:
451
452              dd  if=~/sfdisk-sda-0x00000200.bak  of=/dev/sda  \
453                seek=$((0x00000200))  bs=1  conv=notrunc
454
455       Note that sfdisk since version 2.26 no longer provides the -I option to
456       restore sectors.  dd(1) provides all necessary functionality.
457
458

COLORS

460       Implicit coloring can be disabled by an empty  file  /etc/terminal-col‐
461       ors.d/sfdisk.disable.
462
463       See terminal-colors.d(5) for more details about colorization configura‐
464       tion. The logical color names supported by sfdisk are:
465
466       header The header of the output tables.
467
468       warn   The warning messages.
469
470       welcome
471              The welcome message.
472
473

NOTES

475       Since version 2.26 sfdisk no longer provides the -R or --re-read option
476       to  force  the  kernel  to  reread  the  partition table.  Use blockdev
477       --rereadpt instead.
478
479       Since  version  2.26  sfdisk  does  not  provide  the   --DOS,   --IBM,
480       --DOS-extended, --unhide, --show-extended, --cylinders, --heads, --sec‐
481       tors, --inside-outer, --not-inside-outer options.
482
483

ENVIRONMENT

485       SFDISK_DEBUG=all
486              enables sfdisk debug output.
487
488       LIBFDISK_DEBUG=all
489              enables libfdisk debug output.
490
491       LIBBLKID_DEBUG=all
492              enables libblkid debug output.
493
494       LIBSMARTCOLS_DEBUG=all
495              enables libsmartcols debug output.
496
497

SEE ALSO

499       fdisk(8), cfdisk(8), parted(8), partprobe(8), partx(8)
500
501

AUTHOR

503       Karel Zak <kzak@redhat.com>
504
505       The current sfdisk implementation is based on the original sfdisk  from
506       Andries E. Brouwer.
507
508

AVAILABILITY

510       The  sfdisk  command is part of the util-linux package and is available
511       from https://www.kernel.org/pub/linux/utils/util-linux/.
512
513
514
515util-linux                         June 2015                         SFDISK(8)
Impressum