.\" $OpenBSD: fdisk.8,v 1.45 2005/03/29 19:35:25 otto Exp $ .\" .\" Copyright (c) 1997 Tobias Weingartner .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .Dd January 3, 2002 .Dt FDISK 8 .Os .Sh NAME .Nm fdisk .Nd DOS partition maintenance program .Sh SYNOPSIS .Nm fdisk .Op Fl ieu .Op Fl f Ar mbrname .Op Fl c Ar cylinders .Op Fl h Ar heads .Op Fl s Ar sectors .Ar device .Sh DESCRIPTION In order for the BIOS to boot the kernel, certain conventions must be adhered to. Sector 0 of a bootable hard disk must contain boot code, an MBR partition table, and a magic number (0xAA55). These MBR partitions (also known as BIOS partitions) can be used to break the disk up into several pieces. .Pp The BIOS loads sector 0 of the boot disk into memory, verifies the magic number, and begins executing the code at the first byte. The normal DOS MBR boot code searches the MBR partition table for an .Dq active partition (indicated by a .Ql \&* in the first column), and if one is found, the boot block from that partition is loaded and executed in place of the original (MBR) boot block. .Pp The options are as follows: .Bl -tag -width Ds .It Fl i Initialize the MBR sector. .It Fl e Edit existing MBR sectors. .It Fl f Ar mbrname Specifies an alternate MBR template file. .It Fl u Update MBR code, preserving existing partition table. .It Xo Fl c Ar cylinders , .Fl h Ar heads , .Fl s Ar sectors .Xc Specifies an alternate BIOS geometry for .Nm to use. .El .Pp The DOS .Nm program can be used to divide space on the disk into partitions and set one active. This .Nm program serves a similar purpose to the DOS program. When called with no special flags, it prints the MBR partition table of the specified device, i.e., .Bd -literal # fdisk fd0 Disk: fd0 geometry: 80/2/18 [2880 sectors] Offset: 0 Signature: 0xAA55 Starting Ending #: id cyl hd sec - cyl hd sec [ start - size] ---------------------------------------------------------------------- *0: A6 0 0 1 - 79 1 18 [ 0 - 2880] OpenBSD 1: 00 0 0 0 - 0 0 0 [ 0 - 0] unused 2: A7 0 0 2 - 79 1 18 [ 1 - 2879] NEXTSTEP 3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused .Ed .Pp The geometry displayed is the BIOS geometry unless another geometry has been selected using the .Fl c , .Fl h , and .Fl s options. .Pp This disk is divided into two partitions that happen to fill the disk. The first partition overlaps the third partition. (Used for debugging purposes.) .Bl -tag -width "start/size" .It Em "#" Number of partition table entry. A .Dq \&* denotes the bootable partition. .It Em "id" System identifier. .Ox reserves the magic number 166 decimal (A6 in hex). If no 166 partition is found, it will use an older .Fx partition (with a magic number of 165 or A5 in hex). .It Em "cyl/hd/sec" These fields provide the starting and ending address of the partition in BIOS geometry. .It Em "start/size" These fields provide the starting sector and size in sectors of the partition in linear block addresses. .El .Pp .Em NOTE : The sectors field is .Dq 1 based , and the start field is .Dq 0 based . The CHS values will need to be in the BIOS's geometry for the system to be able to boot and use the drive correctly. .Pp The .Fl i flag is used to indicate that the partition data is to be initialized. In this mode, .Nm will completely overwrite the primary MBR and partition table, either using the default MBR template, or the one specified by the .Fl f flag. In the default template, partition number 3 will be configured as an .Ox partition spanning from cylinder 0, head 1, sector 1, and extending to the end of the disk. This mode is designed to initialize an MBR the very first time, or when it has been corrupted beyond repair. .Pp The .Fl u flag is used to update the MBR code on a given drive. The MBR code extends from offset 0x000 to the start of the partition table at offset 0x1BE. It is similar to the .Fl i flag, except the existing partition table is preserved. This is useful for writing new MBR code onto an existing drive, and is equivalent to the DOS command .Dq FDISK /MBR . Note that this option will overwrite the NT disk signature, if present. .Pp The .Fl e flag is used to modify a partition table using an interactive edit mode of the .Nm program. This mode is designed to allow you to change any partition on the drive you choose, including extended partitions. It is a very powerful mode, but is safe as long as you do not execute the .Em write command, or answer in the negative (the default) when .Nm asks you about writing out changes. .Sh COMMAND MODE When you first enter this mode, you are presented with a prompt, that looks like so: .Em "fdisk: 0>" . This prompt has two important pieces of information for you. It will tell you if the in-memory copy of the boot block has been modified or not. If it has been modified, the prompt will change to look like: .Em "fdisk:*0>" . The second piece of information pertains to the number given in the prompt. This number specifies the disk offset of the currently selected boot block you are editing. This number could be something other than zero when you are editing extended partitions. The list of commands and their explanations are given below. .Bl -tag -width "update" .It Em help Display a list of commands that .Nm understands in the interactive edit mode. .It Em manual Display this manual page. .It Em reinit Initialize the currently selected, in-memory copy of the boot block. .It Em disk Display the current drive geometry that .Nm has probed. You are given a chance to edit it if you wish. .It Em edit Edit a given table entry in the memory copy of the current boot block. You may edit either in BIOS geometry mode, or in sector offsets and sizes. .It Em setpid Change the partition identifier of the given partition table entry. This command is particularly useful for reassigning an existing partition to .Ox . .It Em flag Make the given partition table entry bootable. Only one entry can be marked bootable. If you wish to boot from an extended partition, you will need to mark the partition table entry for the extended partition as bootable. If an optional value is given, the partition is marked with the given value, and other partitions are not touched. .It Em update Update the machine code and 0xAA55 signature in the memory copy of the currently selected boot block. Note that this option will overwrite the NT disk signature, if present. .It Em swap Swap two MBR entries. .It Em select Select and load into memory the boot block pointed to by the extended partition table entry in the current boot block. .It Em print Print the currently selected in-memory copy of the boot block and its MBR table to the terminal. .It Em write Write the in-memory copy of the boot block to disk. You will be asked to confirm this operation. .It Em exit Exit the current level of .Nm fdisk , either returning to the previously selected in-memory copy of a boot block, or exiting the program if there is none. .It Em quit Exit the current level of .Nm fdisk , either returning to the previously selected in-memory copy of a boot block, or exiting the program if there is none. Unlike .Em exit it does write the modified block out. .It Em abort Quit program without saving current changes. .El .Sh NOTES The automatic calculation of starting cylinder etc. uses a set of figures that represent what the BIOS thinks is the geometry of the drive. These figures are by default taken from the in-core disklabel, or values that .Em /boot has passed to the kernel, but .Nm gives you an opportunity to change them if there is a need to. This allows the user to create a bootblock that can work with drives that use geometry translation under a potentially different BIOS. .Pp If you hand craft your disk layout, please make sure that the .Ox partition starts on a cylinder boundary. (This restriction may be changed in the future.) .Pp Editing an existing partition is risky, and may cause you to lose all the data in that partition. .Pp You should run this program interactively once or twice to see how it works. This is completely safe as long as you answer the .Dq write questions in the negative. .Sh FILES .Bl -tag -width /usr/mdec/mbr -compact .It Pa /usr/mdec/mbr default MBR template .El .Sh SEE ALSO .Xr boot_i386 8 , .Xr disklabel 8 .Sh BUGS There are subtleties .Nm detects that are not explained in this manual page. As well, chances are that some of the subtleties it should detect are being steamrolled. Caveat Emptor.