- NetBSD Manual Pages
DISKLABEL(8) NetBSD System Manager's Manual DISKLABEL(8)
Powered by man-cgi (2021-06-01).
Maintained for NetBSD
by Kimmo Suominen.
Based on man-cgi by Panagiotis Christias.
disklabel -- read and write disk pack label
disklabel [-ACDFmnrtv] [-B endian] [-L sector] [-M machine] [-O offset]
[-P size] disk
disklabel -e [-CDFImnrv] [-B endian] [-L sector] [-M machine] [-O offset]
[-P size] disk
disklabel -i [-DFImnrv] [-B endian] [-L sector] [-M machine] [-O offset]
[-P size] disk
disklabel -R [-DFmnrv] [-B endian] [-L sector] [-M machine] [-O offset]
[-P size] disk protofile
disklabel -w [-DFmnrv] [-B endian] [-L sector] [-M machine] [-O offset]
[-P size] [-f disktab] disk disktype [packid]
disklabel [-NW] disk
disklabel can be used to install, examine, or modify the label on a disk
drive or pack. When writing the label, it can be used to change the
drive identification, the disk partitions on the drive, or to replace a
The -e, -i, -l, -N, -R, -W, and -w options determine the basic operation.
If none are specified the label is displayed.
-e Edit the existing label (using EDITOR) and write it back to the
disk. If EDITOR is undefined, then vi(1) is used.
-i Interactively update the existing label and write it back to the
-l Show all known file system types (those that can be specified along
a partition within the label) and exit.
-N Disallow writes to the disk sector that contains the label. This
is the default state.
-R Write (restore) a label by reading it from protofile. The file
should be in the same format as the default output.
-W Allow writes to the disk sector that contains the label. This
state may not persist if no programs have the disk open.
-w Write a standard label for the specified disktype. See disktab(5).
The majority of the rest of the options affect more than one form of the
-A Read all labels from the disk, including ones deleted with
disklabel -D. Implies -r.
Specify the byteorder of the label to be written. It should be:
``be'' or ``le''.
-C Output the partition offset and size values in
<cylinder/head/sector> format. Note this format is always accepted
on input with either the -e or -R flags.
-D Delete all existing labels (by 1's complementing the magic number)
before writing any labels to their default location. Implies -r.
If -D is specified without a request to write the label, then
existing labels are just deleted.
-F Treat disk as a regular file. This suppresses all ioctl(2) calls,
and is the default if disk is a regular file. disk is always
opened using opendisk(3) even if -F is specified. Implies -r.
Specify the name of a file to use instead of /etc/disktab.
-I If a label cannot be read from disk request the default one from
the kernel. Implies -r.
Specify the relative sector number of the disklabel similar to the
environment variable DISKLABELSECTOR.
Specify the machine to generate a label for. Defaults to the cur-
rent machine it is compiled for. Specific details can be overrid-
den via environment and with the options -B, -L, -m, -n, -O, and
-m Expect the label to have an MBR.
-n Expect the label not to have an MBR.
Specify the relative byte offset of the disklabel similar to the
environment variable DISKLABELOFFSET.
Specify the size of the partition table.
-r Read/write the disk directly rather than using ioctl(2) requests on
the kernel. When writing a label, the kernel will be told about
the label before the label is written and asked to write after-
wards. This is the historic behaviour and can be suppressed by
-t Format the output as a disktab(5) entry.
-v Be verbose about the operations being done, in particular the disk
sectors being read and written. Specifying -v more than once will
increase the verbosity.
On systems that expect to have disks with MBR partitions (see fdisk(8))
disklabel will find, and update if requested, labels in the first 8k of
type 169 (NetBSD) MBR labels and within the first 8k of the physical
disk. On other systems disklabel will only look at the start of the
disk. The offset at which the labels are written is also system depen-
disklabel will detect byteswapped labels, but currently cannot display
Previous versions of disklabel could update the bootstrap code on some
architectures. This functionality has been subsumed by installboot(8).
The exit status of disklabel is set to indicate any errors or warnings.
The values used are:
0 The disklabel utility has completed successfully.
1 A fatal error has occurred, such as unknown options passed on the
command line, or writing the disklabel failed.
4 An I/O error of some sort occurred.
101..n One or more warnings occurred while reading the disklabel. Sub-
tract 100 to get the number of warnings detected.
Display the in-core label for sd0 as obtained via /dev/rsd0c.
disklabel -i -r sd0
Read the on-disk label for sd0, edit it using the built-in interactive
editor and reinstall in-core as well as on-disk.
disklabel -i -I sd0
As previous, but do not fail if there was no label on the disk yet; pro-
vide some default values instead.
disklabel -e -I sd0
As previous, only edit using $EDITOR
disklabel -w -r /dev/rsd0c sd2212 foo
Create a label for sd0 based on information for ``sd2212'' found in
/etc/disktab, using foo as the disk pack label. If you do not have an
entry for your disk in /etc/disktab, you can use this style to put an
initial label onto a new disk. Then dump the label to a file (using
disklabel sd0 > protofile), editing the file, and replacing the label
with disklabel -R sd0 protofile.
disklabel -R sd0 mylabel
Restore the on-disk and in-core label for sd0 from information in
The kernel device drivers will not allow the size of a disk partition to
be decreased or the offset of a partition to be changed while it is open.
Some device drivers create a label containing only a single large parti-
tion if a disk is unlabeled; thus, the label must be written to the ``a''
partition of the disk while it is open. This sometimes requires the
desired label to be set in two steps, the first one creating at least one
other partition, and the second setting the label on the new partition
while shrinking the ``a'' partition.
opendisk(3), disklabel(5), disktab(5), dkctl(8), fdisk(8), gpt(8),
installboot(8), mbrlabel(8), mscdlabel(8)
The disklabel utility appeared in 4.3BSD-Tahoe.
The disklabel structure stored on disk cannot support partitions/disks
greater than 2TB. Please use gpt(8) and dkctl(8) to manage partitions
and disks larger than 2TB.
If the disk partition is not specified in the disk name (i.e., xy0
instead of /dev/rxy0c), disklabel will construct the full pathname of the
disk and use the ``d'' partition on i386, hpcmips, or arc, and the ``c''
partition on all others.
On the sparc, sparc64, sun2, and sun3 NetBSD systems, the size of each
partition must be a multiple of the number of sectors per cylinder (i.e.,
each partition must be an integer number of cylinders), or the boot ROMs
will declare the label invalid and fail to boot the system.
In addition, the -r option should never be used on a sparc, sparc64,
sun2, or sun3 system boot disk - the NetBSD kernel translates the NetBSD
disk label into a SunOS compatible format (which is required by the boot
PROMs) when it writes the label. Using the -r flag causes disklabel to
write directly to disk, and bypass the format translation. This will
result in a disk label that the PROMs will not recognize, and that there-
fore cannot be booted from.
The -m flag previously toggled between using an MBR and not using an MBR,
with the default being implied by the machine type. It now always
enables MBR mode, independent of the machine default. Use the -n flag to
disable MBR mode.
NetBSD 9.1 July 2, 2019 NetBSD 9.1