1 `fdisk': the Linux partition table editor
2 =========================================
4 `fdisk' is the Linux partition table editor. In this section we
5 examine this utility and try to describe it thoroughly enough so that
10 * Disks and how they are described.
11 * Dividing up your disk.
12 * The `fdisk' command.
13 * Deleting and adding partitions.
14 * Active flags and system types.
15 * Extra commands for experts.
16 * Warnings for `fdisk' users.
19 Disks and how they are described
20 --------------------------------
22 A typical disk consists physically of one or more circular objects
23 called "platters", which rotate about a central axis. Devices called
24 "heads" move to specified places on the disk surface to read or write
25 information. There is usually one head on each side of every platter,
26 and all these heads are attached to a comb-like controller arm which
27 moves all of them at the same time, either closer to the centre of the
28 disk, or closer to the outer edge.
30 Suppose the arm is in one position, putting an area of the disk
31 surface within reach of one or another of the heads. This total area,
32 everything that is accessible without moving the arm, is called a
33 "cylinder". (A cylinder is a barrel-shaped cross section of a disk,
34 consisting of a circular strip from each side of each platter.) The
35 part of a cylinder that one head can read or write without moving is
38 Each track is divided into several pie-shaped slices called
39 "sectors", which are the smallest parts of the disk which can be read
40 or written at a time. The sectors on one disk are usually all the same
43 In fact, there are not always two heads to every platter, there are
44 some disks which do not have the same amount of data in every cylinder,
45 and there may be disks which do not have the same amount of data in
46 every sector. These features are usually hidden on PCs by the
47 controller card or the BIOS, which map the physical geometry of a disk
48 onto a logical geometry, which is what is actually used to access the
51 The numbers which describe the "geometry" of a disk are
53 1. The number of cylinders it contains.
55 2. The number of tracks per cylinder, which is the number of heads.
57 3. The number of sectors per track.
59 4. The number of bytes per sector.
61 These numbers vary from disk to disk, but a typical PC disk might
62 have about 1000 cylinders, half a dozen heads, and 15 or 20 sectors per
63 track, with each sector containing 512 bytes or characters; such a disk
64 contains 40 to 60 megabytes of data. A "double density" floppy disk
65 contains 40 cylinders, with 2 heads (2 tracks per cylinder), and with 9
66 sectors per track; such a disk contains 360 kilobytes, or 360 * 1024
67 characters. A "high density" 3.5 inch floppy contains 80 cylinders,
68 with 2 heads and 18 sectors per track, or 1.44 megabytes, or 1440 *
71 The exact size of a track or cylinder in bytes varies from one disk
72 to another. This `fdisk' for Linux deals mainly with cylinders, since
73 this is the best unit to use when allocating space for partitions. It
74 reports partition sizes in "blocks" of 1024 bytes, or 2 sectors, since
75 `mkswap' and the various `mkfs' programs require this number. A block
76 is the smallest amount of space which can be set aside for a file in
77 the current file systems.
79 An operating system, such as Linux or DOS or OS/2, may use a disk in
80 any way that it wishes, but if two operating systems share the same
81 disk, they must agree on who owns what, or else one will interfere with
82 the other (that is, by damaging the other's files). A "partition" is a
83 section of a hard disk which is handled as a unit by all operating
84 systems which can access the disk. The standard way to define
85 partitions (for the moment) is the "partition table", a list of
86 information which is stored in parts of the disk that don't belong to
87 any of the systems using the disk. The beginning of the partition
88 table is stored in the disk's primary boot sector, and the rest is
89 stored in a chain of sectors scattered throughout the disk.
91 The first sector on the disk is called the "primary boot block" or
92 "primary boot sector" because (1) it comes first, before other, similar
93 sectors; (2) it tells where the other, similar sectors are found, so
94 that it is logically `prior' to them; and (3) it usually contains code
95 which is executed when the system boots up. This sector contains a
96 table describing at most four partitions. These areas are called
99 The partition table in the primary boot sector may also describe at
100 most one "extended partition". This is a large area of the disk,
101 usually containing all the space which is not in any primary partition.
102 Within this space we can set aside other areas which are called
103 "logical partitions", because they look almost exactly like primary
104 partitions. In fact, the main difference between them is that we can
105 boot from primary partitions, while we cannot boot from logical
106 partitions. This happens because the address of a primary partition is
107 in a fixed place, whereas the address of a secondary partition is not,
108 so we require a more complicated process to discover it, one which is
109 too difficult for most primary boot programs.
112 Dividing up your disk
113 ---------------------
115 It is a good idea to plan ahead before you start creating partitions
116 on your disk. If you set aside a partition for some purpose, it is not
117 easy to change its size: you must backup all the data from the partition,
118 whether to floppies, to another partition, to another hard disk, or
119 somewhere else; then you must edit the table which describes this
120 partition, so changing its size; then you must reboot and initialise
121 the new partition, formatting it, for example, under DOS, or running
122 `mkfs' under Linux; finally you can copy all the data back. It is
123 possible, if you have several partitions, to copy data back and forth
124 between them while you change their sizes, but this is a bit risky and
125 time consuming. It is better to plan ahead what you will need, since
126 it is hard to change it afterwards.
128 Many people with large disks and recent versions of DOS have their
129 entire file system on one large partition. They usually ask, `Isn't
130 there any way I can reformat my disk without copying everything off?'
131 There is no way to do it using standard DOS utilities, and there is no
132 truly safe way to do it using commercial software, because, if you make
133 a mistake, you will lose the entire contents of your disk. If you are
134 going to back up your disk anyway, you might as well copy the data back
135 safely. The Linux FAQ contains references to tools and procedures
136 which will allow you to do this, if you dare.
138 DOS and Linux both allow you to access several partitions on a
139 single disk; on DOS these are treated as if they were separate disks or
140 drives, and under Linux they are treated as different "devices".
142 You can have up to 64 partitions on a single IDE disk, or up to 16
143 partitions on a single SCSI disk, at least as far as Linux is
144 concerned; in practice you will rarely want so many. The maximum size
145 of a Linux file system on a single partition depends on the type of
146 file system you use. Minix file systems are limited to 64 megabytes.
147 You may have all of your Linux files in a single partition, or you may
148 have two, three, or more Linux file systems. Similarly you may have
149 one or more DOS partitions. If you have several small partitions, you
150 run much less risk of losing all your files if your disk gets
151 corrupted. On the other hand, you may run out of space on a small
152 partition more easily.
154 Under DOS, you must refer to each partition by a separate drive
155 letter, but all partitions are automatically accessible. Under Linux
156 only the root partition is automatically accessible, but once we mount
157 another partition, it is indistinguishable from the rest of the file
158 system. Disks are usually mounted by a command in one of the system
159 startup files, `/etc/rc', so you need not worry about having to do it
160 yourself whenever you boot the system. But even ordinary users may
161 be allowed to mount removable hard disks and floppy disks.
163 Linux requires at least one partition, which is the `root' of the
164 file system. You may prefer to have a separate partition for `/usr',
165 which contains most of the executable files, or for `/home', which
166 contains most of your private files. You may also wish to set aside a
167 partition to use for swap space, depending on the amount of memory your
168 PC has. You will certainly need swap space if you have less than 4 MB
169 of RAM and wish to compile anything substantial. You can reserve swap
170 space in a file, but you need a partition big enough to hold it, and
171 this will probably be less efficient than having a partition devoted to
174 The disk space you need for Linux is discussed in README.prepare.
176 Are you going to boot Linux from the hard disk, or will you boot
177 from a floppy? Some boot programs place severe restrictions on where
178 the boot partition can be. LILO is more relaxed about this, but does
179 require either the Master Boot Record on your first hard disk, or the
180 boot record on one of the first four partitions on your first hard disk.
182 If you have an extended partition with logical partitions in it, you
183 can have only three primary partitions containing data.
189 Every operating system, whether DOS, OS/2, or Linux, should provide
190 its own utility for editing hard disk partition tables. At least four
191 of these utilities have been called `fdisk', for `Fixed DISK setup
192 program', where `fixed' means `not removable'. I believe the first PC
193 program named `fdisk' came from Microsoft in about 1985; before that
194 time disks were too small to divide into separate sections.
196 Every operating system has its own peculiarities. Normally you
197 should set up a partition for the use of one operating system by using
198 its own `fdisk' program. Do not use the Linux `fdisk' to create
199 partitions for DOS or for any system other than Linux; otherwise you
202 An `fdisk' program performs two functions: it reports how the disk is
203 configured, and it changes that configuration by adding or deleting
204 partitions. Most `fdisk' programs can also change other information in
207 This `fdisk' for Linux operates on one hard disk at a time. If you
212 it reports on, and is able to change, `/dev/hda', the first hard
213 disk. (If you have no `/dev/hda', `fdisk' uses `/dev/sda' as the
214 default device.) To look at or change the second hard disk, `/dev/hdb',
219 To look at or change the first SCSI disk, give the command
223 There are some special forms of the `fdisk' command. One of them,
224 suggested by Jim Winstead, simply lists all partitions on all available
227 fdisk -l (where `l' is a letter, not the digit `1')
229 The option `-v' is provided to list the current version of the
230 `fdisk' command. Finally, there is an option `-s' which is not really
231 intended for interactive use. It causes fdisk to print the size of a
232 partition in blocks of 1024 bytes as follows:
237 Because this is intended to be used by `mkfs' and `mkswap' programs,
238 it does not return the size of extended partitions or of partitions
239 whose system type code is less than 10 (hexadecimal a). If you start
240 `fdisk' without using one of these special options, it responds by
241 asking for a command:
243 Command (m for help): _
245 Each `fdisk' command consists of a single letter, which must be
246 followed by <RETURN> before it is obeyed. Upper and lower case are not
247 distinguished. Anything you type after the first character is ignored.
248 Give the command `m', and you should see this menu:
250 a toggle a bootable flag
252 l list known partition types
254 n add a new partition
255 p print the partition table
256 q quit without saving changes
257 t change a partition's system id
258 u change display/entry units
259 v verify the partition table
260 w write table to disk and exit
261 x extra functionality (experts only)
263 Command (m for help): _
265 The simplest commands are Print, Verify, and Quit. On a small disk, the
266 Print command might produce a display like this one:
268 Disk /dev/hda: 5 heads, 17 sectors, 977 cylinders
269 Units = cylinders of 85 * 512 bytes
271 Device Boot Begin Start End Blocks Id System
272 /dev/hda1 * 1 1 236 10021+ 1 DOS 12-bit FAT
273 /dev/hda2 837 837 977 5992+ 5 Extended
274 /dev/hda3 * 237 237 836 25500 83 Linux native
275 /dev/hda5 837 837 936 4249+ 82 Linux swap
276 /dev/hda6 942 942 977 1522 1 DOS 12-bit FAT
278 There are 5 partitions reported; `/dev/hda4' does not appear because
279 it is not allocated. Partitions 1 and 3 are flagged as bootable. The
280 size of each partition is reported in 1 kilobyte blocks; hence the
281 primary Linux partition, partition 3, is 25 1/2 megabytes in size. The
282 `+' after three of the sizes warns that these partitions contain an odd
283 number of sectors: Linux normally allocates filespace in 1 kilobyte
284 blocks, so the extra sector in partition 5 is wasted. Id numbers are
285 reported in hexadecimal and explained in English.
287 The display/entry units may be either cylinders or sectors. The
288 default is cylinders, but changing the units makes the print command
289 display the following table for the system reported above:
291 Disk /dev/hda: 5 heads, 17 sectors, 977 cylinders
292 Units = sectors of 1 * 512 bytes
294 Device Boot Begin Start End Blocks Id System
295 /dev/hda1 * 1 17 20059 10021+ 1 DOS 12-bit FAT
296 /dev/hda2 71060 71060 83044 5992+ 5 Extended
297 /dev/hda3 * 20060 20060 71059 25500 83 Linux native
298 /dev/hda5 71061 71061 79559 4249+ 82 Linux swap
299 /dev/hda6 79985 80001 83044 1522 1 DOS 12-bit FAT
301 The start of data in both DOS partitions is 16 sectors after the
302 beginning of the partition: this is one reason why you should use DOS's
303 own `FDISK' to create DOS partitions. Changing the units to sectors
304 also affects the way in which the new partition command asks for the
305 beginning and end of a new partition.
307 *Warning*: it is dangerous to create a new partition when the
308 display/entry units are sectors.
310 The Verify command is useful because
312 1. It warns you if anything is wrong. *Always* do a Verify command
313 to check your work before writing any changes to disk.
315 2. It reports how many unallocated sectors there are on the disk.
317 The Quit command is also useful. `fdisk' does not actually change
318 any data on your disk unless you give a Write command. If you are
319 unhappy about any changes you may have made, give the Quit command, and
320 your disk will remain as it was before you ran `fdisk'. You can also
321 interrupt `fdisk' with `CTRL-C'.
324 Deleting and adding partitions
325 ------------------------------
327 Deleting a partition is simple. Give the Delete command by typing
330 Partition number (1-6): _
332 Once you get this far, you must either delete a partition or
333 interrupt the program with `CTRL-C' (or whatever your current interrupt
336 1. You may delete a nonexistent partition. You will get a warning
339 2. You may delete an extended partition. This has the side effect of
340 deleting all partitions greater than or equal to 5.
342 3. You may delete a logical partition. In that case, all partitions
343 above it are renumbered at once. For example, if you delete
344 partition 5, then partition 6 becomes known as partition 5, and
345 partition 7 as partition 6.
347 Adding a partition is just a bit more complicated. Give the New
348 command by typing `n'. `fdisk' allows you to
350 1. Create a primary partition, if there is a free slot in the primary
353 2. Create an extended partition if there is a free slot in the
354 primary partition table, and if there is no extended partition.
356 3. Create a logical partition if an extended partition exists.
358 If more than one of these actions is possible, you will be asked to
359 select Primary, Extended, or Logical, depending on what is currently
360 permissible. Before you create a primary or an extended partition, you
361 are asked what slot it is to have in the table (1-4).
363 You may not add a primary or an extended partition if the selected
364 slot in the primary partition table is already occupied: in that case
365 you simply return to the main menu. You are not allowed to add a new
366 primary partition unless there are sectors available outside the
367 extended partition. You are not allowed to add a new logical partition
368 unless there are sectors available inside the extended partition.
370 If space is available, you are prompted for the first cylinder:
372 First cylinder ([237]-977): _
374 The limits are the lowest and the highest cylinders in which sectors
375 are available in the appropriate part of the disk. The square-bracketed
376 number is what you'll get if you simply press enter. Not all numbers in
377 this range are necessarily available: they may fall inside an existing
378 partition. If you select a cylinder which is already in use, you are
379 told off and prompted again for the first cylinder. After selecting the
380 first cylinder, you are prompted again:
382 Last cylinder or +size or +sizeM or +sizeK (237-[836]): _
384 The limits are the cylinder you have chosen as the first cylinder,
385 and the highest cylinder which contains a legitimate upper boundary for
386 the new partition. The square-bracketed number is what you'll get if
387 you simply press enter. In other words, all numbers in the given range are
388 legitimate, unlike those in the first range of cylinders. You may also
389 specify the size of a partition in megabytes, kilobytes, or in the
390 current units (cylinders or sectors). A plus sign `+' indicates that
391 your answer is a size rather than a boundary, and the suffix `m' or `k'
392 (upper or lower case) indicates that the size is not given in units of
393 sectors or cyliners, but in megabytes or kilobytes respectively. Thus
394 possible answers to the last cylinder request above are
397 Make cylinder 700 the last cylinder in the partition.
400 Make cylinder 237 + 300 = 537 the last cylinder in the partition.
403 Make the partition at least 15 megabytes in size.
406 Make the partition at least 12,500 kilobytes in size.
408 If you specify a size which is too large or an end which is out of
409 range, fdisk complains and repeats the prompt.
411 Adding or deleting partitions has no effect unless you subsequently
412 give the Write command. Please remember to give the Verify command
413 first, just before giving the Write command: this is a safety
414 precaution. After giving the Write command, you will see this message:
416 The partition table has been altered!
417 Calling ioctl() to re-read partition table.
420 If there are no further messages, the kernel has successfully copied
421 the information from the partition table into its own internal table.
422 But sometimes you will see a message like this one:
424 Re-read table failed with error 16: Device or resource busy.
425 Reboot your system to ensure the partition table is updated.
427 In this case, depending on what you have changed in the partition
428 table, it may be dangerous to continue working without rebooting,
429 since you may lose or corrupt your data.
432 Here are some important things to note:
434 1. Before you reboot, you *may* run `fdisk' again, either to manage
435 another disk, or to make additional changes to the same disk, or
436 just to check that the changes have been made as you expected.
437 This is true even after you receive the message warning you to
440 2. It is not a good idea to run any of the programs `mkfs', `mkswap',
441 `mount', or `swapon' if you have received the warning message but
442 have not rebooted. In this case it is dangerous to run any program,
443 but these in particular may cause serious damage to the data on your
444 disk, including the partition tables themselves.
447 Active flags and system types
448 -----------------------------
450 The active flag is a bit in the partition table entry which marks a
451 partition as bootable. This is important to some primary boot sector
452 programs, which will not boot from an unflagged partition. Other such
453 programs do not allow more than one partition to be flagged. Some,
454 like LILO, ignore the flags completely. I prefer to flag all bootable
455 partitions as active so that they stand out on the menu which `fdisk'
456 lists. Fdisk prints a star after the name of a partition's device file
457 if its active flag is set.
459 The Active command changes, or toggles, a partition's active flag.
460 Give the Active command, and select a partition by number. If it was
461 marked inactive, it will be flagged as active; if it was flagged as
462 active, it will be marked inactive. You may set the active flag on an
463 extended or logical partition, though the meaning of such a flag is by
464 no means clear. This can be used to install LILO as a secondary boot
465 loader to boot a Linux which lives on a second hard disk.
467 The Type command changes the ID number which describes what type a
468 partition is. `fdisk' currently recognises 30 system IDs, in the sense
469 that it prints a string for each of them, but it allows you to change
470 any system ID to any other, with the following exceptions: you may not
471 change any partition to or from the type Extended, and you may not
472 change a partition whose type is Empty (0) to any other type. You may,
473 however, change the type of any data partition to 0, which is
474 equivalent to deleting it.
476 The new system ID or type code is a hexadecimal number. There are
477 two ways of listing the numbers which `fdisk' recognises: use the List
478 command, which prints the list, or use the Type command, which, when it
479 prompts you for the code, says
481 Hex code (type L to list codes): _
483 where the upper case `L' is used for clarity. The codes printed are:
484 Some of these numbers are a trifle uncertain. By default `fdisk' uses
485 a type of 83. It used to use 81, the type code used by the MINIX
486 `fdisk'. It seemed prudent to change the default since (a) many Linux
487 `minix' file systems are no longer compatible with MINIX, (b) the ext2
488 file system, a native Linux file system, is fairly stable, as is the
489 Xia file system, and (c) the number 81 causes problems with DR-DOS.
490 Linux does not usually care what values you use for type codes, but
491 other systems, in particular DOS, OS/2, and DR-DOS, may.
493 The value of 82 for Linux swap partitions is my own invention, and
494 is intended to give some recognisable distinction to the partitions
495 when the values are displayed in hexadecimal.
497 New active flags and new system type codes are not written to the
498 disk until you exit from `fdisk' with the Write command, as described
499 above, in the section on deleting and adding partitions.
502 Extra commands for experts
503 --------------------------
505 The eXtra command `x' puts `fdisk' into `expert' mode, in which a
506 slightly different set of commands is available. The Active, Delete,
507 List, New, Type, Verify, and `eXpert' commands are not available in
508 expert mode. The commands Write and Quit are available as in ordinary
509 mode, the Print command is available, but produces output in a slightly
510 different format, and of course the Menu command prints the expert
511 menu. There are several new commands.
513 1. The Return command brings you back to the main menu.
515 2. The Extended command prints the list of table entries which point
516 to other tables. Ordinary users do not need this information.
517 The data is shown as it is stored. The same format is used for
518 the expert Print command.
520 3. The dangerous Begin command allows you to move the start of data
521 in a partition away from its beginning. Other systems create
522 partitions with this format, and it is sometimes useful to be able
525 4. The slightly dangerous Cylinders command allows you to change the
526 available number of cylinders. For SCSI disk owners, note that we
527 require not the actual number of physical cylinders, but the
528 number of logical cylinders used by DOS and other operating
531 5. The extremely dangerous Heads and Sectors commands allow you to
532 change the number of heads and sectors. It should not be
533 necessary to use these commands unless you have a SCSI disk, whose
534 geometry Linux is not always able to determine. SCSI disk owners
535 note that we need not the actual number of heads or of sectors per
536 track, but the number believed to exist by DOS and other operating
537 systems. *Warning*: If you set either of these numbers to a bad
538 value, you may lose all data on your disk.
540 Always, after giving any of the commands Begin, Cylinder, Heads, or
541 Sectors, you should Return to the main menu and give the Verify command.
544 Warnings for `fdisk' users
545 --------------------------
547 In general, you should not use this `fdisk' program to create
548 partitions for other operating systems, only for Linux. Nor should you
549 use `fdisk' commands from other operating systems to create partitions
552 DR-DOS 5.0 and 6.0 are reported to have difficulties with partition
553 ID codes of 80 or more. The Linux `fdisk' used to set the system type
554 of new partitions to hexadecimal 81. DR-DOS seems to confuse this with
555 hexadecimal 1, a DOS code. The values 82 for swap and 83 for file
556 systems should not cause problems with DR-DOS. If they do, you may use
557 the `fdisk' command `t' to change the system code of any Linux
558 partitions to some number less than hexadecimal 80; I suggest 42 and 43
561 Partitioning a hard disk may destroy data which is on that disk if you
562 are not careful. Go slowly, write down a description of the partition
563 tables before you changed them, and always verify before you write.
565 Most operating systems and utilities expect that all partitions begin and
566 end at cylinder boundaries. This version of `fdisk' does so by default,
567 but you can use it to create partitions which begin or end anywhere.
568 This does not normally affect Linux, but it is very dangerous, as other
569 operating systems (including DOS) may try to `correct' the partition
572 It is dangerous to create a new partition when the display/entry
575 The Verify command warns you if anything is wrong. *Always* give a
576 Verify command before writing any changes to disk.
578 If you set the disk geometry (tracks per cylinder, or sectors per
579 track) to an incorrect value, you may lose all data on your disk.
581 Do create BSD/SUN and/or IRIX/SGI disk labels only when you are sure
582 that you want them. Both features are intended to allow you READing
583 those labels and prevent unintentional formatting of these disks.