xref: /netbsd-src/sbin/fdisk/fdisk.8 (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1.\"	$NetBSD: fdisk.8,v 1.85 2014/04/04 13:07:30 wiz Exp $
2.\"
3.Dd April 3, 2014
4.Dt FDISK 8
5.Os
6.Sh NAME
7.Nm fdisk
8.Nd MS-DOS partition maintenance program
9.Sh SYNOPSIS
10.Nm
11.Op Fl aBFfIiSuv
12.Oo
13.Fl 0 | 1 | 2 | 3 | E Ar number
14.Op Fl s Oo Ar id Oc Ns Oo / Ns Oo Ar start Oc Ns Oo / Ns Oo Ar size Oc Ns Oo / Ns Oo Ar bootmenu Oc Oc Oc Oc
15.Oc
16.Op Fl r Ar file | Fl w Ar file
17.Op Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset
18.Op Fl b Ar cylinders/heads/sectors
19.Op Fl c Ar bootcode
20.Op Fl T Ar disktype
21.Op Fl t Ar disktab
22.Op Fl z Ar sectorsize
23.Op Ar device
24.Nm
25.Fl l
26.Sh DESCRIPTION
27The
28.Nm
29program is used to display or update the
30.Em "master boot record"
31or
32.Em MBR
33in the first sector (sector 0)
34of a disk that uses the MBR style of partitioning.
35The following
36.Nx
37ports use this style of disk partitioning:
38amd64, arc, bebox, cobalt, hpcarm, hpcmips, hpcsh, i386, macppc,
39mvmeppc, netwinder, ofppc, playstation2, and prep.
40.Pp
41The MBR contains bootable code, a partition table,
42an indication of which partition is
43.Sq active ,
44and (optionally, depending on the boot code) a menu
45for selecting a partition to be booted.
46There can be at most 4 partitions defined in sector 0,
47one of which can be an extended
48partition which can be split into any number of sub-partitions (then called
49logical partitions).
50.Pp
51The boot code in the MBR is usually invoked by the BIOS or firmware,
52and the MBR passes control to the next stage boot code
53stored in the first sector of the partition to be booted
54(the
55.Em "partition boot record"
56or
57.Em PBR ) .
58.Pp
59After booting,
60.Nx
61does not use the partitioning done by
62.Nm ,
63instead it uses a
64.Nx
65disklabel saved in sector 1 of the
66.Nx
67partition.
68See
69.Xr mbrlabel 8
70for a way of using information from the MBR
71to construct a
72.Nx
73disklabel.
74.Pp
75The standard MBR boot code will only boot the
76.Sq active
77partition.
78However,
79.Nx
80contains additional boot programs which allow the user to
81interactively select which of the partitions to boot.
82The
83.Sq mbr_ext
84code will also boot
85.Nx
86from an extended partition but will not work on old systems that do not
87support LBA reads, the
88.Sq mbr_com0
89and
90.Sq mbr_com0_9600
91will read and write from a serial port.
92At the start the
93.Nm
94program will determine whether the disk sector 0 is valid as a boot sector.
95(This is determined by checking the magic number.)
96If not,
97.Nm
98will initialise the boot code as well as the partition table.
99During this, all four partitions will be marked empty.
100.Pp
101The flags
102.Fl a ,
103.Fl i
104or
105.Fl u
106are used to indicate that the partition data is to be updated.
107The
108.Nm
109program will enter an interactive conversational mode.
110This mode is designed not to change any data unless you explicitly tell it to;
111.Nm
112selects defaults for its questions to guarantee that behaviour.
113.Pp
114If partition data is going to be updated and the disk carries GUID Partition
115Tables,
116.Nm
117will remove both primary and backup GPT headers from the disk.
118See
119.Xr gpt 8
120for information on how to manipulate GUID Partition Tables.
121.Pp
122.Nm
123will calculate the correct
124.Em cylinder ,
125.Em head ,
126and
127.Em sector
128values for any partition you edit.
129If you specify
130.Fl v
131you will be asked whether you want to specify them yourself.
132.Pp
133Finally, when all the data for the first sector has been accumulated,
134.Nm
135will ask if you really want to write the new partition table.
136Only if you reply affirmatively to this question will
137.Nm
138write anything to the disk.
139.Pp
140Available options:
141.Bl -tag -width Ds
142.It Fl 0
143Specify partition slot 0 to be printed or updated.
144.It Fl 1
145Specify partition slot 1 to be printed or updated.
146.It Fl 2
147Specify partition slot 2 to be printed or updated.
148.It Fl 3
149Specify partition slot 3 to be printed or updated.
150.It Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset
151Specify the alignment for all partitions and optionally the offset for the
152first partition of the disk and of logical partitions.
153If
154.Ar ptn_alignment
155is specified and
156.Ar ptn_0_offset
157is not specified, then the offset is set to the alignment.
158If
159.Fl A
160isn't specified, then the alignment of the first partition is inspected.
161If it ends on a 2048 sector boundary, then the alignment is set to 2048,
162if the start is a power of 2 less than, or equal to 2048 then the offset
163is set to the start sector.
164If the first partition isn't defined then the alignment and offset for disks
165larger than 128GB is set to 2048 (1MB).
166In all other cases the alignment default to a cylinder
167and the offset to a track (both using the BIOS geometry).
168The 1MB alignment is the same as that used by recent windows versions.
169.It Fl a
170Change the active partition.
171In interactive mode this question will be asked after the partitions
172have been processed.
173.It Fl B
174On an i386 or amd64 system, interactively update the boot selector settings.
175(The boot selector permits the user to interactively select the boot
176partition, and thus which operating system is run, at system boot time; see
177.Xr mbr 8
178for more information.)
179.It Fl b Ar cylinders/heads/sectors
180Specify the BIOS geometry parameters for
181.Ar cylinders ,
182.Ar heads ,
183and
184.Ar sectors .
185It is used only in conjunction with the
186.Fl u
187flag.
188If not specified the BIOS geometry will be obtained using sysctl (i386 and
189amd64) or by solving the simultaenous equations from the existing partition
190information.
191If that fails then either the geometry from the disklabel or 63 sectors and
19216 heads is used.
193For modern disks larger than about 8GB, and where the BIOS is configured
194to use LBA-Assisted translation, a setting of
195.Fl b Ar 1023/255/63
196is likely to work.
197.\" see http://web.inter.nl.net/hcc/J.Steunebrink/bioslim.htm#LBA
198.\" for a table of C/H/S values used in LBA-Assisted translation mode
199.It Fl c Ar bootcode
200Specify the filename that
201.Nm
202should read the bootcode from.
203If the name of a directory is specified, then
204.Nm
205will look for files with the default names in that directory.
206The default is to read from
207.Pa /usr/mdec/mbr ,
208.Pa /usr/mdec/mbr_bootsel
209or
210.Pa /usr/mdec/mbr_ext
211depending on whether
212.Ar bootmenu
213was specified for any partitions
214on an i386 machine, and leave the bootcode empty for other
215machines.
216.It Fl E Ar number
217Specify logical partition
218.Ar number
219to be printed or updated.
220If the specified logical partition doesn't exist on updating partition data
221an additional logical partition will be created.
222.It Fl F
223Indicate that
224.Ar device
225is a regular file.
226Unless the geometry of
227.Ar device
228is told to
229.Nm
230by
231.Fl T Ar disktype ,
232.Nm
233will count the 512-byte sectors in
234.Ar device
235and produce a fake geometry.
236If
237.Ar device
238is a regular file,
239.Fl F
240will be used implicitly.
241.It Fl f
242Run
243.Nm
244in a non-interactive mode.
245In this mode, you can only change the disk parameters by using the
246.Fl b
247flag.
248This is provided only so scripts or other programs may use
249.Nm
250as part of an automatic installation process.
251.Pp
252Using the
253.Fl f
254flag with
255.Fl u
256makes it impossible to specify the starting and ending
257.Ar cylinder ,
258.Ar head ,
259and
260.Ar sector
261fields
262.Pq only Ar start No and Ar size No can be specified by Fl s No option .
263They will be automatically computed using the BIOS geometry.
264.It Fl I
265Ignore errors from overlapping partitions.
266Some devices (cameras CHDK) require overlapping partitions to support
267bigger than 4GB cards.
268The
269.Fl I
270flag ignores overlapping error checks and does not fix them, allowing these
271incorrect configurations to be used.
272.It Fl i
273Explicitly request initialisation of the master boot code
274(similar to what
275.Ic fdisk /mbr
276does under
277.Tn MS-DOS ) ,
278even if the magic number in the first sector is ok.
279The partition table is left alone by this (but see above).
280.It Fl l
281Lists known
282.Em sysid
283values and exit.
284.It Fl r Ar file
285Read the boot record from file
286.Ar file
287instead of the specified disk.
288The geometry information used is still that of the disk volume.
289Any changes are written back to the file.
290.It Fl S
291When used with no other flags print a series of
292.Pa /bin/sh
293commands for setting variables to the partition information.
294This could be used by installation scripts.
295.It Fl s Oo Ar id Oc Ns Oo / Ns Oo Ar start Oc Ns Oo / Ns Oo Ar size Oc Ns Oo / Ns Oo Ar bootmenu Oc Oc Oc Oc
296Specify the partition
297.Ar id ,
298.Ar start ,
299.Ar size ,
300and
301.Ar bootmenu .
302If the optional arguments are not provided, they stay as before or
303use the same defaults as the interactive mode, if new.
304This flag requires the use of a partition selection flag
305.Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number .
306.It Fl T Ar disktype
307Use the disklabel
308.Ar disktype
309instead of the disklabel on
310.Ar device .
311.It Fl t Ar disktab
312Read
313.Ar disktype
314from the named
315.Xr disktab 5
316file instead of from
317.Pa /etc/disktab .
318.It Fl u
319Update partition data, including
320.Em id , start , No and Em size .
321Unless
322.Fl f
323option
324.Pq non-interactive mode
325is specified,
326.Nm
327will display the partitions and interactively ask which one you want to edit.
328.Nm
329will step through each field showing the old value and asking for a new one.
330The
331.Em start
332and
333.Em size
334can be specified in blocks (NN),
335cylinders (NNc or NNcyl),
336megabytes (NNm or NNMB),
337or gigabytes (NNg or NNGB), values in megabytes and gigabytes
338will be rounded to the nearest cylinder boundary.
339The
340.Em size
341may be specified as
342.Em $
343in which case the partition will extend to the end of the available free space.
344.Pp
345In a non-interactive mode
346.Pq specified by Fl f No option ,
347partition data should be specified by
348.Fl s
349option.
350A partition selection option
351.Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number
352should also be specified to select a partition slot to be updated.
353.Pp
354.Nm
355will not allow you to create partitions which overlap.
356If
357.Fl u
358and
359.Fl s
360are specified in a non-interactive mode
361then the details of the specified partition will be changed.
362Any other partitions which overlap the requested part of the disk will be
363silently deleted.
364.Pp
365If
366.Em bootmenu
367is specified for any partition
368.Nm
369will determine whether the installed boot code supports the bootselect code,
370if it doesn't you will be asked whether you want to install the required
371boot code.
372To remove a
373.Em bootmenu
374label, simply press
375.Aq space
376followed by
377.Aq return .
378.It Fl v
379Be more verbose, specifying
380.Fl v
381more than once may increase the amount of output.
382.Pp
383Using
384.Fl v
385with
386.Fl u
387allows the user to change more parameters than normally permitted.
388.It Fl w Ar file
389Write the modified partition table to file
390.Ar file
391instead of the disk.
392.It Fl z Ar sectorsize
393Specify a sector size other than 512, for devices that only
394support larger sector sizes.
395The sector size needs to be a power of two greater than 512.
396.El
397.Pp
398When called with no arguments, it prints the partition table.
399An example follows:
400.Bd -literal
401    Disk: /dev/rwd0d
402    NetBSD disklabel disk geometry:
403    cylinders: 16383, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
404    total sectors: 40032696
405
406    BIOS disk geometry:
407    cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
408    total sectors: 40032696
409
410    Partition table:
411    0: NetBSD (sysid 169)
412	bootmenu: net 1.5.
413	start 4209030, size 8289540 (4048 MB, Cyls 262-778), Active
414    1: Primary DOS with 32 bit FAT (sysid 11)
415	bootmenu: win98
416	start 63, size 4208967 (2055 MB, Cyls 0-262)
417    2: NetBSD (sysid 169)
418	bootmenu: current
419	start 32515560, size 7517136 (3670 MB, Cyls 2024-2491/234/40)
420    3: Ext. partition - LBA (sysid 15)
421	start 12498570, size 20016990 (9774 MB, Cyls 778-2024)
422    Extended partition table:
423    E0: NetBSD (sysid 169)
424	bootmenu: test
425	start 12498633, size 12305727 (6009 MB, Cyls 778-1544)
426    E1: Primary DOS with 32 bit FAT (sysid 11)
427	start 24804423, size 4096512 (2000 MB, Cyls 1544-1799)
428    E2: Primary DOS with 32 bit FAT (sysid 11)
429	start 28900998, size 3614562 (1765 MB, Cyls 1799-2024)
430    Bootselector enabled, infinite timeout.
431    First active partition: 0
432.Ed
433.Pp
434This example disk is divided into four partitions, the last of which is
435an extended partition.
436The logical partitions of the extended partition are also shown.
437In this case there is no free space in either the disk or in the extended
438partition.
439.Pp
440The various fields in each partition entry are:
441.Bd -filled -offset 4n -compact
442.Em ptn_number : id_name
443(sysid
444.Em id_number )
445.Ed
446.Bd -filled -offset 8n -compact
447bootmenu:
448.Em bootmenu
449.br
450start
451.Em start ,
452size
453.Em size ( MB
454MB, Cyls
455.Em first Ns No - Ns Em next )
456.Op , Active
457.Ed
458.Bl -tag -width "bootmenu"
459.It Em ptn_number
460is the number of the partition.
461.It Em id_name
462is the name of the filesystem type or operating system that uses this partition.
463.It Em id_number
464is the number that identifies the partition type.
465169 decimal is used for
466.Nx
467partitions,
46815 decimal to create an extended partition
469and 0 to mark a partition as unused.
470Use
471.Nm
472.Fl l
473to list the known partition types.
474.It Em bootmenu
475is the menu prompt output by the interactive boot code for this partition.
476This line is omitted if the prompt is not defined.
477.It Em start , Em size
478are the start address and size of the partition in sectors.
479.It Em MB
480is the size of the partition in megabytes.
481.It Em first , Em next
482are the bounds of this partition displayed as cylinder/head/sector.
483If the partition starts (or ends) on a cylinder boundary the head and
484sector values are omitted.
485If
486.Fl v
487is not specified the start of logical partitions and the first partition
488on the disk are rounded down to include the mandatory red tape in the
489preceding track.
490.It Active
491is output if this is the active partition.
492.El
493.Pp
494If the
495.Fl v
496flag is specified, the beginning and end of each partition are also
497displayed as follows:
498.Bd -filled -offset 4n -compact
499beg: cylinder
500.Em cylinder ,
501head
502.Em head ,
503sector
504.Em sector
505.br
506end: cylinder
507.Em cylinder ,
508head
509.Em head ,
510sector
511.Em sector
512.Ed
513.Bl -tag -width "bootmenu"
514.It Em "cylinder" , Em "head" , Em "sector"
515are the beginning or ending address of a partition.
516.Pp
517.Em "Note:"
518these numbers are read from the bootblock, so are the values calculated
519by a previous run of
520.Nm .
521.El
522.Pp
523.Nm
524attempts to check whether each partition is bootable,
525by checking the magic number and some other characteristics
526of the first sector of each partition (the PBR).
527If the partition does not appear to be bootable,
528.Nm
529will print a line containing
530.Dq "PBR is not bootable"
531followed by an error message.
532If the partition is bootable, and if the
533.Fl v
534flag is specified,
535.Nm
536will print
537.Dq "PBR appears to be bootable" .
538If the
539.Fl v
540flag is specified more than once,
541.Nm
542will print the heading
543.Dq "Information from PBR:"
544followed by one or more lines of information gleaned from the PBR;
545this additional information may be incorrect or misleading,
546because different operating systems use different PBR formats.
547Note that, even if no errors are reported, an attempt to boot
548from the partition might fail.
549.Nx
550partitions may be made bootable using
551.Xr installboot 8 .
552.Sh NOTES
553This program is only available (and useful) on systems with PC-platform-style
554MBR partitioning.
555.Pp
556Traditionally the partition boundaries should be on cylinder boundaries
557using the BIOS geometry, with the exception of the first partition,
558which traditionally begins in the second track of the first cylinder
559(cylinder 0, head 1, sector 1).
560Although the BIOS geometry is typically different from the geometry
561reported by the drive, neither will match the actual physical geometry
562for modern disks (the actual geometry will vary across the disk).
563Keeping the partition boundaries on cylinder boundaries makes partitioning
564a driver easier as only relatively small numbers need be entered.
565.Pp
566The automatic calculation of the starting cylinder and
567other parameters uses
568a set of figures that represent what the BIOS thinks is the
569geometry of the drive.
570The default values should be correct for the system on which
571.Nm
572is run; however, if you move the disk to a different system, the
573BIOS of that system might use a different geometry translation.
574.Pp
575If you run the equivalent of
576.Nm
577on a different operating system then the
578.Ar bootmenu
579strings associated with extended partitions may be lost.
580.Pp
581Editing an existing partition is risky, and may cause you to
582lose all the data in that partition.
583.Pp
584You should run this program interactively once or twice to see how it works.
585This is completely safe as long as you answer the last question in the negative.
586You can also specify
587.Fl w Ar file
588to write the output to a file and later specify
589.Fl r Ar file
590to read back the updated information.
591This can be done without having write access to the disk volume.
592.Sh FILES
593.Bl -tag -width /usr/mdec/mbrxxxxxxxx -compact
594.It Pa /usr/mdec/mbr
595Default location of i386 bootcode
596.It Pa /usr/mdec/mbr_bootsel
597Default location of i386 bootselect code
598.It Pa /usr/mdec/mbr_ext
599Default location of i386 bootselect for extended partitions (i.e., NetBSD on
600logical partitions)
601.El
602.Sh EXAMPLES
603Update MBR partition data of
604.Pa /dev/rwd0d
605in interactive mode:
606.Pp
607.Dl Ic fdisk -u /dev/rwd0d
608.Pp
609Change active MBR partition of
610.Pa /dev/rwd0d
611in interactive mode:
612.Pp
613.Dl Ic fdisk -a /dev/rwd0d
614.Pp
615Install MBR bootcode
616.Pa /usr/mdec/mbr_bootsel
617into
618.Pa /dev/rwd0d :
619.Pp
620.Dl Ic fdisk -c /usr/mdec/mbr_bootsel /dev/rwd0d
621.Pp
622Set MBR partition data for slot 0 of
623.Pa /dev/rwd0d
624specifying values without prompt:
625.Pp
626.Dl Ic fdisk -f -u -0 -s 169/63/2097089 /dev/rwd0d
627.Pp
628Make partition slot 0 of
629.Pa /dev/rwd0d
630active without prompt:
631.Pp
632.Dl Ic fdisk -f -a -0 /dev/rwd0d
633.Pp
634Initialize and create MBR partition data using bootcode
635.Pa destdir/usr/mdec/mbr
636without prompt against 1GB disk image file
637.Pa diskimg :
638.Pp
639.Dl Ic fdisk -f -i -b 130/255/63 -c destdir/usr/mdec/mbr -F diskimg
640.Pp
641Create MBR partition data for slot 0 which has an active
642.Nx
643partition using whole disk without prompt against 1GB disk image file
644.Pa diskimg :
645.Pp
646.Dl Ic fdisk -f -a -u -0 -s 169/63/2097089 -F diskimg
647.Sh SEE ALSO
648.Xr disktab 5 ,
649.Xr boot 8 ,
650.Xr disklabel 8 ,
651.Xr gpt 8 ,
652.Xr installboot 8 ,
653.Xr mbr 8 ,
654.Xr mbrlabel 8
655.Sh BUGS
656The word
657.Sq partition
658is used to mean both an MBR partition and a
659.Nx
660partition, sometimes in the same sentence.
661.Pp
662There are subtleties that the program detects that are not explained in
663this manual page.
664