1.\" Copyright (c) 1987, 1988, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Symmetric Computer Systems. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed by the University of 18.\" California, Berkeley and its contributors. 19.\" 4. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 36.\" $Id$ 37.\" 38.Dd "April 19, 1994" 39.Dt DISKLABEL 8 40.Os BSD 4.2 41.Sh NAME 42.Nm disklabel 43.Nd read and write disk pack label 44.Sh SYNOPSIS 45.Nm disklabel 46.Op Fl r 47.Ar disk 48.Nm disklabel 49.Fl w 50.Op Fl r 51.Ar disk Ar disktype 52.Oo Ar packid Oc 53.Nm disklabel 54.Fl e 55.Op Fl r 56.Ar disk 57.Nm disklabel 58.Fl R 59.Op Fl r 60.Ar disk Ar protofile 61.Nm disklabel 62.Op Fl NW 63.Ar disk 64.sp 65.Nm disklabel 66.Fl B 67.Oo 68.Fl b Ar boot1 69.Op Fl s Ar boot2 70.Oc 71.Ar disk 72.Oo Ar disktype Oc 73.Nm disklabel 74.Fl w 75.Fl B 76.Oo 77.Fl b Ar boot1 78.Op Fl s Ar boot2 79.Oc 80.Ar disk Ar disktype 81.Oo Ar packid Oc 82.Nm disklabel 83.Fl R 84.Fl B 85.Oo 86.Fl b Ar boot1 87.Op Fl s Ar boot2 88.Oc 89.Ar disk Ar protofile 90.Oo Ar disktype Oc 91.Sh DESCRIPTION 92.Nm Disklabel 93can be used to install, examine or modify the label on a disk drive or pack. 94When writing the label, it can be used 95to change the drive identification, 96the disk partitions on the drive, 97or to replace a damaged label. 98On some systems, 99.Nm disklabel 100can be used to install bootstrap code as well. 101There are several forms of the command that read (display), install or edit 102the label on a disk. 103Each form has an additional option, 104.Fl r , 105which causes the label to be read from or written to the disk directly, 106rather than going through the system's in-core copy of the label. 107This option may allow a label to be installed on a disk 108without kernel support for a label, such as when labels are first installed 109on a system; it must be used when first installing a label on a disk. 110The specific effect of 111.Fl r 112is described under each command. 113The read and install forms also support the 114.Fl B 115option to install bootstrap code. 116These variants are described later. 117.Pp 118The first form of the command (read) is used to examine the label on the named 119disk drive (e.g. sd0 or /dev/rsd0c). 120It will display all of the parameters associated with the drive 121and its partition layout. 122Unless the 123.Fl r 124flag is given, 125the kernel's in-core copy of the label is displayed; 126if the disk has no label, or the partition types on the disk are incorrect, 127the kernel may have constructed or modified the label. 128If the 129.Fl r 130flag is given, the label from the raw disk will be displayed rather 131than the in-core label. 132.Pp 133The second form of the command, with the 134.Fl w 135flag, is used to write a standard label on the designated drive. 136The required arguments to 137.Nm disklabel 138are the drive to be labelled (e.g. sd0), and 139the drive type as described in the 140.Xr disktab 5 141file. 142The drive parameters and partitions are taken from that file. 143If different disks of the same physical type are to have different 144partitions, it will be necessary to have separate disktab entries 145describing each, or to edit the label after installation as described below. 146The optional argument is a pack identification string, 147up to 16 characters long. 148The pack id must be quoted if it contains blanks. 149If the 150.Fl r 151flag is given, the disk sectors containing the label and bootstrap 152will be written directly. 153A side-effect of this is that any existing bootstrap code will be overwritten 154and the disk rendered unbootable. 155If 156.Fl r 157is not specified, 158the existing label will be updated via the in-core copy and any bootstrap 159code will be unaffected. 160If the disk does not already have a label, the 161.Fl r 162flag must be used. 163In either case, the kernel's in-core label is replaced. 164.Pp 165For a virgin disk that is not known to 166.Xr disktab 5 , 167.Ar disktype 168can be specified as 169.Dq auto . 170In this case, the driver is requested to produce a virgin label for the 171disk. This might or might not be successful, depending on whether the 172driver for the disk is able to get the required data without reading 173anything from the disk at all. It will likely succeed for all SCSI 174disks, most IDE disks, and vnode devices. Writing a label to the 175disk is the only supported operation, and the 176.Ar disk 177itself must be provided as the canonical name, i.e. not as a full 178path name. 179.Pp 180An existing disk label may be edited by using the 181.Fl e 182flag. 183The label is read from the in-core kernel copy, 184or directly from the disk if the 185.Fl r 186flag is also given. 187The label is formatted and then supplied to an editor for changes. 188If no editor is specified in an 189.Ev EDITOR 190environment variable, 191.Xr vi 1 192is used. 193When the editor terminates, the formatted label is reread 194and used to rewrite the disk label. 195Existing bootstrap code is unchanged regardless of whether 196.Fl r 197was specified. 198.Pp 199With the 200.Fl R 201flag, 202.Nm disklabel 203is capable of restoring a disk label that was formatted 204in a prior operation and saved in an ascii file. 205The prototype file used to create the label should be in the same format 206as that produced when reading or editing a label. 207Comments are delimited by 208.Ar \&# 209and newline. 210As with 211.Fl w , 212any existing bootstrap code will be clobbered if 213.Fl r 214is specified and will be unaffected otherwise. 215.Pp 216The 217.Fl NW 218flags for 219.Nm disklabel 220explicitly disallow and 221allow, respectively, writing of the pack label area on the selected disk. 222.Pp 223The final three forms of 224.Nm disklabel 225are used to install boostrap code on machines where the bootstrap is part 226of the label. 227The bootstrap code is comprised of one or two boot programs depending on 228the machine. 229The 230.Fl B 231option is used to denote that bootstrap code is to be installed. 232The 233.Fl r 234flag is implied by 235.Fl B 236and never needs to be specified. 237The name of the boot program(s) to be installed can be selected in a 238variety of ways. 239First, the names can be specified explicitly via the 240.Fl b 241and 242.Fl s 243flags. 244On machines with only a single level of boot program, 245.Fl b 246is the name of that program. 247For machines with a two-level bootstrap, 248.Fl b 249indicates the primary boot program and 250.Fl s 251the secondary boot program. 252If the names are not explicitly given, standard boot programs will be used. 253The boot programs are located in 254.Pa /usr/mdec . 255The names of the programs are taken from the ``b0'' and ``b1'' parameters 256of the 257.Xr disktab 5 258entry for the disk if 259.Ar disktype 260was given and its disktab entry exists and includes those parameters. 261Otherwise, boot program names are derived from the name of the disk. 262These names are of the form 263.Pa basename Ns boot 264for the primary (or only) bootstrap, and 265.Pf boot Pa basename 266for the secondary bootstrap; 267for example, 268.Pa /usr/mdec/sdboot 269and 270.Pa /usr/mdec/bootsd 271if the disk device is 272.Em sd0 . 273.Pp 274The first of the three boot-installation forms is used to install 275bootstrap code without changing the existing label. 276It is essentially a read command with respect to the disk label 277itself and all options are related to the specification of the boot 278program as described previously. 279The final two forms are analogous to the basic write and restore versions 280except that they will install bootstrap code in addition to a new label. 281.Sh FILES 282.Bl -tag -width Pa -compact 283.It Pa /etc/disktab 284.It Pa /usr/mdec/ Ns Em xx Ns boot 285.It Pa /usr/mdec/boot Ns Em xx 286.El 287.Sh EXAMPLES 288.Dl disklabel sd0 289.Pp 290Display the in-core label for sd0 as obtained via 291.Pa /dev/rsd0c . 292.Pp 293.Dl disklabel -w -r /dev/rsd0c sd2212 foo 294.Pp 295Create a label for sd0 based on information for ``sd2212'' found in 296.Pa /etc/disktab . 297Any existing bootstrap code will be clobbered. 298.Pp 299.Dl disklabel -e -r sd0 300.Pp 301Read the on-disk label for sd0, edit it and reinstall in-core as well 302as on-disk. 303Existing bootstrap code is unaffected. 304.Pp 305.Dl disklabel -r -w sd0 auto 306.Pp 307Try to auto-detect the required information from sd0, and write a new 308label to the disk. Use another disklabel -e command to edit the 309partitioning and file system information. 310.Pp 311.Dl disklabel -R sd0 mylabel 312.Pp 313Restore the on-disk and in-core label for sd0 from information in 314.Pa mylabel . 315Existing bootstrap code is unaffected. 316.Pp 317.Dl disklabel -B sd0 318.Pp 319Install a new bootstrap on sd0. 320The boot code comes from 321.Pa /usr/mdec/sdboot 322and possibly 323.Pa /usr/mdec/bootsd . 324On-disk and in-core labels are unchanged. 325.Pp 326.Dl disklabel -w -B /dev/rsd0c -b newboot sd2212 327.Pp 328Install a new label and bootstrap. 329The label is derived from disktab information for ``sd2212'' and 330installed both in-core and on-disk. 331The bootstrap code comes from the file 332.Pa /usr/mdec/newboot . 333.Sh SEE ALSO 334.Xr disklabel 5 , 335.Xr disktab 5 336.Sh DIAGNOSTICS 337The kernel device drivers will not allow the size of a disk partition 338to be decreased or the offset of a partition to be changed while it is open. 339Some device drivers create a label containing only a single large partition 340if a disk is unlabeled; thus, the label must be written to the ``a'' 341partition of the disk while it is open. 342This sometimes requires the desired label to be set in two steps, 343the first one creating at least one other partition, 344and the second setting the label on the new partition 345while shrinking the ``a'' partition. 346.Pp 347On some machines the bootstrap code may not fit entirely in the area 348allocated for it by some filesystems. 349As a result, it may not be possible to have filesystems on some partitions 350of a ``bootable'' disk. 351When installing bootstrap code, 352.Nm disklabel 353checks for these cases. 354If the installed boot code would overlap a partition of type FS_UNUSED 355it is marked as type FS_BOOT. 356The 357.Xr newfs 8 358utility will disallow creation of filesystems on FS_BOOT partitions. 359Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT, 360.Nm disklabel 361will not install bootstrap code that overlaps it. 362.Sh BUGS 363When a disk name is given without a full pathname, 364the constructed device name uses the ``a'' partition on the tahoe, 365the ``c'' partition on all others. 366.Pp 367For the i386 architecture, the primary bootstrap sector contains 368an embedded 369.Em fdisk 370table. 371.Nm Disklabel 372takes care to not clobber it when installing a bootstrap only 373.Pq Fl B , 374or when editing an existing label 375.Pq Fl e , 376but it unconditionally writes the primary bootstrap program onto 377the disk for 378.Fl w 379or 380.Fl R , 381thus replacing the 382.Em fdisk 383table by the dummy one in the bootstrap program. This is only of 384concern if the disk is fully dedicated, so that the BSD disklabel 385starts at absolute block 0 on the disk. 386