DISKLABEL(8)

NAME
disklabel - read and write disk pack label

SYNOPSIS
disklabel [-rt] disk
-w [-r] disk disktype [packid]
-e [-r] disk
-i [-r] disk
-R [-r] disk protofile
[-NW] disk

-B [ -b boot1 [-s boot2]] disk [disktype]
-w -B [ -b boot1 [-s boot2]] disk disktype [packid]
-R -B [ -b boot1 [-s boot2]] disk protofile [disktype]

DESCRIPTION
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 damaged label. On some systems, disklabel can be used to install bootstrap code as well.

There are several forms of the command that read (display), install or edit the label on a disk. Each form has an additional option, -r, which causes the label to be read from or written to the disk directly, rather than going through the system's in-core copy of the label. This option may allow a label to be installed on a disk without kernel support for a label, such as when labels are first installed on a system; it must be used when first installing a label on a disk. The specific effect of -r is described under each command. The read and install forms also support the -B option to install bootstrap code. These variants are described later.

The first form of the command (read) is used to examine the label on the named disk drive (e.g. sd0 or /dev/rsd0c). It will display all of the parameters associated with the drive and its partition layout. Unless the -r flag is given, the kernel's in-core copy of the label is displayed; if the disk has no label, or the partition types on the disk are incorrect, the kernel may have constructed or modified the label. If the -r flag is given, the label from the raw disk will be displayed rather than the in-core label. If the -t flag is given, then the label will be formatted as a disktab(5) entry.

The second form of the command, with the -w flag, is used to write a standard label on the designated drive. The required arguments to disklabel are the drive to be labelled (e.g. sd0), and the drive type as described in the disktab(5) file. The drive parameters and partitions are taken from that file. If different disks of the same physical type are to have different partitions, it will be necessary to have separate disktab entries describing each, or to edit the label after installation as described below. The optional argument is a pack identification string, up to 16 characters long. The pack id must be quoted if it contains blanks. If the -r flag is given, the disk sectors containing the label and bootstrap will be written directly. A side-effect of this is that any existing bootstrap code will be overwritten and the disk rendered unbootable. If -r is not specified, the existing label will be updated via the in-core copy and any bootstrap code will be unaffected. If the disk does not already have a label, the -r flag must be used. In either case, the kernel's in-core label is replaced.

An existing disk label may be edited by using the -e flag. The label is read from the in-core kernel copy, or directly from the disk if the -r flag is also given. The label is formatted and then supplied to an editor for changes. If no editor is specified in an EDITOR environment variable, vi(1) is used. When the editor terminates, the formatted label is reread and used to rewrite the disk label. Existing bootstrap code is unchanged regardless of whether -r was specified.

Labels can also created interactively using the -e flag. The -C flag causes the partition offset and size values to be displayed in <cylinder/track/sector> format. Note that, regardless of whether -C was specified, this format is always accepted by disklabel on input with either the -e or -R flag.

With the -R flag, disklabel is capable of restoring a disk label that was formatted in a prior operation and saved in an ascii file. The prototype file used to create the label should be in the same format as that produced when reading or editing a label. Comments are delimited by # and newline. As with -w, any existing bootstrap code will be clobbered if -r is specified and will be unaffected otherwise.

The -NW flags for disklabel explicitly disallow and allow, respectively, writing of the pack label area on the selected disk.

The final three forms of disklabel are used to install boostrap code on machines where the bootstrap is part of the label. The bootstrap code is comprised of one or two boot programs depending on the machine. The -B option is used to denote that bootstrap code is to be installed. The -r flag is implied by -B and never needs to be specified. The name of the boot program(s) to be installed can be selected in a variety of ways. First, the names can be specified explicitly via the -b and -s flags. On machines with only a single level of boot program, -b is the name of that program. For machines with a two-level bootstrap, -b indicates the primary boot program and -s the secondary boot program. If the names are not explicitly given, standard boot programs will be used. The boot programs are located in /usr/mdec. The names of the programs are taken from the ``b0'' and ``b1'' parameters of the disktab(5) entry for the disk if disktype was given and its disktab entry exists and includes those parameters. Otherwise, boot program names are derived from the name of the disk. These names are of the form basenameboot for the primary (or only) bootstrap, and bootbasename for the secondary bootstrap; for example, /usr/mdec/sdboot and /usr/mdec/bootsd if the disk device is sd0.

The first of the three boot-installation forms is used to install bootstrap code without changing the existing label. It is essentially a read command with respect to the disk label itself and all options are related to the specification of the boot program as described previously. The final two forms are analogous to the basic write and restore versions except that they will install bootstrap code in addition to a new label.

FILES
/etc/disktab
/usr/mdec/xxboot
/usr/mdec/bootxx

EXAMPLES
    disklabel sd0

Display the in-core label for sd0 as obtained via /dev/rsd0c.

    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. Any existing bootstrap code will be clobbered. 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 -e -r sd0

Read the on-disk label for sd0, edit it and reinstall in-core as well as on-disk. Existing bootstrap code is unaffected.

    disklabel -R sd0 mylabel

Restore the on-disk and in-core label for sd0 from information in mylabel. Existing bootstrap code is unaffected.

    disklabel -B sd0

Install a new bootstrap on sd0. The boot code comes from /usr/mdec/sdboot and possibly /usr/mdec/bootsd. On-disk and in-core labels are unchanged.

    disklabel -w -B /dev/rsd0c -b newboot sd2212

Install a new label and bootstrap. The label is derived from disktab information for ``sd2212'' and installed both in-core and on-disk. The bootstrap code comes from the file /usr/mdec/newboot.

    disklabel -R -r sd0 <protofile>

Install a new label and bootstrap on a disk, from a prototype label file. This is a good way to install a label on a previously unlabeled disk for which no entry appears in /etc/disktab, if you create the prototype file by dumping some other disk's label to a file and editing it appropriately (total size, partition offsets, types, etc.)

SEE ALSO
disktab(5), disklabel(5), installboot(8)

DIAGNOSTICS
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 partition 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.

On some machines the bootstrap code may not fit entirely in the area allocated for it by some filesystems. As a result, it may not be possible to have filesystems on some partitions of a ``bootable'' disk. When installing bootstrap code, disklabel checks for these cases. If the installed boot code would overlap a partition of type FS_UNUSED it is marked as type FS_BOOT. The newfs(8) utility will disallow creation of filesystems on FS_BOOT partitions. Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT, disklabel will not install bootstrap code that overlaps it.

BUGS
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 ``a'' partition on the tahoe, the ``d'' partition on the i386 or its successors, and the ``c'' partition on all others.

On the sun3 and sparc 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 sun3 or sparc 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 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 therefore cannot be booted from.