summaryrefslogtreecommitdiffstats
path: root/disk-utils/sfdisk.8
blob: ff54760ca08e8762d7a5e7ccd3c23ae55fba5ae7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
.\" sfdisk.8 -- man page for sfdisk
.\" Copyright (C) 2014 Karel Zak <kzak@redhat.com>
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.TH SFDISK 8 "June 2015" "util-linux" "System Administration"
.SH NAME
sfdisk \- display or manipulate a disk partition table
.SH SYNOPSIS
.B sfdisk
[options]
.I device
.RB [ \-N
.IR partition-number ]
.sp
.B sfdisk
[options]
.I command
.SH DESCRIPTION
.B sfdisk
is a script-oriented tool for partitioning any block device.

Since version 2.26
.B sfdisk
supports MBR (DOS), GPT, SUN and SGI disk labels, but no longer provides any
functionality for CHS (Cylinder-Head-Sector) addressing.  CHS has
never been important for Linux, and this addressing concept does not make any
sense for new devices.
.sp
.B sfdisk
(since version 2.26)
.B aligns the start and end of partitions
to block-device I/O limits when relative sizes are specified, when the default
values are used or when multiplicative suffixes (e.g. MiB) are used for sizes.
It is possible that partition size will be optimized (reduced or enlarged) due
to alignment if the start offset is specified exactly in sectors and partition
size relative or by multiplicative suffixes.

The recommended way is not to specify start offsets at all and specify
partition size in MiB, GiB (or so).  In this case sfdisk align all partitions
to block-device I/O limits (or when I/O limits are too small then to megabyte
boundary to keep disk layout portable).  If this default behaviour is unwanted
(usually for very small partitions) then specify offsets and sizes in
sectors.  In this case sfdisk entirely follows specified numbers without any
optimization.
.sp
.B sfdisk
does not create the standard system partitions for SGI and SUN disk labels like
.BR fdisk (8)
does.
It is necessary to explicitly create all partitions including whole-disk system
partitions.

.B sfdisk
uses BLKRRPART (reread partition table) ioctl to make sure that the device is
not used by system or another tools (see also --no-reread).  It's possible that
this feature or another sfdisk activity races with \fBudevd\fR.  The recommended way
how to avoid possible collisions is to use exclusive flock for the whole-disk
device to serialize device access.  The exclusive lock will cause udevd to skip
the event handling on the device.  For example:
.RS
.sp
.nf
.B "flock /dev/sdc sfdisk /dev/sdc"
.fi
.sp
.RE
Note, this semantic is not currently supported by udevd for MD and DM devices.

