NetBSD/sbin/disklabel/disklabel.8

328 lines
8.7 KiB
Groff

.\" $NetBSD: disklabel.8,v 1.59 2006/02/04 20:10:53 wiz Exp $
.\"
.\" Copyright (c) 1987, 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Symmetric Computer Systems.
.\"
.\" 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. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
.\"
.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94
.\"
.Dd January 29, 2006
.Dt DISKLABEL 8
.Os
.Sh NAME
.Nm disklabel
.Nd read and write disk pack label
.Sh SYNOPSIS
.\" disklabel: read label
.Nm
.Op Fl ACDFrtv
.Ar disk
.\" disklabel -e: read/modify/write using $EDITOR
.Nm
.Fl e
.Op Fl CDFIrv
.Ar disk
.\" disklabel -i: read/modify/write using builtin commands
.Nm
.Fl i
.Op Fl DFIrv
.Ar disk
.\" disklabel -R: write from edited output
.Nm
.Fl R
.Op Fl DFrv
.Ar disk Ar protofile
.\" disklabel -w: write from disctab entry
.Nm
.Fl w
.Op Fl DFrv
.Op Fl f Ar disktab
.Ar disk Ar disktype
.Oo Ar packid Oc
.\" disklabel -NW: disallow/allow writes to the label sector
.Nm
.Op Fl NW
.Ar disk
.Sh DESCRIPTION
.Nm
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.
.Pp
The
.Fl e , i , R , w , N ,
and
.Fl W
options determine the basic operation, if none are specified the label
is displayed.
.Bl -tag -width flag
.It Fl e
Edit the existing label (using
.Ev EDITOR )
and write it back to the disk.
If
.Ev EDITOR
is undefined, then
.Xr vi 1
is used.
.It Fl i
Interactively update the existing label and write it back to the disk.
.It Fl R
Write (restore) a label by reading it from
.Ar protofile .
The file should be in the same format as the default output.
.It Fl w
Write a standard label for the specified
.Ar disktype .
See
.Xr disktab 5 .
.It Fl N
Disallow writes to the disk sector that contains the label.
This is the default state.
.It Fl W
Allow writes to the disk sector that contains the label.
This state may not persist if no programs have the disk open.
.El
.Pp
The majority of the rest of the options affect more than one form of the
command:
.Bl -tag -width flag
.It Fl A
Read all labels from the disk, including ones deleted with
.Nm
.Fl D .
Implies
.Fl r .
.It Fl C
Output the partition offset and size values in
.Aq cylinder/head/sector
format.
Note this format is always accepted on input with either the
.Fl e
or
.Fl R
flags.
.It Fl D
Delete all existing labels (by 1's complimenting the magic number) before
writing any labels to their default location.
Implies
.Fl r .
If
.Fl D
is specified without a request to write the label, then existing labels are
just deleted.
.It Fl F
Treat
.Ar disk
as a regular file.
This suppresses all
.Xr ioctl 2
calls, and is the default if
.Ar disk
is a regular file.
.Ar disk
is always opened using
.Xr opendisk 3
even if
.Fl F
is specified.
Implies
.Fl r .
.It Fl I
If a label cannot be read from
.Ar disk
request the default one from the kernel.
Implies
.Fl r .
.It Fl f Ar disktab
Specify the name of a file to use instead of
.Pa /etc/disktab .
.It Fl r
Read/write the disk directly rather than using
.Xr 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 afterwards.
This is the historic behaviour and can be supressed by specifying
.Fl F .
.It Fl t
Format the output as a
.Xr disktab 5
entry.
.It Fl v
Be verbose about the operations being done, in particular the disk sectors
being read and written.
Specifying
.Fl v
more than once will increase the verbosity.
.El
.Pp
On systems that expect to have disks with MBR partitions (see
.Xr fdisk 8 )
.Nm
will find, and update if requested, labels in the first 8k of type 169
.Pq Nx
MBR labels and within the first 8k of the physical disk.
On other systems
.Nm
will only look at the start of the disk.
The offset at which the labels are written is also system dependent.
.Pp
.Nm
will detect byteswapped labels, but currently cannot display them.
.Pp
Previous versions of
.Nm
could update the bootstrap code on some architectures.
This functionality has been subsumed by
.Xr installboot 8 .
.Sh EXIT STATUS
The exit status of
.Nm
is set to indicate any errors or warnings.
The values used are:
.Bl -tag -width indent
.It 0
The
.Nm
utility has completed successfully.
.It 1
A fatal error has occurred, such as unknown options passed on the
command line, or writing the disklabel failed.
.It 4
An I/O error of some sort occurred.
.It 101..n
One or more warnings occured while reading the disklabel.
Subtract 100 to get the number of warnings detected.
.El
.Sh FILES
.Bl -tag -width /etc/disktab -compact
.It Pa /etc/disktab
.El
.Sh EXAMPLES
.Dl Ic disklabel sd0
.Pp
Display the in-core label for sd0 as obtained via
.Pa /dev/rsd0c .
.Pp
.Dl Ic disklabel -w -r /dev/rsd0c sd2212 foo
.Pp
Create a label for sd0 based on information for
.Dq sd2212
found in
.Pa /etc/disktab ,
using
.Pa foo
as the disk pack label.
If you do not have an entry for your disk in
.Pa /etc/disktab ,
you can use this style to put
an initial label onto a new disk.
Then dump the label to a file (using
.Ic disklabel sd0 \*[Gt] protofile ) ,
editing the file, and replacing the label with
.Ic disklabel -R sd0 protofile .
.Pp
.Dl Ic disklabel -e -r sd0
.Pp
Read the on-disk label for sd0, edit it and reinstall in-core as well
as on-disk.
.Pp
.Dl Ic disklabel -e -I sd0
.Pp
As previous, but don't fail if there was no label on the disk yet;
provide some default values instead.
.Pp
.Dl Ic disklabel -i -I sd0
.Pp
As previous, only use the built-in interactive editor.
.Pp
.Dl Ic disklabel -R sd0 mylabel
.Pp
Restore the on-disk and in-core label for sd0 from information in
.Pa mylabel .
.Sh 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
.Dq 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
.Dq a
partition.
.Sh SEE ALSO
.Xr opendisk 3 ,
.Xr disklabel 5 ,
.Xr disktab 5 ,
.Xr dkctl 8 ,
.Xr fdisk 8 ,
.Xr installboot 8 ,
.Xr mbrlabel 8 ,
.Xr mscdlabel 8
.Sh BUGS
If the disk partition is not specified in the disk name
(i.e.,
.Ar xy0
instead of
.Ar /dev/rxy0c ) ,
.Nm
will construct the full pathname of the disk and use the
.Dq d
partition on i386, hpcmips, or arc, and the
.Dq c
partition on all others.
.Pp
On the sparc, sparc64, sun2, and sun3
.Nx
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.
.Pp
In addition, the
.Fl r
option should never be used on a sparc, sparc64, sun2, or sun3 system
boot disk - the
.Nx
kernel translates the
.Nx
disk label into a SunOS compatible format (which is required by the
boot PROMs) when it writes the label.
Using the
.Fl r
flag causes
.Nm
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.