.\" $OpenBSD: fdisk.8,v 1.38 2002/01/04 21:20:56 kjell Exp $ .\" .\" Copyright (c) 2002 Apple Computer, Inc. All rights reserved. .\" .\" "Portions Copyright (c) 2002 Apple Computer, Inc. All Rights .\" Reserved. This file contains Original Code and/or Modifications of .\" Original Code as defined in and that are subject to the Apple Public .\" Source License Version 1.2 (the 'License'). You may not use this file .\" except in compliance with the License. Please obtain a copy of the .\" License at http://www.apple.com/publicsource and read it before using .\" this file. .\" .\" The Original Code and all software distributed under the License are .\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, .\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the .\" License for the specific language governing rights and limitations .\" under the License." .\" .\" 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. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by Tobias Weingartner. .\" 4. The name of the author may not be used to endorse or promote products .\" derived from this software without specific prior written permission. .\" .\" 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 .Op Fl S Ar size .Op Fl b Ar size .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 a Ar style Specify an automatic partitioning style. .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 Fl y Do not ask for confirmation before writing. .It Fl d Dump partition table in a format readable by the -r option. .It Fl r Read a partition table from the standard input. .It Fl t Test if the disk is partitioned. .It Xo Fl c Ar cylinders , .Fl h Ar heads , .Fl s Ar sectors .Xc Specifies an alternate BIOS geometry for .Nm to use. .It Fl S Ar size Specify the disk size in blocks. .It Fl b Ar size Specify the number of bytes per disk block. .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] ---------------------------------------------------------------------- *1: A6 0 0 1 - 79 1 18 [ 0 - 2880] OpenBSD 2: 00 0 0 0 - 0 0 0 [ 0 - 0] unused 3: A7 0 0 2 - 79 1 18 [ 1 - 2879] NEXTSTEP 4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused .Ed .Pp The geometry displayed is a synthetic geometry unless another geometry has been selected using the .Fl c , .Fl h , .Fl s , .Fl S , and .Fl b options. In the future, .Nm will read the BIOS geometry from the IOKit registry. .Pp In this example, the 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 may need to be in the BIOS's geometry for older systems to be able to boot and use the drive correctly; most modern systems prefer the starting sector and size in preference to the CHS values. .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. .Pp In the default template, partition number 1 will be configured as a Darwin boot partition spanning from cylinder 0, head 1, sector 1, and extending for 8 megabytes. Partition number 2 will be configured as a Darwin HFS partition spanning the rest of the disk. This mode is designed to initialize an MBR the very first time, or when it has been corrupted beyond repair. .Pp You can specify other default partition styles with the .Fl a flag. The available styles are: .Bl -tag -width "start/size" .It Em "boothfs" Creates an 8Mb boot partition (type AB hex) and makes the rest of the disk a Darwin HFS partition (type AF hex). .It Em "bootufs" Creates an 8Mb boot partition (type AB hex) and makes the rest of the disk a Darwin UFS partition (type A8 hex). .It Em "ufs" Makes the entire disk one Darwin UFS partition (type A8 hex). .It Em "hfs" Makes the entire disk one HFS+ partition (type AF hex). .It Em "dos" Makes the entire disk one DOS partition (type 0C hex). .It Em "raid" Makes the entire disk one type AC hex partition. .El .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. The .Fl u and .Fl i flags may not be specified together. .Pp The flag .Fl e is used to modify a partition table using a 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 different that 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 auto Partition the disk with one of the automatic partition styles. .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 OpenBSD. .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. .It Em update Update the machine code in the memory copy of the currently selected boot block. Note that this option will overwrite the NT disk signature, if present. .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 gpt 8 , .Xr pdisk 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.