.SH COMMANDS
The commands are mutually exclusive.
.TP
.RB [ \-N " \fIpartition-number\fR] " \fIdevice\fR
The default \fBsfdisk\fR command is to read the specification for the desired
partitioning of \fIdevice\fR from standard input, and then create a partition
table according to the specification.  See below for the description of the
input format.  If standard input is a terminal, then \fBsfdisk\fR starts an
interactive session.
.sp
If the option \fB\-N\fR is specified, then the changes are applied to
the partition addressed by \fIpartition-number\fR.  The unspecified fields
of the partition are not modified.
.sp
Note that it's possible to address an unused partition with \fB\-N\fR.
For example, an MBR always contains 4 partitions, but the number of used
partitions may be smaller.  In this case \fBsfdisk\fR follows the default
values from the partition table and does not use built-in defaults for the
unused partition given with \fB\-N\fR.  See also \fB\-\-append\fR.
.TP
.BR \-A , " \-\-activate \fIdevice " [ \fIpartition-number...]
Switch on the bootable flag for the specified partitions and switch off the
bootable flag on all unspecified partitions. The special placeholder '-'
may be used instead of the partition numbers to switch off the bootable flag
on all partitions.

The activation command is supported for MBR and PMBR only.  If GPT label is detected
than sfdisk prints warning and automatically enter PMBR.

If no \fIpartition-number\fR is specified, then list the partitions with an
enabled flag.
.TP
.BR "\-\-delete \fIdevice " [ \fIpartition-number ...]
Delete all or the specified partitions.
.TP
.BR \-d , " \-\-dump " \fIdevice\fR
Dump the partitions of a device in a format that is usable as input to \fBsfdisk\fR.
See the section \fBBACKING UP THE PARTITION TABLE\fR.
.TP
.BR \-g , " \-\-show\-geometry " [ \fIdevice ...]
List the geometry of all or the specified devices. For backward
compatibility the deprecated option \fB\-\-show\-pt\-geometry\fR have the same
meaning as this one.
.TP
.BR \-J , " \-\-json " \fIdevice\fR
Dump the partitions of a device in JSON format.  Note that \fBsfdisk\fR is
not able to use JSON as input format.
.TP
.BR \-l , " \-\-list " [ \fIdevice ...]
List the partitions of all or the specified devices.  This command can be used
together with \fB\-\-verify\fR.
.TP
.BR \-F , " \-\-list-free " [ \fIdevice ...]
List the free unpartitioned areas on all or the specified devices.
.TP
.BR "\-\-part\-attrs \fIdevice partition-number " [ \fIattributes ]
Change the GPT partition attribute bits.  If \fIattributes\fR is not specified,
then print the current partition settings.  The \fIattributes\fR argument is a
comma- or space-delimited list of bits.  The currently supported attribute
bits are: RequiredPartition, NoBlockIOProtocol, LegacyBIOSBootable
and GUID-specific bits in the range from 48 to 63.  For example, the string
"RequiredPartition,50,51" sets three bits.
.TP
.BR "\-\-part\-label \fIdevice partition-number " [ \fIlabel ]
Change the GPT partition name (label).  If \fIlabel\fR is not specified,
then print the current partition label.
.TP
.BR "\-\-part\-type \fIdevice partition-number " [ \fItype ]
Change the partition type.  If \fItype\fR is not specified, then print the
current partition type.  The \fItype\fR argument is hexadecimal for MBR,
or a GUID for GPT.  For backward compatibility the options \fB\-c\fR and
\fB\-\-id\fR have the same meaning as this one.
.TP
.BR "\-\-part\-uuid \fIdevice partition-number " [ \fIuuid ]
Change the GPT partition UUID.  If \fIuuid\fR is not specified,
then print the current partition UUID.
.TP
.BR \-r , " \-\-reorder " \fIdevice
Renumber the partitions, ordering them by their start offset.
.TP
.BR \-s , " \-\-show\-size " [ \fIdevice ...]
List the sizes of all or the specified devices in units of 1024 byte size.
This command is DEPRECATED in favour of
.BR blockdev (1).
.TP
.BR \-T , " \-\-list\-types"
Print all supported types for the current disk label or the label specified by
\fB\-\-label\fR.
.TP
.BR \-V , " \-\-verify " [ \fIdevice ...]
Test whether the partition table and partitions seem correct.

.SH OPTIONS
.TP
.BR \-a , " \-\-append"
Don't create a new partition table, but only append the specified partitions.
.TP
.BR \-b , " \-\-backup"
Back up the current partition table sectors before starting the partitioning.
The default backup file name is ~/sfdisk-<device>-<offset>.bak; to use another
name see option \fB\-O\fR, \fB\-\-backup\-file\fR.
.TP
.BR \-\-color [ =\fIwhen ]
Colorize the output.  The optional argument \fIwhen\fP
can be \fBauto\fR, \fBnever\fR or \fBalways\fR.  If the \fIwhen\fR argument is omitted,
it defaults to \fBauto\fR.  The colors can be disabled; for the current built-in default
see the \fB\-\-help\fR output.  See also the \fBCOLORS\fR section.
.TP
.BR \-f , " \-\-force"
Disable all consistency checking.
.TP
.B \-\-Linux
Deprecated and ignored option.  Partitioning that is compatible with
Linux (and other modern operating systems) is the default.
.TP
.BR \-n , " \-\-no\-act"
Do everything except writing to the device.
.TP
.B \-\-no\-reread
Do not check through the re-read-partition-table ioctl whether the device is in use.
.TP
.B \-\-no\-tell\-kernel
Don't tell the kernel about partition changes. This option is recommended together
with \fB\-\-no\-reread\fR to modify a partition on used disk. The modified partition
should not be used (e.g. mounted).
.TP
.BR \-O , " \-\-backup\-file " \fIpath
Override the default backup file name.  Note that the device name and offset
are always appended to the file name.
.TP
.BR \-\-move-data [ =\fIpath ]
Move data after partition relocation, for example when moving the beginning
of a partition to another place on the disk.  The size of the partition has
to remain the same, the new and old location may overlap.  This option requires
option \fB\-N\fR in order to be processed on one specific partition only.

The \fIpath\fR overrides the default log file name
(the default is ~/sfdisk-<devname>.move).  The log file contains information
about all read/write operations on the partition data.

Note that this operation is risky and not atomic. \fBDon't forget to backup your data!\fR

In the example below, the first command creates a 100MiB free area before
the first partition and moves the data it contains (e.g. a filesystem),
the next command creates a new partition from the free space (at offset 2048),
and the last command reorders partitions to match disk order
(the original sdc1 will become sdc2).
.RS
.sp
.B "echo '+100M,' | sfdisk --move-data /dev/sdc -N 1"
.br
.B "echo '2048,' | sfdisk /dev/sdc --append
.br
.B sfdisk /dev/sdc --reorder
.sp
.RE

.TP
.BR \-o , " \-\-output " \fIlist
Specify which output columns to print.  Use
.B \-\-help
to get a list of all supported columns.
.sp
The default list of columns may be extended if \fIlist\fP is
specified in the format \fI+list\fP (e.g. \fB-o +UUID\fP).
.TP
.BR \-q , " \-\-quiet"
Suppress extra info messages.
.TP
.BR \-u , " \-\-unit S"
Deprecated option.  Only the sector unit is supported. This option is not
supported when using the --show-size command.
.TP
.BR \-X , " \-\-label " \fItype
Specify the disk label type (e.g. \fBdos\fR, \fBgpt\fR, ...).  If this option
is not given, then \fBsfdisk\fR defaults to the existing label, but if there
is no label on the device yet, then the type defaults to \fBdos\fR. The default
or the current label may be overwritten by the "label: <name>" script header
line. The option \fB\-\-label\fR does not force \fBsfdisk\fR to create empty
disk label (see the \fBEMPTY DISK LABEL\fR section below).
.TP
.BR \-Y , " \-\-label\-nested " \fItype
Force editing of a nested disk label.  The primary disk label has to exist already.
This option allows to edit for example a hybrid/protective MBR on devices with GPT.

.TP
.BR -w , " \-\-wipe "\fIwhen
Wipe filesystem, RAID and partition-table signatures from the device, in order
to avoid possible collisions.  The argument \fIwhen\fR can be \fBauto\fR,
\fBnever\fR or \fBalways\fR.  When this option is not given, the default is
\fBauto\fR, in which case signatures are wiped only when in interactive mode;
except the old partition-table signatures which are always wiped before create
a new partition-table if the argument \fIwhen\fR is not \fBnever\fR. In all
cases detected signatures are reported by warning messages before a new
partition table is created.  See also
.BR wipefs (8)
command.

.TP
.BR -W , " \-\-wipe-partitions "\fIwhen
Wipe filesystem, RAID and partition-table signatures from a newly created
partitions, in order to avoid possible collisions.  The argument \fIwhen\fR can
be \fBauto\fR, \fBnever\fR or \fBalways\fR.  When this option is not given, the
default is \fBauto\fR, in which case signatures are wiped only when in
interactive mode and after confirmation by user.  In all cases detected
signatures are reported by warning messages after a new partition is created.
See also
.BR wipefs (8)
command.

.TP
.BR \-v , " \-\-version"
Display version information and exit.
.TP
.BR \-h , " \-\-help"
Display help text and exit.

.SH "INPUT FORMATS"
.B sfdisk
supports two input formats and generic header lines.

.B Header lines
.RS
The optional header lines specify generic information that apply to the partition
table.  The header-line format is:
.RS
.sp
.B "<name>: <value>"
.sp
.RE
The currently recognized headers are:
.RS
.TP
.B unit
Specify the partitioning unit.  The only supported unit is \fBsectors\fR.
.TP
.B label
Specify the partition table type.  For example \fBdos\fR or \fBgpt\fR.
.TP
.B label-id
Specify the partition table identifier.  It should be a  hexadecimal number
(with a 0x prefix) for MBR and a UUID for GPT.
.TP
.B first-lba
Specify the first usable sector for GPT partitions.
.TP
.B last-lba
Specify the last usable sector for GPT partitions.
.TP
.B table-length
Specify the maximal number of GPT partitions.
.TP
.B grain
Specify minimal size in bytes used to calculate partitions alignment.  The
default is 1MiB and it's strongly recommended to use the default.  Do not
modify this variable if you're not sure.
.RE
.sp
Note that it is only possible to use header lines before the first partition
is specified in the input.
.RE

.B Unnamed-fields format
.RS
.RS
.sp
.I start size type bootable
.sp
.RE
where each line fills one partition descriptor.
.sp
Fields are separated by whitespace, comma or semicolon possibly
followed by whitespace; initial and trailing whitespace is ignored.
Numbers can be octal, decimal or hexadecimal; decimal is the default.
When a field is absent, empty or specified as '-' a default value is
used.  But when the \fB-N\fR option (change a single partition) is
given, the default for each field is its previous value.
.sp
The default value of
.I start
is the first non-assigned sector aligned according to device I/O limits.
The default start offset for the first partition is 1 MiB.  The offset may
be followed by the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB,
EiB, ZiB and YiB) then the number is interpreted as offset in bytes.
.sp
The default value of
.I size
indicates "as much as possible"; i.e. until the next partition or
end-of-device.  A numerical argument is by default interpreted as a
number of sectors, however if the size is followed by one of the
multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB)
then the number is interpreted as the size of the partition in bytes
and it is then aligned according to the device I/O limits.  A '+' can
be used instead of a number to enlarge the partition as much as
possible.  Note '+' is equivalent to the default behaviour for a new
partition; existing partitions will be resized as required.
.sp
The partition
.I type
is given in hex for MBR (DOS), without the 0x prefix, a GUID string for GPT, or
a shortcut:
.RS
.TP
.B L
Linux; means 83 for MBR and 0FC63DAF-8483-4772-8E79-3D69D8477DE4 for GPT.
.TP
.B S
swap area; means 82 for MBR and 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F for GPT
.TP
.B E
extended partition; means 5 for MBR
.TP
.B H
home partition; means 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 for GPT
.TP
.B X
linux extended partition; means 85 for MBR.
.TP
.B U
EFI System partition, means EF for MBR and C12A7328-F81F-11D2-BA4B-00A0C93EC93B for GPT
.TP
.B R
Linux RAID; means FD for MBR and A19D880F-05FC-4D3B-A006-743F0F84911E for GPT
.TP
.B V
LVM; means 8E for MBR and E6D6D379-F507-44C2-A23C-238F2A3DF928 for GPT
.RE
.PP
The default
.I type
value is
.I L

