enable login utils
[framework/base/util-linux-ng.git] / fdisk / fdisk.8
1 .\" Copyright 1992, 1993 Rickard E. Faith (faith@cs.unc.edu)
2 .\" Copyright 1998 Andries E. Brouwer (aeb@cwi.nl)
3 .\" May be distributed under the GNU General Public License
4 .TH FDISK 8 "June 2010" "util-linux" "System Administration"
5 .SH NAME
6 fdisk \- manipulate disk partition table
7 .SH SYNOPSIS
8 .B fdisk
9 .RB [ \-uc ]
10 .RB [ \-b
11 .IR sectorsize ]
12 .RB [ \-C
13 .IR cyls ]
14 .RB [ \-H
15 .IR heads ]
16 .RB [ \-S
17 .IR sects ]
18 .I device
19 .sp
20 .B fdisk \-l
21 .RB [ \-u ]
22 .RI [ device ...]
23 .sp
24 .B fdisk \-s
25 .IR partition ...
26 .sp
27 .B fdisk \-v
28 .sp
29 .B fdisk \-h
30 .SH DESCRIPTION
31 .B fdisk
32 (in the first form of invocation)
33 is a menu-driven program for creation and manipulation of
34 partition tables.
35 It understands DOS-type partition tables and BSD- or SUN-type disklabels.
36
37 .B fdisk
38 does not understand GUID partition tables (GPTs) and it is not designed
39 for large partitions.  In these cases, use the more advanced GNU
40 .BR parted (8).
41
42 .B fdisk
43 does not use DOS-compatible mode and cylinders as display units by default.
44 The old deprecated DOS behavior can be enabled with
45 the '-c=dos -u=cylinders' command-line options.
46
47 Hard disks can be divided into one or more logical disks called
48 .IR partitions .
49 This division is recorded in the
50 .IR "partition table" ,
51 found in sector 0 of the disk.
52 (In the BSD world one talks about `disk slices' and a `disklabel'.)
53
54 Linux needs at least one partition, namely for its root file system.
55 It can use swap files and/or swap partitions, but the latter are more
56 efficient.  So, usually one will want a second Linux partition
57 dedicated as swap partition.
58 On Intel-compatible hardware, the BIOS that boots the system
59 can often only access the first 1024 cylinders of the disk.
60 For this reason people with large disks often create a third partition,
61 just a few MB large, typically mounted on
62 .IR /boot ,
63 to store the kernel image and a few auxiliary files needed at boot time,
64 so as to make sure that this stuff is accessible to the BIOS.
65 There may be reasons of security, ease of administration and backup,
66 or testing, to use more than the minimum number of partitions.
67
68 .SH DEVICES
69 The
70 .I device
71 is usually /dev/sda, /dev/sdb or so.  A device name refers to the entire disk.
72 Old systems without libata (a library used inside the Linux kernel to
73 support ATA host controllers and devices) make a difference between IDE and
74 SCSI disks.  In such cases the device name will be /dev/hd* (IDE) or /dev/sd*
75 (SCSI).
76
77 The
78 .I partition
79 is a device name followed by a partition number.  For example, /dev/sda1
80 is the first partition on the first hard disk in the system.
81 See also Linux kernel documentation (the Documentation/devices.txt file).
82
83 .SH DISK LABELS
84 A BSD/SUN-type disklabel can describe 8 partitions,
85 the third of which should be a `whole disk' partition.
86 Do not start a partition that actually uses its first sector
87 (like a swap partition) at cylinder 0, since that will
88 destroy the disklabel.
89
90 An IRIX/SGI-type disklabel can describe 16 partitions,
91 the eleventh of which should be an entire `volume' partition,
92 while the ninth should be labeled `volume header'.
93 The volume header will also cover the partition table, i.e.,
94 it starts at block zero and extends by default over five cylinders.
95 The remaining space in the volume header may be used by header
96 directory entries.  No partitions may overlap with the volume header.
97 Also do not change its type or make some filesystem on it, since
98 you will lose the partition table.  Use this type of label only when
99 working with Linux on IRIX/SGI machines or IRIX/SGI disks under Linux.
100
101 A DOS-type partition table can describe an unlimited number
102 of partitions.  In sector 0 there is room for the description
103 of 4 partitions (called `primary').  One of these may be an
104 extended partition; this is a box holding logical partitions,
105 with descriptors found in a linked list of sectors, each
106 preceding the corresponding logical partitions.
107 The four primary partitions, present or not, get numbers 1-4.
108 Logical partitions start numbering from 5.
109
110 In a DOS-type partition table the starting offset and the size
111 of each partition is stored in two ways: as an absolute number
112 of sectors (given in 32 bits), and as a Cylinders/Heads/Sectors
113 triple (given in 10+8+6 bits).  The former is OK -- with 512-byte
114 sectors this will work up to 2 TB.  The latter has two
115 problems.  First, these C/H/S fields can be filled only
116 when the number of heads and the number of sectors per track
117 are known.  And second, even if we know what these numbers should be,
118 the 24 bits that are available do not suffice.
119 DOS uses C/H/S only, Windows uses both, Linux never uses C/H/S.
120
121 If possible,
122 .B fdisk
123 will obtain the disk geometry automatically.  This is not
124 necessarily the physical disk geometry (indeed, modern disks do not
125 really have anything like a physical geometry, certainly not something
126 that can be described in simplistic Cylinders/Heads/Sectors form),
127 but it is the disk geometry that MS-DOS uses for the partition table.
128
129 Usually all goes well by default, and there are no problems if
130 Linux is the only system on the disk.  However, if the disk has
131 to be shared with other operating systems, it is often a good idea
132 to let an fdisk from another operating system make at least one
133 partition.  When Linux boots it looks at the partition table, and
134 tries to deduce what (fake) geometry is required for good
135 cooperation with other systems.
136
137 Whenever a partition table is printed out, a consistency check is performed
138 on the partition table entries.  This check verifies that the physical and
139 logical start and end points are identical, and that each partition starts
140 and ends on a cylinder boundary (except for the first partition).
141
142 Some versions of MS-DOS create a first partition which does not begin
143 on a cylinder boundary, but on sector 2 of the first cylinder.
144 Partitions beginning in cylinder 1 cannot begin on a cylinder boundary, but
145 this is unlikely to cause difficulty unless you have OS/2 on your machine.
146
147 A sync() and an ioctl(BLKRRPART) (reread partition table from disk)
148 are performed before exiting when the partition table has been updated.
149 Long ago it used to be necessary to reboot after the use of fdisk.
150 I do not think this is the case anymore -- indeed, rebooting too quickly
151 might cause loss of not-yet-written data.  Note that both the kernel
152 and the disk hardware may buffer data.
153
154 .SH "DOS 6.x WARNING"
155
156 The DOS 6.x FORMAT command looks for some information in the first
157 sector of the data area of the partition, and treats this information
158 as more reliable than the information in the partition table.  DOS
159 FORMAT expects DOS FDISK to clear the first 512 bytes of the data area
160 of a partition whenever a size change occurs.  DOS FORMAT will look at
161 this extra information even if the /U flag is given -- we consider
162 this a bug in DOS FORMAT and DOS FDISK.
163
164 The bottom line is that if you use cfdisk or fdisk to change the size of a
165 DOS partition table entry, then you must also use
166 .B dd
167 to zero the first 512 bytes of that partition before using DOS FORMAT to
168 format the partition.  For example, if you were using cfdisk to make a DOS
169 partition table entry for /dev/sda1, then (after exiting fdisk or cfdisk
170 and rebooting Linux so that the partition table information is valid) you
171 would use the command "dd if=/dev/zero of=/dev/sda1 bs=512 count=1" to zero
172 the first 512 bytes of the partition.
173
174 .B BE EXTREMELY CAREFUL
175 if you use the
176 .B dd
177 command, since a small typo can make all of the data on your disk useless.
178
179 For best results, you should always use an OS-specific partition table
180 program.  For example, you should make DOS partitions with the DOS FDISK
181 program and Linux partitions with the Linux fdisk or Linux cfdisk program.
182
183 .SH OPTIONS
184 .TP
185 .BI "\-b " sectorsize
186 Specify the sector size of the disk.  Valid values are 512, 1024, 2048 or 4096.
187 (Recent kernels know the sector size.  Use this only on old kernels or
188 to override the kernel's ideas.)  Since util-linux-2.17, fdisk differentiates
189 between logical and physical sector size.  This option changes both sector sizes to
190 .IB sectorsize .
191 .TP
192 .BI "\-c"[=mode]
193 Specify the compatiblity mode, 'dos' or 'nondos'.  The default is non-DOS
194 mode.  For backward compatibility, it is possible to use the option without
195 the <mode> argument -- then the default is used.  Note that the optional
196 <mode> argument cannot be separated from the -c option by a space, the correct
197 form is for example '-c=dos'.
198 .TP
199 .BI "\-C " cyls
200 Specify the number of cylinders of the disk.
201 I have no idea why anybody would want to do so.
202 .TP
203 .BI "\-H " heads
204 Specify the number of heads of the disk.  (Not the physical number,
205 of course, but the number used for partition tables.)
206 Reasonable values are 255 and 16.
207 .TP
208 .BI "\-S " sects
209 Specify the number of sectors per track of the disk.
210 (Not the physical number, of course, but the number used for
211 partition tables.)
212 A reasonable value is 63.
213 .TP
214 .BI \-h
215 Print help and then exit.
216 .TP
217 .B \-l
218 List the partition tables for the specified devices and then exit.
219 If no devices are given, those mentioned in
220 .I /proc/partitions
221 (if that exists) are used.
222 .TP
223 .BI "\-s " partition...
224 Print the size (in blocks) of each given partition.
225 .TP
226 .BI "\-u"[=unit]
227 When listing partition tables, show sizes in 'sectors' or in 'cylinders'.  The
228 default is to show sizes in sectors.  For backward compatibility, it is possible
229 to use the option without the <units> argument -- then the default is used.
230 Note that the optional <unit> argument cannot be separated from the -u option
231 by a space, the correct form is for example '-u=cylinders'.
232 .TP
233 .B \-v
234 Print version number of
235 .B fdisk
236 program and exit.
237 .SH BUGS
238 There are several *fdisk programs around.
239 Each has its problems and strengths.
240 Try them in the order
241 .BR cfdisk ,
242 .BR fdisk ,
243 .BR sfdisk .
244 (Indeed,
245 .B cfdisk
246 is a beautiful program that has strict requirements on
247 the partition tables it accepts, and produces high quality partition
248 tables.  Use it if you can.
249 .B fdisk
250 is a buggy program that does fuzzy things - usually it happens to
251 produce reasonable results.  Its single advantage is that it has
252 some support for BSD disk labels and other non-DOS partition tables.
253 Avoid it if you can.
254 .B sfdisk
255 is for hackers only -- the user interface is terrible, but it is
256 more correct than fdisk and more powerful than both fdisk and cfdisk.
257 Moreover, it can be used noninteractively.)
258 .PP
259 These days there also is
260 .BR parted .
261 The cfdisk interface is nicer, but parted does much more: it not only
262 resizes partitions, but also the filesystems that live in them.
263 .PP
264 The IRIX/SGI-type disklabel is currently not supported by the kernel.
265 Moreover, IRIX/SGI header directories are not fully supported yet.
266 .PP
267 The option `dump partition table to file' is missing.
268 .\" .SH AUTHORS
269 .\" A. V. Le Blanc (LeBlanc@mcc.ac.uk)
270 .\" Bernhard Fastenrath (fasten@informatik.uni-bonn.de)
271 .\" Jakub Jelinek (jj@sunsite.mff.cuni.cz)
272 .\" Andreas Neuper (ANeuper@GUUG.de)
273 .\" and many others.
274 .SH "SEE ALSO"
275 .BR cfdisk (8),
276 .BR sfdisk (8),
277 .BR mkfs (8),
278 .BR parted (8),
279 .BR partprobe (8),
280 .BR kpartx (8)
281 .SH AVAILABILITY
282 The fdisk command is part of the util-linux package and is available from
283 ftp://ftp.kernel.org/pub/linux/utils/util-linux/.