1FDISK(8) Linux Programmer's Manual FDISK(8)
2
3
4
6 fdisk - Partition table manipulator for Linux
7
9 fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device
10
11 fdisk -l [-u] [device...]
12
13 fdisk -s partition...
14
15 fdisk -v
16
17 fdisk -h
18
20 Hard disks can be divided into one or more logical disks called parti‐
21 tions. This division is described in the partition table found in sec‐
22 tor 0 of the disk.
23
24 In the BSD world one talks about `disk slices' and a `disklabel'.
25
26 Linux needs at least one partition, namely for its root file system.
27 It can use swap files and/or swap partitions, but the latter are more
28 efficient. So, usually one will want a second Linux partition dedicated
29 as swap partition. On Intel compatible hardware, the BIOS that boots
30 the system can often only access the first 1024 cylinders of the disk.
31 For this reason people with large disks often create a third partition,
32 just a few MB large, typically mounted on /boot, to store the kernel
33 image and a few auxiliary files needed at boot time, so as to make sure
34 that this stuff is accessible to the BIOS. There may be reasons of
35 security, ease of administration and backup, or testing, to use more
36 than the minimum number of partitions.
37
38 fdisk (in the first form of invocation) is a menu driven program for
39 creation and manipulation of partition tables. It understands DOS type
40 partition tables and BSD or SUN type disklabels.
41
42 fdisk doesn't understand GUID Partition Table (GPT) and it is not
43 designed for large partitions. In particular case use more advanced GNU
44 parted(8).
45
46 The device is usually /dev/sda, /dev/sdb or so. A device name refers to
47 the entire disk. The old systems without libata (a library used inside
48 the Linux kernel to support ATA host controllers and devices) make a
49 difference between IDE and SCSI disks. In such a case the device name
50 will be /dev/hd* (IDE) or /dev/sd* (SCSI).
51
52 The partition is a device name followed by a partition number. For
53 example, /dev/sda1 is the first partition on the first hard disk in the
54 system. See also Linux kernel documentation (the Documenta‐
55 tion/devices.txt file).
56
57 A BSD/SUN type disklabel can describe 8 partitions, the third of which
58 should be a `whole disk' partition. Do not start a partition that
59 actually uses its first sector (like a swap partition) at cylinder 0,
60 since that will destroy the disklabel.
61
62 An IRIX/SGI type disklabel can describe 16 partitions, the eleventh of
63 which should be an entire `volume' partition, while the ninth should be
64 labeled `volume header'. The volume header will also cover the parti‐
65 tion table, i.e., it starts at block zero and extends by default over
66 five cylinders. The remaining space in the volume header may be used
67 by header directory entries. No partitions may overlap with the volume
68 header. Also do not change its type and make some file system on it,
69 since you will lose the partition table. Use this type of label only
70 when working with Linux on IRIX/SGI machines or IRIX/SGI disks under
71 Linux.
72
73 A DOS type partition table can describe an unlimited number of parti‐
74 tions. In sector 0 there is room for the description of 4 partitions
75 (called `primary'). One of these may be an extended partition; this is
76 a box holding logical partitions, with descriptors found in a linked
77 list of sectors, each preceding the corresponding logical partitions.
78 The four primary partitions, present or not, get numbers 1-4. Logical
79 partitions start numbering from 5.
80
81 In a DOS type partition table the starting offset and the size of each
82 partition is stored in two ways: as an absolute number of sectors
83 (given in 32 bits) and as a Cylinders/Heads/Sectors triple (given in
84 10+8+6 bits). The former is OK - with 512-byte sectors this will work
85 up to 2 TB. The latter has two different problems. First of all, these
86 C/H/S fields can be filled only when the number of heads and the number
87 of sectors per track are known. Secondly, even if we know what these
88 numbers should be, the 24 bits that are available do not suffice. DOS
89 uses C/H/S only, Windows uses both, Linux never uses C/H/S.
90
91 If possible, fdisk will obtain the disk geometry automatically. This
92 is not necessarily the physical disk geometry (indeed, modern disks do
93 not really have anything like a physical geometry, certainly not some‐
94 thing that can be described in simplistic Cylinders/Heads/Sectors
95 form), but is the disk geometry that MS-DOS uses for the partition ta‐
96 ble.
97
98 Usually all goes well by default, and there are no problems if Linux is
99 the only system on the disk. However, if the disk has to be shared with
100 other operating systems, it is often a good idea to let an fdisk from
101 another operating system make at least one partition. When Linux boots
102 it looks at the partition table, and tries to deduce what (fake) geome‐
103 try is required for good cooperation with other systems.
104
105 Whenever a partition table is printed out, a consistency check is per‐
106 formed on the partition table entries. This check verifies that the
107 physical and logical start and end points are identical, and that the
108 partition starts and ends on a cylinder boundary (except for the first
109 partition).
110
111 Some versions of MS-DOS create a first partition which does not begin
112 on a cylinder boundary, but on sector 2 of the first cylinder. Parti‐
113 tions beginning in cylinder 1 cannot begin on a cylinder boundary, but
114 this is unlikely to cause difficulty unless you have OS/2 on your
115 machine.
116
117 A sync() and a BLKRRPART ioctl() (reread partition table from disk) are
118 performed before exiting when the partition table has been updated.
119 Long ago it used to be necessary to reboot after the use of fdisk. I
120 do not think this is the case anymore - indeed, rebooting too quickly
121 might cause loss of not-yet-written data. Note that both the kernel and
122 the disk hardware may buffer data.
123
124
126 The DOS 6.x FORMAT command looks for some information in the first sec‐
127 tor of the data area of the partition, and treats this information as
128 more reliable than the information in the partition table. DOS FORMAT
129 expects DOS FDISK to clear the first 512 bytes of the data area of a
130 partition whenever a size change occurs. DOS FORMAT will look at this
131 extra information even if the /U flag is given -- we consider this a
132 bug in DOS FORMAT and DOS FDISK.
133
134 The bottom line is that if you use cfdisk or fdisk to change the size
135 of a DOS partition table entry, then you must also use dd to zero the
136 first 512 bytes of that partition before using DOS FORMAT to format the
137 partition. For example, if you were using cfdisk to make a DOS parti‐
138 tion table entry for /dev/sda1, then (after exiting fdisk or cfdisk and
139 rebooting Linux so that the partition table information is valid) you
140 would use the command "dd if=/dev/zero of=/dev/sda1 bs=512 count=1" to
141 zero the first 512 bytes of the partition.
142
143 BE EXTREMELY CAREFUL if you use the dd command, since a small typo can
144 make all of the data on your disk useless.
145
146 For best results, you should always use an OS-specific partition table
147 program. For example, you should make DOS partitions with the DOS
148 FDISK program and Linux partitions with the Linux fdisk or Linux cfdisk
149 program.
150
151
153 -b sectorsize
154 Specify the sector size of the disk. Valid values are 512, 1024,
155 2048 or 4096. (Recent kernels know the sector size. Use this
156 only on old kernels or to override the kernel's ideas.) Since
157 util-linux-ng 2.17 fdisk differentiates between logical and
158 physical sector size. This option changes both sector sizes to
159 sectorsize.
160
161 -h Print help and then exit.
162
163 -c Switch off DOS-compatible mode. (Recommended)
164
165 -C cyls
166 Specify the number of cylinders of the disk. I have no idea why
167 anybody would want to do so.
168
169 -H heads
170 Specify the number of heads of the disk. (Not the physical num‐
171 ber, of course, but the number used for partition tables.) Rea‐
172 sonable values are 255 and 16.
173
174 -S sects
175 Specify the number of sectors per track of the disk. (Not the
176 physical number, of course, but the number used for partition
177 tables.) A reasonable value is 63.
178
179 -l List the partition tables for the specified devices and then
180 exit. If no devices are given, those mentioned in /proc/parti‐
181 tions (if that exists) are used.
182
183 -u When listing partition tables, give sizes in sectors instead of
184 cylinders.
185
186 -s partition
187 The size of the partition (in blocks) is printed on the standard
188 output.
189
190 -v Print version number of fdisk program and exit.
191
193 There are several *fdisk programs around. Each has its problems and
194 strengths. Try them in the order cfdisk, fdisk, sfdisk. (Indeed,
195 cfdisk is a beautiful program that has strict requirements on the par‐
196 tition tables it accepts, and produces high quality partition tables.
197 Use it if you can. fdisk is a buggy program that does fuzzy things -
198 usually it happens to produce reasonable results. Its single advantage
199 is that it has some support for BSD disk labels and other non-DOS par‐
200 tition tables. Avoid it if you can. sfdisk is for hackers only - the
201 user interface is terrible, but it is more correct than fdisk and more
202 powerful than both fdisk and cfdisk. Moreover, it can be used nonin‐
203 teractively.)
204
205 These days there also is parted. The cfdisk interface is nicer, but
206 parted does much more: it not only resizes partitions, but also the
207 filesystems that live in them.
208
209 The IRIX/SGI type disklabel is currently not supported by the kernel.
210 Moreover, IRIX/SGI header directories are not fully supported yet.
211
212 The option `dump partition table to file' is missing.
213
215 cfdisk(8), sfdisk(8), mkfs(8), parted(8), partprobe(8), kpartx(8)
216
218 The fdisk command is part of the util-linux-ng package and is available
219 from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
220
221
222
223Linux 2.0 11 June 1998 FDISK(8)