.I bootable
is specified as [\fB*\fR|\fB-\fR], with as default not-bootable.  The
value of this field is irrelevant for Linux - when Linux runs it has
been booted already - but ir might play a role for certain boot
loaders and for other operating systems.
.RE

.B Named-fields format
.RS
This format is more readable, robust, extensible and allows to specify additional
information (e.g. a UUID).  It is recommended to use this format to keep your scripts
more readable.
.RS
.sp
.RI [ "device \fB:" ] " name" [\fB= value "], ..."
.sp
.RE
The
.I device
field is optional.  \fBsfdisk\fR extracts the partition number from the
device name.  It allows to specify the partitions in random order.
This functionality is mostly used by \fB\-\-dump\fR.
Don't use it if you are not sure.

The
.I value
can be between quotation marks (e.g. name="This is partition name").
The currently supported fields are:
.RS
.TP
.BI start= number
The first non-assigned sector aligned according to device I/O limits.  The default
start offset for the first partition is 1 MiB. The offset may be followed by
the multiplicative suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB) then
the number is interpreted as offset in bytes.
.TP
.BI size= number
Specify the partition size in sectors.  The number may be followed by the multiplicative
suffixes (KiB, MiB, GiB, TiB, PiB, EiB, ZiB and YiB), then it's interpreted as size
in bytes and the size is aligned according to device I/O limits.
.TP
.B bootable
Mark the partition as bootable.
.TP
.BI attrs= string
Partition attributes, usually GPT partition attribute bits.  See
\fB\-\-part\-attrs\fR for more details about the GPT-bits string format.
.TP
.BI uuid= string
GPT partition UUID.
.TP
.BI name= string
GPT partition name.
.TP
.BI type= code
A hexadecimal number (without 0x) for an MBR partition, or a GUID for a GPT partition.
For backward compatibility the \fBId=\fR field has the same meaning.
.RE
.RE

