FDISK(8) | System Manager's Manual | FDISK(8) |
fdisk
— partition
table maintenance program
fdisk |
[-egvy ] [-i |
-u ] [-b
blocks] [-c
cylinders -h
heads -s
sectors] [-f
mbrfile] [-l
blocks] disk |
fdisk
makes changes to the MBR and GPT
tables found on some disks. On such disks sector 0 contains a 4-entry MBR
partition table that divides the space. The GPT partition table, when
present, starts at sector 1.
Each entry has a type. A type of 0xA6 indicates an OpenBSD MBR partition, which starts with its own 16-entry partition table known as a disklabel(5). This can be edited using disklabel(8).
Caution is advised when editing these tables, since some platforms use tricks to boot and may rely on specific configurations created at install time.
The options are as follows:
-b
blocks-i
.-c
cylinders -h
heads -s
sectorsfdisk
to
use. By default, an automatic calculation of disk size will be built using
heuristics. These figures are taken from the in-core disklabel (see
disklabel(8)), or values
that
/boot
has passed to the kernel.
Only one of -chs
or
-l
can be specified.
-e
fdisk
interactive editor to modify the
partition table. See COMMAND MODE,
below, for more information.-f
mbrfile-g
-b
specification. Only valid with
-i
.-i
fdisk
will completely overwrite the primary MBR
bootcode and MBR partition table.
If -g
is not specified then the MBR
will be overwritten by the default MBR template
/usr/mdec/mbr (or the one optionally specified
by the -f
flag). In the default template, MBR
partition number 3 will be configured as an
OpenBSD MBR partition containing all available
space not allocated by a -b
specification.
Only one of -i
or
-u
can be specified.
-l
blocksOnly one of -chs
or
-l
can be specified.
-u
-i
flag,
except the existing MBR partition table is preserved. This is useful for
writing new MBR bootcode onto an existing drive, and is equivalent to the
DOS command “FDISK /MBR”. Note that this option will
overwrite the NT disk signature, if present.
Only one of -i
or
-u
can be specified.
-v
-i
, -u
, or
-e
.-y
When called with no special flags, fdisk
prints the partition table of the specified disk.
If the disk does not contain a valid GPT the contents of the MBR are displayed. For example:
# fdisk sd0 Disk: sd0 geometry: 121601/255/63 [1953525168 Sectors] Offset: 0 Signature: 0xAA55 Starting Ending LBA Info: #: id C H S - C H S [ start: size ] ------------------------------------------------------------------------ 0: 0B 0 1 1 - 26108 0 63 [ 63: 419425020 ] FAT32 1: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused 2: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused *3: A6 26108 1 1 - 121600 254 63 [ 419425083: 1534094982 ] OpenBSD
This 1953525168 sector (931GB) disk drive is divided into two MBR partitions that span the whole disk. The first MBR partition is a 200GB FAT32 partition; the second is a 731GB OpenBSD MBR partition using the remainder of the disk. The fields of the output are:
NOTE: The BIOS geometry sectors field (C/H/S) is “1 based”, but the LBA "start" field is “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. These values must be kept correctly synchronized or a variety of problems develop which are very difficult to diagnose.
If the disk contains a protective MBR and a valid GPT, the contents of the GPT are displayed. For example:
Disk: sd2 Usable LBA: 64 to 7765952 [7766016 Sectors] #: type [ start: size ] ------------------------------------------------------------------------ 1: EFI Sys [ 64: 960 ] 3: OpenBSD [ 1024: 7764929 ]
This 7766016 sector disk drive is divided into two partitions that span the whole disk. The first partition is a 960 sector EFI Sys partition; the second is a 7764929 sector OpenBSD partition using the remainder of the disk. The fields of the output are:
If the -v
option is specified, the disk
GUID and each partition's GUID and name are also displayed.
In either the MBR or GPT case the OpenBSD partition shown above is subdivided further using the functionality provided by disklabel(8), which provides OpenBSD partitions.
# /dev/rsd0c: type: SCSI disk: SCSI disk label: WDC WD10EADS-65L duid: 085ef8d68623f5b3 flags: bytes/sector: 512 sectors/track: 63 tracks/cylinder: 255 sectors/cylinder: 16065 cylinders: 121601 total sectors: 1953525168 boundstart: 419425083 boundend: 1953520065 drivedata: 0 16 partitions: # size offset fstype [fsize bsize cpg] a: 2097125 419425083 4.2BSD 2048 16384 1 b: 4715520 421522208 swap c: 1953525168 0 unused d: 8388608 426237728 4.2BSD 2048 16384 1 e: 16771072 434626336 4.2BSD 2048 16384 1 f: 4194304 451397408 4.2BSD 2048 16384 1 g: 2097152 455591712 4.2BSD 2048 16384 1 h: 20971520 457688864 4.2BSD 2048 16384 1 i: 419425020 63 MSDOS j: 4194304 478660384 4.2BSD 2048 16384 1 k: 4194304 482854688 4.2BSD 2048 16384 1 l: 629145536 487049024 4.2BSD 4096 32768 1
These OpenBSD partitions are then mounted as follows using /etc/fstab:
/dev/sd0a / ffs rw,softdep 1 1 /dev/sd0d /tmp ffs rw,softdep,nodev,nosuid 1 2 /dev/sd0e /var ffs rw,softdep,nodev,nosuid 1 2 /dev/sd0f /usr ffs rw,softdep,nodev 1 2 /dev/sd0g /usr/X11R6 ffs rw,softdep,nodev 1 2 /dev/sd0h /usr/local ffs rw,softdep,nodev 1 2 /dev/sd0i /mnt/example msdos rw,nodev,nosuid 1 2 /dev/sd0j /usr/src ffs rw,softdep,nodev,nosuid 1 2 /dev/sd0k /usr/obj ffs rw,softdep,nodev,nosuid 1 2 /dev/sd0l /home ffs rw,softdep,nodev,nosuid 1 2
The -e
flag causes
fdisk
to enter an interactive command mode. The
prompt contains information about the state of the edit process.
disk*:1>
Where disk is the name of the disk being edited, ‘*’ means that the in-memory copy of the partition table has been modified, but not yet written to disk and 1 is the number of the boot block being edited. This number will be 2 when editing an extended MBR partition, 3 when editing an extended MBR partition within an extended MBR partition, and so on.
The list of commands and their explanations are given below. Commands may be abbreviated provided enough characters are given to ensure unambiguity.
?
help
.help
fdisk
understands
in the interactive edit mode.manual
reinit
[gpt
| mbr
]gpt
is specified a protective MBR and a GPT are
initialized. If mbr
is specified only an MBR is
initialized. If neither mbr
nor
gpt
are specified then a protective MBR and a GPT
are initialized if a protective MBR already exists. Otherwise only an MBR
is initialized.disk
fdisk
probed using kernel provided information and various heuristics. The disk
geometry may be changed at this point. Not available when editing a
GPT.edit
#flag
# [value]update
select
#setpid
#swap
# #print
[unit]write
exit
fdisk
, either returning
to the previously selected in-memory copy of a MBR, or exiting the program
if there is none.quit
fdisk
, either returning
to the previously selected in-memory copy of a MBR, or exiting the program
if there is none. Unlike exit it does write the modified
block out.abort
fstab(5), boot_amd64(8), boot_i386(8), boot_macppc(8), disklabel(8)
Hand crafted disk layouts are highly error prone. It is common practice, though by no means required, that MBR partitions start on a cylinder boundary (generally head 0, sector 1, but head 1, sector 1 for track 0), and that MBR partitions also end at cylinder boundaries.
April 29, 2019 | OpenBSD-6.8 |