xref: /netbsd/sbin/fdisk/fdisk.8 (revision c4a72b64)
1.\"	$NetBSD: fdisk.8,v 1.31 2002/10/01 13:40:29 wiz Exp $
2.\"
3.Dd December 19, 2000
4.Dt FDISK 8
5.Os
6.Sh NAME
7.Nm fdisk
8.Nd DOS partition maintenance program
9.Sh SYNOPSIS
10.Nm ""
11.Op Fl aiufBS
12.Bk -words
13.Op Fl 0 | 1 | 2 | 3
14.Ek
15.Bk -words
16.Op Fl b Ar cylinders/heads/sectors
17.Ek
18.Bk -words
19.Op Fl s Ar id/start/size
20.Ek
21.Bk -words
22.Op Fl c Ar bootcode
23.Ek
24.Bk -words
25.Op Ar device
26.Ek
27.Sh DESCRIPTION
28In order for the BIOS to boot the kernel, certain conventions must be
29adhered to.
30Sector 0 of the disk must contain boot code, a partition table, and a
31magic number.
32Newer BIOS programs want the entire first track reserved.
33BIOS partitions can be used to break the disk up into several pieces.
34The BIOS brings in sector 0, verifies the magic number, and begins
35executing the code at the first byte.
36This code in turn searches the DOS partition table for an `active'
37partition.
38If one is found, the boot block from that partition is loaded and replaces
39the original boot block.
40Under DOS, you could have one or more partitions with one active.
41The DOS
42.Nm
43program can be used to divide space on the disk into partitions and set
44one active.
45.Pp
46The
47.Nx
48program
49.Nm
50serves a similar purpose to the DOS program.
51When called with no arguments, it prints the sector 0 partition table.
52An example follows:
53.Bd -literal
54	NetBSD disklabel disk geometry:
55	cylinders: 769 heads: 15 sectors/track: 33 (495 sectors/cylinder)
56
57	BIOS geometry:
58	cylinders: 769 heads: 15 sectors/track: 33 (495 sectors/cylinder)
59
60	Partition table:
61	0: sysid 169 (NetBSD)
62    	    start 495, size 380160 (185 MB), flag 0
63		beg: cylinder    1, head   0, sector  1
64		end: cylinder  768, head  14, sector 33
65	1: sysid 164 (reserved)
66    	    start 378180, size 2475 (1 MB), flag 0
67		beg: cylinder  764, head   0, sector  1
68		end: cylinder  768, head  14, sector 33
69	2: \*[Lt]UNUSED\*[Gt]
70	3: sysid 99 (GNU HURD or Mach or Sys V/386 (such as ISC UNIX))
71    	    start 380656, size 224234 (109 MB), flag 80
72		beg: cylinder  769, head   0, sector  2
73		end: cylinder  197, head  14, sector 33
74.Ed
75.Pp
76This example disk is divided into three partitions that happen to fill the
77disk.
78The second partition overlaps the end of the first
79.Po
80used for debugging purposes
81.Pc .
82.Pp
83The various fields in each partition are:
84.Bl -tag -width "cylinder"
85.It Em "sysid"
86is used to label the partition.
87.Nx
88reserves the magic number 169 decimal (A9 in hex).
89The number 0 is used to mark a partition as unused.
90See the
91.Fl l
92flag.
93.It Xo
94.Em start ,
95.Em size
96.Xc
97start address and size of a partition in sectors.
98.It Em "flag 80"
99specifies that this is the active partition.
100.It Xo
101.Em "cylinder" ,
102.Em "head" ,
103.Em "sector"
104.Xc
105the beginning or ending address of a partition.
106.El
107.Pp
108.Em "Note:"
109these numbers are calculated using BIOS's understanding of the disk geometry
110and saved in the bootblock.
111.Pp
112At the start the
113.Nm
114program will determine whether the disk sector 0 is valid as a boot sector.
115(This is determined by checking the magic number.)
116If not,
117.Nm
118will initialize the boot code as well as the partition table.
119During this, all four partitions will be marked empty.
120.Pp
121The flags
122.Fl a ,
123.Fl i
124or
125.Fl u
126are used to indicate that the partition data is to be updated.
127The
128.Nm
129program will enter an interactive conversational mode.
130This mode is designed not to change any data unless you explicitly tell it to;
131.Nm
132selects defaults for its questions to guarantee that behavior.
133.Pp
134Getting the
135.Em cylinder ,
136.Em head ,
137and
138.Em sector
139fields correct is tricky.
140So by default,
141they will be calculated for you;
142you can specify them if you choose.
143.Pp
144Finally,
145when all the data for the first sector has been accumulated,
146.Nm
147will ask if you really want to rewrite sector 0.
148Only if you reply affirmatively to this question will
149.Nm
150write anything to the disk.
151.Pp
152Available options:
153.Pp
154.Bl -tag -width Ds
155.It Fl 0
156Update partition slot 0.
157.It Fl 1
158Update partition slot 1.
159.It Fl 2
160Update partition slot 2.
161.It Fl 3
162Update partition slot 3.
163.It Fl a
164Change the active partition.
165In interactive mode this question will be asked after the partitions
166have been processed.
167.It Fl b Ar cylinders/heads/sectors
168Specify the BIOS parameters for
169.Ar cylinders ,
170.Ar heads
171and
172.Ar sectors .
173It is used only in conjunction with the
174.Fl u
175flag.
176.It Fl B
177Install or update the bootselect code on an i386 machine.
178.It Fl c Ar bootcode
179Specify the filename that
180.Nm
181should read the bootcode from.
182The default is to read from
183.Pa /usr/mdec/mbr
184if run on an i386 machine, and leave the bootcode empty for other
185machines.
186.It Fl f
187Run
188.Nm
189in a non-interactive mode.
190In this mode, you can only change the disk parameters by using the
191.Fl b
192flag.
193This is provided only so scripts or other programs may use
194.Nm
195as part of an automatic installation process.
196Using the
197.Fl f
198flag with
199.Fl u
200makes it impossible to specify the starting and ending
201.Ar cylinder ,
202.Ar head
203and
204.Ar sector
205fields.
206They will be automatically computed using the BIOS geometry.
207.It Fl i
208Explicitly request initialization of the master boot code
209(similar to what
210.Nm fdisk /mbr
211does under
212.Tn MSDOS ) ,
213even if the magic number in the first sector is ok.
214The partition table is left alone by this (but see above).
215.It Fl l
216Lists known
217.Em sysid
218values and exit.
219.It Fl s Ar id/start/size
220Specify the partition
221.Ar id ,
222.Ar start
223and
224.Ar size .
225This flag requires the use of a partition selection flag
226.Po
227.Fl 0 ,
228.Fl 1 ,
229.Fl 2 ,
230or
231.Fl 3
232.Pc
233.It Fl S
234When used with no other flags print a series of
235.Pa /bin/sh
236commands for setting variables to the partition information.
237This is used by the installation scripts.
238.It Fl u
239Display each partition in turn and interactively ask if you want to edit it.
240If you reply affirmatively, it will step through each field showing the old
241value and asking for a new one.
242When you are done with a partition,
243.Nm
244will display the information again and ask if it is correct.
245.Nm
246will then proceed to the next entry.
247.El
248.Sh NOTES
249The automatic calculation of the starting cylinder and
250other parameters uses
251a set of figures that represent what the BIOS thinks is the
252geometry of the drive.
253These figures are by default taken from the incore disklabel, but
254.Nm
255gives you an opportunity to change them.
256This allows the user to create a bootblock that can work with drives
257that use geometry translation under the BIOS.
258.Pp
259Editing an existing partition is risky, and may cause you to
260lose all the data in that partition.
261.Pp
262You should run this program interactively once or twice to see how it works.
263This is completely safe as long as you answer the last question in the negative.
264.Sh FILES
265.Bl -tag -width /usr/mdec/mbrxxxxxxxx -compact
266.It Pa /usr/mdec/mbr
267Default location of i386 bootcode
268.It Pa /usr/mdec/mbr_bootsel
269Default location of i386 bootselect code
270.El
271.Sh SEE ALSO
272.Xr disklabel 8 ,
273.Xr mbr 8 ,
274.Xr mbrlabel 8
275.Sh BUGS
276There are subtleties that the program detects that are not explained in
277this manual page.
278