.SH "EMPTY DISK LABEL"
.B sfdisk
does not create partition table without partitions by default. The lines with
partitions are expected in the script by default. The empty partition table has
to be explicitly requested by "label: <name>" script header line without any
partitions lines. For example:
.RS
.sp
.B "echo 'label: gpt' | sfdisk /dev/sdb"
.sp
.RE
creates empty GPT partition table. Note that the \fB\-\-append\fR disables this feature.

.SH "BACKING UP THE PARTITION TABLE"
It is recommended to save the layout of your devices.
.B sfdisk
supports two ways.
.sp
Use the \fB\-\-dump\fR option to save a description of the device layout
to a text file.  The dump format is suitable for later \fBsfdisk\fR input.
For example:
.RS
.sp
.B "sfdisk --dump /dev/sda > sda.dump"
.sp
.RE
This can later be restored by:
.RS
.sp
.B "sfdisk /dev/sda < sda.dump"
.RE

If you want to do a full (binary) backup of all sectors where the
partition table is stored,
then use the \fB\-\-backup\fR option.  It writes the sectors to
~/sfdisk-<device>-<offset>.bak files.  The default name of the backup file can
be changed with the \fB\-\-backup\-file\fR option.  The backup files
contain only raw data from the \fIdevice\fR.
Note that the same concept of backup files is used by
.BR wipefs (8).
For example:
.RS
.sp
.B "sfdisk --backup /dev/sda"
.sp
.RE
The GPT header can later be restored by:
.RS
.sp
.nf
.B "dd  if=~/sfdisk-sda-0x00000200.bak  of=/dev/sda  \e"
.B "  seek=$((0x00000200))  bs=1  conv=notrunc"
.fi
.sp
.RE
Note that \fBsfdisk\fR since version 2.26 no longer provides the \fB\-I\fR option to
restore sectors.
.BR dd (1)
provides all necessary functionality.

