1.\" $NetBSD: disklabel.8,v 1.59 2006/02/04 20:10:53 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 January 29, 2006 36.Dt DISKLABEL 8 37.Os 38.Sh NAME 39.Nm disklabel 40.Nd read and write disk pack label 41.Sh SYNOPSIS 42.\" disklabel: read label 43.Nm 44.Op Fl ACDFrtv 45.Ar disk 46.\" disklabel -e: read/modify/write using $EDITOR 47.Nm 48.Fl e 49.Op Fl CDFIrv 50.Ar disk 51.\" disklabel -i: read/modify/write using builtin commands 52.Nm 53.Fl i 54.Op Fl DFIrv 55.Ar disk 56.\" disklabel -R: write from edited output 57.Nm 58.Fl R 59.Op Fl DFrv 60.Ar disk Ar protofile 61.\" disklabel -w: write from disctab entry 62.Nm 63.Fl w 64.Op Fl DFrv 65.Op Fl f Ar disktab 66.Ar disk Ar disktype 67.Oo Ar packid Oc 68.\" disklabel -NW: disallow/allow writes to the label sector 69.Nm 70.Op Fl NW 71.Ar disk 72.Sh DESCRIPTION 73.Nm 74can be used to install, examine, or modify the label on a disk drive or pack. 75When writing the label, it can be used to change the drive identification, 76the disk partitions on the drive, or to replace a damaged label. 77.Pp 78The 79.Fl e , i , R , w , N , 80and 81.Fl W 82options determine the basic operation, if none are specified the label 83is displayed. 84.Bl -tag -width flag 85.It Fl e 86Edit the existing label (using 87.Ev EDITOR ) 88and write it back to the disk. 89If 90.Ev EDITOR 91is undefined, then 92.Xr vi 1 93is used. 94.It Fl i 95Interactively update the existing label and write it back to the disk. 96.It Fl R 97Write (restore) a label by reading it from 98.Ar protofile . 99The file should be in the same format as the default output. 100.It Fl w 101Write a standard label for the specified 102.Ar disktype . 103See 104.Xr disktab 5 . 105.It Fl N 106Disallow writes to the disk sector that contains the label. 107This is the default state. 108.It Fl W 109Allow writes to the disk sector that contains the label. 110This state may not persist if no programs have the disk open. 111.El 112.Pp 113The majority of the rest of the options affect more than one form of the 114command: 115.Bl -tag -width flag 116.It Fl A 117Read all labels from the disk, including ones deleted with 118.Nm 119.Fl D . 120Implies 121.Fl r . 122.It Fl C 123Output the partition offset and size values in 124.Aq cylinder/head/sector 125format. 126Note this format is always accepted on input with either the 127.Fl e 128or 129.Fl R 130flags. 131.It Fl D 132Delete all existing labels (by 1's complimenting the magic number) before 133writing any labels to their default location. 134Implies 135.Fl r . 136If 137.Fl D 138is specified without a request to write the label, then existing labels are 139just deleted. 140.It Fl F 141Treat 142.Ar disk 143as a regular file. 144This suppresses all 145.Xr ioctl 2 146calls, and is the default if 147.Ar disk 148is a regular file. 149.Ar disk 150is always opened using 151.Xr opendisk 3 152even if 153.Fl F 154is specified. 155Implies 156.Fl r . 157.It Fl I 158If a label cannot be read from 159.Ar disk 160request the default one from the kernel. 161Implies 162.Fl r . 163.It Fl f Ar disktab 164Specify the name of a file to use instead of 165.Pa /etc/disktab . 166.It Fl r 167Read/write the disk directly rather than using 168.Xr ioctl 2 169requests on the kernel. 170When writing a label, the kernel will be told about the label before the 171label is written and asked to write afterwards. 172This is the historic behaviour and can be supressed by specifying 173.Fl F . 174.It Fl t 175Format the output as a 176.Xr disktab 5 177entry. 178.It Fl v 179Be verbose about the operations being done, in particular the disk sectors 180being read and written. 181Specifying 182.Fl v 183more than once will increase the verbosity. 184.El 185.Pp 186On systems that expect to have disks with MBR partitions (see 187.Xr fdisk 8 ) 188.Nm 189will find, and update if requested, labels in the first 8k of type 169 190.Pq Nx 191MBR labels and within the first 8k of the physical disk. 192On other systems 193.Nm 194will only look at the start of the disk. 195The offset at which the labels are written is also system dependent. 196.Pp 197.Nm 198will detect byteswapped labels, but currently cannot display them. 199.Pp 200Previous versions of 201.Nm 202could update the bootstrap code on some architectures. 203This functionality has been subsumed by 204.Xr installboot 8 . 205.Sh EXIT STATUS 206The exit status of 207.Nm 208is set to indicate any errors or warnings. 209The values used are: 210.Bl -tag -width indent 211.It 0 212The 213.Nm 214utility has completed successfully. 215.It 1 216A fatal error has occurred, such as unknown options passed on the 217command line, or writing the disklabel failed. 218.It 4 219An I/O error of some sort occurred. 220.It 101..n 221One or more warnings occured while reading the disklabel. 222Subtract 100 to get the number of warnings detected. 223.El 224.Sh FILES 225.Bl -tag -width /etc/disktab -compact 226.It Pa /etc/disktab 227.El 228.Sh EXAMPLES 229.Dl Ic disklabel sd0 230.Pp 231Display the in-core label for sd0 as obtained via 232.Pa /dev/rsd0c . 233.Pp 234.Dl Ic disklabel -w -r /dev/rsd0c sd2212 foo 235.Pp 236Create a label for sd0 based on information for 237.Dq sd2212 238found in 239.Pa /etc/disktab , 240using 241.Pa foo 242as the disk pack label. 243If you do not have an entry for your disk in 244.Pa /etc/disktab , 245you can use this style to put 246an initial label onto a new disk. 247Then dump the label to a file (using 248.Ic disklabel sd0 \*[Gt] protofile ) , 249editing the file, and replacing the label with 250.Ic disklabel -R sd0 protofile . 251.Pp 252.Dl Ic disklabel -e -r sd0 253.Pp 254Read the on-disk label for sd0, edit it and reinstall in-core as well 255as on-disk. 256.Pp 257.Dl Ic disklabel -e -I sd0 258.Pp 259As previous, but don't fail if there was no label on the disk yet; 260provide some default values instead. 261.Pp 262.Dl Ic disklabel -i -I sd0 263.Pp 264As previous, only use the built-in interactive editor. 265.Pp 266.Dl Ic disklabel -R sd0 mylabel 267.Pp 268Restore the on-disk and in-core label for sd0 from information in 269.Pa mylabel . 270.Sh DIAGNOSTICS 271The kernel device drivers will not allow the size of a disk partition 272to be decreased or the offset of a partition to be changed while it is open. 273Some device drivers create a label containing only a single large partition 274if a disk is unlabeled; thus, the label must be written to the 275.Dq a 276partition of the disk while it is open. 277This sometimes requires the desired label to be set in two steps, 278the first one creating at least one other partition, 279and the second setting the label on the new partition 280while shrinking the 281.Dq a 282partition. 283.Sh SEE ALSO 284.Xr opendisk 3 , 285.Xr disklabel 5 , 286.Xr disktab 5 , 287.Xr dkctl 8 , 288.Xr fdisk 8 , 289.Xr installboot 8 , 290.Xr mbrlabel 8 , 291.Xr mscdlabel 8 292.Sh BUGS 293If the disk partition is not specified in the disk name 294(i.e., 295.Ar xy0 296instead of 297.Ar /dev/rxy0c ) , 298.Nm 299will construct the full pathname of the disk and use the 300.Dq d 301partition on i386, hpcmips, or arc, and the 302.Dq c 303partition on all others. 304.Pp 305On the sparc, sparc64, sun2, and sun3 306.Nx 307systems, the size of each partition must be a multiple of the number 308of sectors per cylinder (i.e., each partition must be an integer 309number of cylinders), or the boot ROMs will declare the label 310invalid and fail to boot the system. 311.Pp 312In addition, the 313.Fl r 314option should never be used on a sparc, sparc64, sun2, or sun3 system 315boot disk - the 316.Nx 317kernel translates the 318.Nx 319disk label into a SunOS compatible format (which is required by the 320boot PROMs) when it writes the label. 321Using the 322.Fl r 323flag causes 324.Nm 325to write directly to disk, and bypass the format translation. 326This will result in a disk label that the PROMs will not recognize, 327and that therefore cannot be booted from. 328