The
fdisk program is used to display or update the
master boot record or
MBR in the first sector (sector 0) of a disk that uses the MBR style of partitioning. The following
NetBSD ports use this style of disk partitioning: amd64, arc, bebox, cobalt, hpcarm, hpcmips, hpcsh, i386, macppc, mvmeppc, netwinder, ofppc, and prep.
The MBR contains bootable code, a partition table, an indication of which partition is ‘active', and (optionally, depending on the boot code) a menu for selecting a partition to be booted. There can be at most 4 partitions defined in sector 0, one of which can be an extended partition which can be split into any number of sub-partitions.
The boot code in the MBR is usually invoked by the BIOS or firmware, and the MBR passes control to the next stage boot code stored in the first sector of the partition to be booted (the
partition boot record or
PBR).
After booting,
NetBSD does not use the partitioning done by
fdisk, instead it uses a
NetBSD disklabel saved in sector 1 of the
NetBSD partition. See
mbrlabel(8) for a way of using information from the MBR to construct a
NetBSD disklabel.
The standard MBR boot code will only boot the ‘active' partition. However,
NetBSD contains additional boot programs which allow the user to interactively select which of the partitions to boot. The ‘mbr_ext' code will also boot
NetBSD from an extended partition but will not work on old systems that do not support LBA reads, the ‘mbr_com0' and ‘mbr_com0_9600' will read and write from a serial port. At the start the
fdisk program will determine whether the disk sector 0 is valid as a boot sector. (This is determined by checking the magic number.) If not,
fdisk will initialise the boot code as well as the partition table. During this, all four partitions will be marked empty.
The flags
-a,
-i or
-u are used to indicate that the partition data is to be updated. The
fdisk program will enter an interactive conversational mode. This mode is designed not to change any data unless you explicitly tell it to;
fdisk selects defaults for its questions to guarantee that behaviour.
If partition data is going to be updated and the disk carries GUID Partition Tables,
fdisk will remove both primary and backup GPT headers from the disk. See
gpt(8) for information on how to manipulate GUID Partition Tables.
fdisk will calculate the correct
cylinder,
head, and
sector values for any partition you edit. If you specify
-v you will be asked whether you want to specify them yourself.
Finally, when all the data for the first sector has been accumulated,
fdisk will ask if you really want to write the new partition table. Only if you reply affirmatively to this question will
fdisk write anything to the disk.
Available options:
-0
Specify partition slot 0 to be printed or updated.
-1
Specify partition slot 1 to be printed or updated.
-2
Specify partition slot 2 to be printed or updated.
-3
Specify partition slot 3 to be printed or updated.
-A ptn_alignment[/ptn_0_offset]
Specify the alignment for all partitions and optionally the offset for the first partition of the disk and of extended partitions. If ptn_alignment is specified and ptn_0_offset is not specified, then the offset is set to the alignment. If -A isn't specified, then the alignment of the first partition is inspected. If it ends on a 2048 sector boundary, then the alignment is set to 2048, if the start is a power of 2 less than, or equal to 2048 then the offset is set to the start sector. If the first partition isn't defined then the alignment and offset for disks larger than 128GB is set to 2048 (1MB). In all other cases the alignment default to a cylinder and the offset to a track (both using the BIOS geometry). The 1MB alignment is the same as that used by recent windows versions.
-a
Change the active partition. In interactive mode this question will be asked after the partitions have been processed.
-B
On an i386 or amd64 system, interactively update the boot selector settings. (The boot selector permits the user to interactively select the boot partition, and thus which operating system is run, at system boot time; see
mbr(8) for more information.)
-b cylinders/heads/sectors
Specify the BIOS geometry parameters for cylinders, heads, and sectors. It is used only in conjunction with the -u flag. If not specified the BIOS geometry will be obtained using sysctl (i386 and amd64) or by solving the simultaenous equations from the existing partition information. If that fails then either the geometry from the disklabel or 63 sectors and 16 heads is used.
-c bootcode
Specify the filename that fdisk should read the bootcode from. If the name of a directory is specified, then fdisk will look for files with the default names in that directory. The default is to read from /usr/mdec/mbr, /usr/mdec/mbr_bootsel or /usr/mdec/mbr_ext depending on whether bootmenu was specified for any partitions on an i386 machine, and leave the bootcode empty for other machines.
-E number
Specify extended partition number to be printed or updated. If the specified extended partition doesn't exist on updating partition data an additional extended partition will be created.
-F
Indicate that device is a regular file. Unless the geometry of device is told to fdisk by -T disktype, fdisk will count the 512-byte sectors in device and produce a fake geometry. If device is a regular file, -F will be used implicitly.
-f
Run
fdisk in a non-interactive mode. In this mode, you can only change the disk parameters by using the
-b flag. This is provided only so scripts or other programs may use
fdisk as part of an automatic installation process.
Using the
-f flag with
-u makes it impossible to specify the starting and ending
cylinder,
head, and
sector fields (only
start and
size can be specified by
-s option). They will be automatically computed using the BIOS geometry.
-i
Explicitly request initialisation of the master boot code (similar to what fdisk /mbr does under MS-DOS), even if the magic number in the first sector is ok. The partition table is left alone by this (but see above).
-l
Lists known sysid values and exit.
-r file
Read the boot record from file file instead of the specified disk. The geometry information used is still that of the disk volume. Any changes are written back to the file.
-S
When used with no other flags print a series of /bin/sh commands for setting variables to the partition information. This could be used by installation scripts.
-s id/start/size[/bootmenu]
Specify the partition id, start, size, and optionally bootmenu. This flag requires the use of a partition selection flag (-0, -1, -2, -3, or -E number).
-T disktype
Use the disklabel disktype instead of the disklabel on device.
-t disktab
Read
disktype from the named
disktab(5) file instead of from
/etc/disktab.
-u
Update partition data, including
id,
start, and
size. Unless
-f option (non-interactive mode) is specified,
fdisk will display the partitions and interactively ask which one you want to edit.
fdisk will step through each field showing the old value and asking for a new one. The
start and
size can be specified in blocks (NN), cylinders (NNc or NNcyl), megabytes (NNm or NNMB), or gigabytes (NNg or NNGB), values in megabytes and gigabytes will be rounded to the nearest cylinder boundary. The
size may be specified as
$ in which case the partition will extend to the end of the available free space.
In a non-interactive mode (specified by
-f option), partition data should be specified by
-s option. A partition selection option (
-0,
-1,
-2,
-3, or
-E number) should also be specified to select a partition slot to be updated.
fdisk will not allow you to create partitions which overlap. If
-u and
-s are specified in a non-interactive mode then the details of the specified partition will be changed. Any other partitions which overlap the requested part of the disk will be silently deleted.
If
bootmenu is specified for any partition
fdisk will determine whether the installed boot code supports the bootselect code, if it doesn't you will be asked whether you want to install the required boot code. To remove a
bootmenu label, simply press <space> followed by <return>.
-v
Be more verbose, specifying
-v more than once may increase the amount of output.
Using
-v with
-u allows the user to change more parameters than normally permitted.
-w file
Write the modified partition table to file file instead of the disk.
When called with no arguments, it prints the partition table. An example follows:
Disk: /dev/rwd0d
NetBSD disklabel disk geometry:
cylinders: 16383, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
total sectors: 40032696
BIOS disk geometry:
cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 40032696
Partition table:
0: NetBSD (sysid 169)
bootmenu: net 1.5.
start 4209030, size 8289540 (4048 MB, Cyls 262-778), Active
1: Primary DOS with 32 bit FAT (sysid 11)
bootmenu: win98
start 63, size 4208967 (2055 MB, Cyls 0-262)
2: NetBSD (sysid 169)
bootmenu: current
start 32515560, size 7517136 (3670 MB, Cyls 2024-2491/234/40)
3: Ext. partition - LBA (sysid 15)
start 12498570, size 20016990 (9774 MB, Cyls 778-2024)
Extended partition table:
E0: NetBSD (sysid 169)
bootmenu: test
start 12498633, size 12305727 (6009 MB, Cyls 778-1544)
E1: Primary DOS with 32 bit FAT (sysid 11)
start 24804423, size 4096512 (2000 MB, Cyls 1544-1799)
E2: Primary DOS with 32 bit FAT (sysid 11)
start 28900998, size 3614562 (1765 MB, Cyls 1799-2024)
Bootselector enabled, infinite timeout.
First active partition: 0
This example disk is divided into four partitions, the last of which is an extended partition. The sub-partitions of the extended partition are also shown. In this case there is no free space in either the disk or in the extended partition.
The various fields in each partition entry are:
ptn_number:
id_name (sysid
id_number)
bootmenu:
bootmenu
start
start, size
size (
MB MB, Cyls
first-
next) [
, Active]
ptn_number
is the number of the partition.
id_name
is the name of the filesystem type or operating system that uses this partition.
id_number
is the number that identifies the partition type. 169 decimal is used for NetBSD partitions, 15 decimal to create an extended partition and 0 to mark a partition as unused. Use fdisk -l to list the known partition types.
bootmenu
is the menu prompt output by the interactive boot code for this partition. This line is omitted if the prompt is not defined.
start, size
are the start address and size of the partition in sectors.
MB
is the size of the partition in megabytes.
first, next
are the bounds of this partition displayed as cylinder/head/sector. If the partition starts (or ends) on a cylinder boundary the head and sector values are omitted. If -v is not specified the start of extended partitions and the first partition on the disk are rounded down to include the mandatory red tape in the preceding track.
Active
is output if this is the active partition.
If the
-v flag is specified, the beginning and end of each partition are also displayed as follows: beg: cylinder
cylinder, head
head, sector
sector
end: cylinder
cylinder, head
head, sector
sectorcylinder, head, sector
are the beginning or ending address of a partition.
Note: these numbers are read from the bootblock, so are the values calculated by a previous run of
fdisk.
fdisk attempts to check whether each partition is bootable, by checking the magic number and some other characteristics of the first sector of each partition (the PBR). If the partition does not appear to be bootable,
fdisk will print a line containing “PBR is not bootable” followed by an error message. If the partition is bootable, and if the
-v flag is specified,
fdisk will print “PBR appears to be bootable”. If the
-v flag is specified more than once,
fdisk will print the heading “Information from PBR:” followed by one or more lines of information gleaned from the PBR; this additional information may be incorrect or misleading, because different operating systems use different PBR formats. Note that, even if no errors are reported, an attempt to boot from the partition might fail.
NetBSD partitions may be made bootable using
installboot(8).