.SH COLORS
Implicit coloring can be disabled by an empty file \fI/etc/terminal-colors.d/sfdisk.disable\fR.

See
.BR terminal-colors.d (5)
for more details about colorization configuration. The logical color names
supported by
.B sfdisk
are:
.TP
.B header
The header of the output tables.
.TP
.B warn
The warning messages.
.TP
.B welcome
The welcome message.

.SH NOTES
Since version 2.26 \fBsfdisk\fR no longer provides the \fB\-R\fR or
\fB\-\-re\-read\fR option to force the kernel to reread the partition table.
Use \fBblockdev \-\-rereadpt\fR instead.
.PP
Since version 2.26 \fBsfdisk\fR does not provide the \fB\-\-DOS\fR, \fB\-\-IBM\fR, \fB\-\-DOS\-extended\fR,
\fB\-\-unhide\fR, \fB\-\-show\-extended\fR, \fB\-\-cylinders\fR, \fB\-\-heads\fR, \fB\-\-sectors\fR,
\fB\-\-inside\-outer\fR, \fB\-\-not\-inside\-outer\fR options.

.SH ENVIRONMENT
.IP SFDISK_DEBUG=all
enables sfdisk debug output.
.IP LIBFDISK_DEBUG=all
enables libfdisk debug output.
.IP LIBBLKID_DEBUG=all
enables libblkid debug output.
.IP LIBSMARTCOLS_DEBUG=all
enables libsmartcols debug output.

.SH "SEE ALSO"
.BR fdisk (8),
.BR cfdisk (8),
.BR parted (8),
.BR partprobe (8),
.BR partx (8)

.SH AUTHOR
Karel Zak <kzak@redhat.com>
.PP
The current sfdisk implementation is based on the original sfdisk
from Andries E. Brouwer.

.SH AVAILABILITY
The sfdisk command is part of the util-linux package and is available from
https://www.kernel.org/pub/linux/utils/util-linux/.