]> git.ipfire.org Git - thirdparty/util-linux.git/blob - disk-utils/fdisk.8
libmount: don't use sscanf() for swaps parsing
[thirdparty/util-linux.git] / disk-utils / fdisk.8
1 .\" Copyright 1992, 1993 Rickard E. Faith (faith@cs.unc.edu)
2 .\" Copyright 1998 Andries E. Brouwer (aeb@cwi.nl)
3 .\" Copyright 2012 Davidlohr Bueso <dave@gnu.org>
4 .\" Copyright (C) 2013 Karel Zak <kzak@redhat.com>
5 .\" May be distributed under the GNU General Public License
6 .TH FDISK 8 "February 2016" "util-linux" "System Administration"
7
8 .SH NAME
9 fdisk \- manipulate disk partition table
10
11 .SH SYNOPSIS
12 .B fdisk
13 [options]
14 .I device
15 .sp
16 .B fdisk \-l
17 .RI [ device ...]
18
19 .SH DESCRIPTION
20 .B fdisk
21 is a dialog-driven program for creation and manipulation of partition tables.
22 It understands GPT, MBR, Sun, SGI and BSD partition tables.
23
24 Block devices can be divided into one or more logical disks called
25 .IR partitions .
26 This division is recorded in the
27 .IR "partition table" ,
28 usually found in sector 0 of the disk.
29 (In the BSD world one talks about `disk slices' and a `disklabel'.)
30
31 All partitioning is driven by device I/O limits (the topology) by default.
32 .B fdisk
33 is able to optimize the disk layout for a 4K-sector size and use an alignment offset on
34 modern devices for MBR and GPT. It is always a good idea to follow \fBfdisk\fR's defaults
35 as the default values (e.g. first and last partition sectors) and partition
36 sizes specified by the +/-<size>{M,G,...} notation are always aligned according
37 to the device properties.
38
39 Note that
40 .BR partx (8)
41 provides a rich interface for scripts to print disk layouts,
42 .B fdisk
43 is mostly designed for humans. Backward compatibility in the output of
44 .B fdisk
45 is not guaranteed. The input (the commands) should always be backward compatible.
46
47 .SH OPTIONS
48 .TP
49 \fB\-b\fR, \fB\-\-sector\-size\fR \fIsectorsize\fP
50 Specify the sector size of the disk. Valid values are 512, 1024, 2048, and 4096.
51 (Recent kernels know the sector size. Use this option only on old kernels or
52 to override the kernel's ideas.) Since util-linux-2.17, \fBfdisk\fR differentiates
53 between logical and physical sector size. This option changes both sector sizes to
54 .IB sectorsize .
55 .TP
56 \fB\-B\fR, \fB\-\-protect\-boot\fP
57 Don't erase the begin of the first disk sector when create a new disk label. This
58 feature is supported for GPT and MBR.
59 .TP
60 \fB\-c\fR, \fB\-\-compatibility\fR[=\fImode\fR]
61 Specify the compatibility mode, 'dos' or 'nondos'. The default is non-DOS
62 mode. For backward compatibility, it is possible to use the option without
63 the \fImode\fR argument -- then the default is used. Note that the optional
64 \fImode\fR argument cannot be separated from the \fB-c\fR option by a space,
65 the correct form is for example '-c=dos'.
66 .TP
67 \fB\-h\fR, \fB\-\-help\fR
68 Display a help text and exit.
69 .TP
70 \fB\-L\fR, \fB\-\-color\fR[=\fIwhen\fR]
71 Colorize the output. The optional argument \fIwhen\fP
72 can be \fBauto\fR, \fBnever\fR or \fBalways\fR. If the \fIwhen\fR argument is omitted,
73 it defaults to \fBauto\fR. The colors can be disabled; for the current built-in default
74 see the \fB\-\-help\fR output. See also the \fBCOLORS\fR section.
75 .TP
76 \fB\-l\fR, \fB\-\-list\fR
77 List the partition tables for the specified devices and then exit.
78 If no devices are given, those mentioned in
79 .I /proc/partitions
80 (if that file exists) are used.
81 .TP
82 .BR \-o , " \-\-output " \fIlist\fP
83 Specify which output columns to print. Use
84 .B \-\-help
85 to get a list of all supported columns.
86
87 The default list of columns may be extended if \fIlist\fP is
88 specified in the format \fI+list\fP (e.g. \fB-o +UUID\fP).
89 .TP
90 \fB\-s\fR, \fB\-\-getsz\fR
91 Print the size in 512-byte sectors of each given block device. This option is DEPRECATED
92 in favour of
93 .BR blockdev (1).
94 .TP
95 \fB\-t\fR, \fB\-\-type\fR \fItype\fR
96 Enable support only for disklabels of the specified \fItype\fP, and disable
97 support for all other types.
98 .TP
99 \fB\-u\fR, \fB\-\-units\fR[=\fIunit\fR]
100 When listing partition tables, show sizes in 'sectors' or in 'cylinders'. The
101 default is to show sizes in sectors. For backward compatibility, it is possible
102 to use the option without the \fIunit\fR argument -- then the default is used.
103 Note that the optional \fIunit\fR argument cannot be separated from the \fB-u\fR
104 option by a space, the correct form is for example '-u=cylinders'.
105
106 .TP
107 \fB\-C\fR, \fB\-\-cylinders\fR \fInumber\fR
108 Specify the number of cylinders of the disk.
109 I have no idea why anybody would want to do so.
110 .TP
111 \fB\-H\fR, \fB\-\-heads\fR \fInumber\fR
112 Specify the number of heads of the disk. (Not the physical number,
113 of course, but the number used for partition tables.)
114 Reasonable values are 255 and 16.
115 .TP
116 \fB\-S\fR, \fB\-\-sectors\fR \fInumber\fR
117 Specify the number of sectors per track of the disk.
118 (Not the physical number, of course, but the number used for
119 partition tables.) A reasonable value is 63.
120
121 .TP
122 \fB\-w\fR, \fB\-\-wipe\fR \fIwhen\fR
123 Wipe filesystem, RAID and partition-table signatures from the device, in order
124 to avoid possible collisions. The argument \fIwhen\fR can be \fBauto\fR,
125 \fBnever\fR or \fBalways\fR. When this option is not given, the default is
126 \fBauto\fR, in which case signatures are wiped only when in interactive mode.
127 In all cases detected signatures are reported by warning messages
128 before a new partition table is created. See also
129 .BR wipefs (8)
130 command.
131
132 .TP
133 \fB\-W\fR, \fB\-\-wipe-partition\fR \fIwhen\fR
134 Wipe filesystem, RAID and partition-table signatures from a newly created
135 partitions, in order to avoid possible collisions. The argument \fIwhen\fR can
136 be \fBauto\fR, \fBnever\fR or \fBalways\fR. When this option is not given, the
137 default is \fBauto\fR, in which case signatures are wiped only when in
138 interactive mode and after confirmation by user. In all cases detected
139 signatures are reported by warning messages before a new partition is
140 created. See also
141 .BR wipefs (8)
142 command.
143
144 .TP
145 \fB\-V\fR, \fB\-\-version\fR
146 Display version information and exit.
147
148 .SH DEVICES
149 The
150 .I device
151 is usually /dev/sda, /dev/sdb or so. A device name refers to the entire disk.
152 Old systems without libata (a library used inside the Linux kernel to support
153 ATA host controllers and devices) make a difference between IDE and SCSI disks.
154 In such cases the device name will be /dev/hd* (IDE) or /dev/sd* (SCSI).
155
156 The
157 .I partition
158 is a device name followed by a partition number. For example, /dev/sda1 is the
159 first partition on the first hard disk in the system. See also Linux kernel
160 documentation (the Documentation/devices.txt file).
161
162 .SH SIZES
163 The "last sector" dialog accepts partition size specified by number of sectors
164 or by +/-<size>{K,B,M,G,...} notation.
165
166 If the size is prefixed by '+' then it is interpreted as relative to the
167 partition first sector. If the size is prefixed by '-' then it is interpreted
168 as relative to the high limit (last available sector for the partition).
169
170 In the case the size is specified in bytes than the number may be followed by
171 the multiplicative suffixes KiB=1024, MiB=1024*1024, and so on for GiB, TiB,
172 PiB, EiB, ZiB and YiB. The "iB" is optional, e.g. "K" has the same meaning as
173 "KiB".
174
175 The relative sizes are always aligned according to device I/O limits. The
176 +/-<size>{K,B,M,G,...} notation is recommended.
177
178 For backward compatibility fdisk also accepts the suffixes KB=1000,
179 MB=1000*1000, and so on for GB, TB, PB, EB, ZB and YB. These 10^N suffixes
180 are deprecated.
181
182 .SH SCRIPT FILES
183 .B fdisk
184 allows to read (by 'I' command) sfdisk compatible script files. The script is
185 applied to in-memory partition table, and then it is possible to modify the
186 partition table before you write it to the device.
187 .PP
188 And vice-versa it is possible to write the current in-memory disk layout
189 to the script file by command 'O'.
190 .PP
191 The script files are compatible between cfdisk, sfdisk, fdisk and another
192 libfdisk applications. For more details see
193 .BR sfdisk (8).
194
195 .SH DISK LABELS
196 .B GPT (GUID Partition Table)
197 .RS
198 GPT is modern standard for the layout of the partition table. GPT uses 64-bit
199 logical block addresses, checksums, UUIDs and names for partitions and an
200 unlimited number of partitions (although the number of partitions is
201 usually restricted to 128 in many partitioning tools).
202
203 Note that the first sector is still reserved for a
204 .B protective MBR
205 in the GPT specification. It prevents MBR-only partitioning tools
206 from mis-recognizing and overwriting GPT disks.
207
208 GPT is always a better choice than MBR, especially on modern hardware with a UEFI
209 boot loader.
210 .RE
211
212 .B DOS-type (MBR)
213 .RS
214 A DOS-type partition table can describe an unlimited number of partitions. In sector 0
215 there is room for the description of 4 partitions (called `primary'). One of
216 these may be an extended partition; this is a box holding logical partitions,
217 with descriptors found in a linked list of sectors, each preceding the
218 corresponding logical partitions. The four primary partitions, present or not,
219 get numbers 1-4. Logical partitions are numbered starting from 5.
220
221 In a DOS-type partition table the starting offset and the size of each
222 partition is stored in two ways: as an absolute number of sectors (given in 32
223 bits), and as a
224 .B Cylinders/Heads/Sectors
225 triple (given in 10+8+6 bits). The former is OK -- with 512-byte sectors this
226 will work up to 2 TB. The latter has two problems. First, these C/H/S fields
227 can be filled only when the number of heads and the number of sectors per track
228 are known. And second, even if we know what these numbers should be, the 24
229 bits that are available do not suffice. DOS uses C/H/S only, Windows uses
230 both, Linux never uses C/H/S. The
231 .B C/H/S addressing is deprecated
232 and may be unsupported in some later fdisk version.
233
234 .B Please, read the DOS-mode section if you want DOS-compatible partitions.
235 .B fdisk
236 does not care about cylinder boundaries by default.
237 .RE
238
239 .B BSD/Sun-type
240 .RS
241 A BSD/Sun disklabel can describe 8 partitions, the third of which should be a `whole
242 disk' partition. Do not start a partition that actually uses its first sector
243 (like a swap partition) at cylinder 0, since that will destroy the disklabel.
244 Note that a
245 .B BSD label
246 is usually nested within a DOS partition.
247 .RE
248
249 .B IRIX/SGI-type
250 .RS
251 An IRIX/SGI disklabel can describe 16 partitions, the eleventh of which should be an entire
252 `volume' partition, while the ninth should be labeled `volume header'. The
253 volume header will also cover the partition table, i.e., it starts at block
254 zero and extends by default over five cylinders. The remaining space in the
255 volume header may be used by header directory entries. No partitions may
256 overlap with the volume header. Also do not change its type or make some
257 filesystem on it, since you will lose the partition table. Use this type of
258 label only when working with Linux on IRIX/SGI machines or IRIX/SGI disks under
259 Linux.
260 .RE
261
262 A sync() and an ioctl(BLKRRPART) (rereading the partition table from disk)
263 are performed before exiting when the partition table has been updated.
264
265 .SH "DOS mode and DOS 6.x WARNING"
266 .B Note that all this is deprecated. You don't have to care about things like
267 .B geometry and cylinders on modern operating systems. If you really want
268 .B DOS-compatible partitioning then you have to enable DOS mode and cylinder
269 .B units by using the '-c=dos -u=cylinders' fdisk command-line options.
270
271 The DOS 6.x FORMAT command looks for some information in the first sector of
272 the data area of the partition, and treats this information as more reliable
273 than the information in the partition table. DOS FORMAT expects DOS FDISK to
274 clear the first 512 bytes of the data area of a partition whenever a size
275 change occurs. DOS FORMAT will look at this extra information even if the /U
276 flag is given -- we consider this a bug in DOS FORMAT and DOS FDISK.
277
278 The bottom line is that if you use \fBfdisk\fR or \fBcfdisk\fR to change the
279 size of a DOS partition table entry, then you must also use
280 .BR dd "(1) to " "zero the first 512 bytes"
281 of that partition before using DOS FORMAT to format the partition. For
282 example, if you were using \fBfdisk\fR to make a DOS partition table entry for
283 /dev/sda1, then (after exiting \fBfdisk\fR and rebooting Linux so that the
284 partition table information is valid) you would use the command "dd
285 if=/dev/zero of=/dev/sda1 bs=512 count=1" to zero the first 512 bytes of the
286 partition.
287
288 .B fdisk
289 usually obtains the disk geometry automatically. This is not necessarily the
290 physical disk geometry (indeed, modern disks do not really have anything like a
291 physical geometry, certainly not something that can be described in the simplistic
292 Cylinders/Heads/Sectors form), but it is the disk geometry that MS-DOS uses for
293 the partition table.
294
295 Usually all goes well by default, and there are no problems if Linux is the
296 only system on the disk. However, if the disk has to be shared with other
297 operating systems, it is often a good idea to let an fdisk from another
298 operating system make at least one partition. When Linux boots it looks at the
299 partition table, and tries to deduce what (fake) geometry is required for good
300 cooperation with other systems.
301
302 Whenever a partition table is printed out in DOS mode, a consistency check is
303 performed on the partition table entries. This check verifies that the
304 physical and logical start and end points are identical, and that each
305 partition starts and ends on a cylinder boundary (except for the first
306 partition).
307
308 Some versions of MS-DOS create a first partition which does not begin
309 on a cylinder boundary, but on sector 2 of the first cylinder.
310 Partitions beginning in cylinder 1 cannot begin on a cylinder boundary, but
311 this is unlikely to cause difficulty unless you have OS/2 on your machine.
312
313 For best results, you should always use an OS-specific partition table
314 program. For example, you should make DOS partitions with the DOS FDISK
315 program and Linux partitions with the Linux fdisk or Linux cfdisk programs.
316 .SH COLORS
317 Implicit coloring can be disabled by an empty file \fI/etc/terminal-colors.d/fdisk.disable\fR.
318
319 See
320 .BR terminal-colors.d (5)
321 for more details about colorization configuration. The logical color names
322 supported by
323 .B fdisk
324 are:
325 .TP
326 .B header
327 The header of the output tables.
328 .TP
329 .B help-title
330 The help section titles.
331 .TP
332 .B warn
333 The warning messages.
334 .TP
335 .B welcome
336 The welcome message.
337
338 .SH AUTHORS
339 .MT kzak@redhat.com
340 Karel Zak
341 .ME
342 .br
343 .MT dave@gnu.org
344 Davidlohr Bueso
345 .ME
346 .br
347 .PP
348 The original version was written by
349 Andries E. Brouwer, A. V. Le Blanc and others.
350
351 .SH ENVIRONMENT
352 .IP FDISK_DEBUG=all
353 enables fdisk debug output.
354 .IP LIBFDISK_DEBUG=all
355 enables libfdisk debug output.
356 .IP LIBBLKID_DEBUG=all
357 enables libblkid debug output.
358 .IP LIBSMARTCOLS_DEBUG=all
359 enables libsmartcols debug output.
360 .IP LIBSMARTCOLS_DEBUG_PADDING=on
361 use visible padding characters. Requires enabled LIBSMARTCOLS_DEBUG.
362
363 .SH "SEE ALSO"
364 .BR cfdisk (8),
365 .BR mkfs (8),
366 .BR partx (8),
367 .BR sfdisk (8)
368
369 .SH AVAILABILITY
370 The fdisk command is part of the util-linux package and is available from
371 https://www.kernel.org/pub/linux/utils/util-linux/.