1.\" $NetBSD: disklabel.8,v 1.57 2005/06/19 17:24:20 wiz Exp $ 2.\" 3.\" Copyright (c) 1987, 1988, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" Symmetric Computer Systems. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 34.\" 35.Dd June 17, 2005 36.Dt DISKLABEL 8 37.Os 38.Sh NAME 39.Nm disklabel 40.Nd read and write disk pack label 41.Sh SYNOPSIS 42.Nm 43.Op Fl CFrt 44.Ar disk 45.Nm 46.Fl w 47.Op Fl \&Fr 48.Op Fl f Ar disktab 49.Ar disk Ar disktype 50.Oo Ar packid Oc 51.Nm 52.Fl e 53.Op Fl CFIr 54.Ar disk 55.Nm 56.Fl i 57.\" .Op Fl Fr - except Fr is treated as a macro :-( 58.Op Fl FIr 59.Ar disk 60.Nm 61.Fl R 62.Op Fl \&Fr 63.Ar disk Ar protofile 64.Nm 65.Op Fl NW 66.Ar disk 67.Sh DESCRIPTION 68.Nm 69can be used to install, examine or modify the label on a disk drive or pack. 70When writing the label, it can be used 71to change the drive identification, 72the disk partitions on the drive, 73or to replace a damaged label. 74.Pp 75There are several forms of the command that read (display), install, or edit 76the label on a disk. 77Each form has an additional option, 78.Fl r , 79which causes the label to be read from or written to the disk directly, 80rather than going through the system's in-core copy of the label. 81This option may allow a label to be installed on a disk 82without kernel support for a label, such as when labels are first installed 83on a system; it must be used when first installing a label on a disk. 84Any special effects of the 85.Fl r 86flag are described with the affected commands. 87.Pp 88The 89.Fl F 90option indicates that 91.Nm 92should treat 93.Ar disk 94as if it is a regular file, instead of as if it is a block device, 95for the purposes of reading and writing a disklabel. 96.Pp 97The 98.Fl I 99option is similar to the 100.Fl r 101option but provides defaults instead of failing with 102an error, if there is no existing disklabel on the disk. 103.Pp 104The first form of the command (read) is used to examine the label on the named 105disk drive (e.g., 106.Pa sd0 107or 108.Pa /dev/rsd0c ) . 109It will display all of the parameters associated with the drive 110and its partition layout. 111Unless the 112.Fl r 113flag is given, 114the kernel's in-core copy of the label is displayed; 115if the disk has no label, or the partition types on the disk are incorrect, 116the kernel may have constructed or modified the label. 117If the 118.Fl r 119flag is given, the label from the raw disk will be displayed rather 120than the in-core label. 121If the 122.Fl t 123flag is given, then the label will be formatted as a 124.Xr disktab 5 125entry. 126.Pp 127The second form of the command, with the 128.Fl w 129flag, is used to write a standard label on the designated drive. 130The required arguments to 131.Nm 132are the drive to be labelled (e.g., 133.Pa sd0 ) , 134and the drive type as described in the 135.Xr disktab 5 136file. 137The drive parameters and partitions are taken from that file. 138If different disks of the same physical type are to have different 139partitions, it will be necessary to have separate disktab entries 140describing each, or to edit the label after installation as described below. 141The optional argument is a pack identification string, 142up to 16 characters long. 143The pack id must be quoted if it contains blanks. 144If the disk does not already have a label, the 145.Fl r 146flag must be used. 147In either case, the kernel's in-core label is replaced. 148.Pp 149An alternate 150.Xr disktab 5 151file may be specified with the 152.Fl f Ar disktab 153option. 154.Pp 155An existing disk label may be edited by using the 156.Fl e 157flag. 158The label is formatted and then supplied to an editor for changes. 159If no editor is specified in an 160.Ev EDITOR 161environment variable, 162.Xr vi 1 163is used. 164When the editor terminates, the formatted label is reread 165and used to rewrite the disk label. 166.Pp 167Labels can also created interactively using the 168.Fl i 169flag. 170.Pp 171The 172.Fl C 173flag causes the partition offset and size values to be displayed in 174.Aq cylinder/track/sector 175format. 176Note that, regardless of whether 177.Fl C 178was specified, this format is always accepted by 179.Nm 180on input with either the 181.Fl e 182or 183.Fl R 184flag. 185.Pp 186With the 187.Fl R 188flag, 189.Nm 190is capable of restoring a disk label that was formatted 191in a prior operation and saved in an ascii file. 192The prototype file used to create the label should be in the same format 193as that produced when reading or editing a label. 194Comments are delimited by 195.Ar \&# 196and newline. 197.Pp 198The 199.Fl NW 200flags for 201.Nm 202explicitly disallow and 203allow, respectively, writing of the pack label area on the selected disk. 204.Pp 205Previous versions of 206.Nm 207could update the bootstrap code on some architectures. 208This functionality has been subsumed by 209.Xr installboot 8 . 210.Sh EXIT STATUS 211The exit status of 212.Nm 213is set to indicate any errors or warnings. 214The values used are: 215.Bl -tag -width indent 216.It 0 217The 218.Nm 219utility has completed successfully. 220.It 1 221A fatal error has occurred, such as unknown options passed on the command line, 222or writing the disklabel failed. 223.It 4 224An I/O error of some sort occurred. 225.It 101..n 226One or more warnings occured while reading the disklabel. 227Subtract 100 to get the number of warnings detected. 228.El 229.Sh FILES 230.Bl -tag -width /etc/disktab -compact 231.It Pa /etc/disktab 232.El 233.Sh EXAMPLES 234.Dl disklabel sd0 235.Pp 236Display the in-core label for sd0 as obtained via 237.Pa /dev/rsd0c . 238.Pp 239.Dl disklabel -w -r /dev/rsd0c sd2212 foo 240.Pp 241Create a label for sd0 based on information for 242.Dq sd2212 243found in 244.Pa /etc/disktab , 245using 246.Pa foo 247as the disk pack label. 248If you do not have an entry for your disk in 249.Pa /etc/disktab , 250you can use this style to put 251an initial label onto a new disk. 252Then dump the label to a file (using 253.Em disklabel sd0 \*[Gt] 254.Em protofile ) , 255editing the file, and replacing the label with 256.Em disklabel -R sd0 257.Em protofile . 258.Pp 259.Dl disklabel -e -r sd0 260.Pp 261Read the on-disk label for sd0, edit it and reinstall in-core as well 262as on-disk. 263.Pp 264.Dl disklabel -e -I sd0 265.Pp 266As previous, but don't fail if there was no label on the disk yet; 267provide some default values instead. 268.Pp 269.Dl disklabel -i -I sd0 270.Pp 271As previous, only use the built-in interactive editor. 272.Pp 273.Dl disklabel -R sd0 mylabel 274.Pp 275Restore the on-disk and in-core label for sd0 from information in 276.Pa mylabel . 277.Sh DIAGNOSTICS 278The kernel device drivers will not allow the size of a disk partition 279to be decreased or the offset of a partition to be changed while it is open. 280Some device drivers create a label containing only a single large partition 281if a disk is unlabeled; thus, the label must be written to the 282.Dq a 283partition of the disk while it is open. 284This sometimes requires the desired label to be set in two steps, 285the first one creating at least one other partition, 286and the second setting the label on the new partition 287while shrinking the 288.Dq a 289partition. 290.Sh SEE ALSO 291.Xr disklabel 5 , 292.Xr disktab 5 , 293.Xr dkctl 8 , 294.Xr fdisk 8 , 295.Xr installboot 8 , 296.Xr mbrlabel 8 , 297.Xr mscdlabel 8 298.Sh BUGS 299If the disk partition is not specified in the disk name 300(i.e., 301.Dq xy0 302instead of 303.Dq /dev/rxy0c ) , 304.Nm 305will construct the full pathname of the disk and use the 306.Dq d 307partition on i386, hpcmips, or arc, and the 308.Dq c 309partition on all others. 310.Pp 311On the sparc, sparc64, sun2, and sun3 312.Nx 313systems, the size of each partition must be a multiple of the number 314of sectors per cylinder (i.e., each partition must be an integer 315number of cylinders), or the boot ROMs will declare the label 316invalid and fail to boot the system. 317.Pp 318In addition, the 319.Fl r 320option should never be used on a sparc, sparc64, sun2 or sun3 system 321boot disk - the 322.Nx 323kernel translates the 324.Nx 325disk label into a SunOS compatible format (which is required by the 326boot PROMs) when it writes the label. 327Using the 328.Fl r 329flag causes 330.Nm 331to write directly to disk, and bypass the format translation. 332This will result in a disk label that the PROMs will not recognize, 333and that therefore cannot be booted from. 334