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.\" %sccs.include.redist.roff% 8.\" 9.\" @(#)disklabel.8 8.2 (Berkeley) 04/19/94 10.\" 11.Dd "" 12.Dt DISKLABEL 8 13.Os BSD 4.2 14.Sh NAME 15.Nm disklabel 16.Nd read and write disk pack label 17.Sh SYNOPSIS 18.Nm disklabel 19.Op Fl r 20.Ar disk 21.Nm disklabel 22.Fl w 23.Op Fl r 24.Ar disk Ar disktype 25.Oo Ar packid Oc 26.Nm disklabel 27.Fl e 28.Op Fl r 29.Ar disk 30.Nm disklabel 31.Fl R 32.Op Fl r 33.Ar disk Ar protofile 34.Nm disklabel 35.Op Fl NW 36.Ar disk 37.sp 38.Nm disklabel 39.Fl B 40.Oo 41.Fl b Ar boot1 42.Op Fl s Ar boot2 43.Oc 44.Ar disk 45.Oo Ar disktype Oc 46.Nm disklabel 47.Fl w 48.Fl B 49.Oo 50.Fl b Ar boot1 51.Op Fl s Ar boot2 52.Oc 53.Ar disk Ar disktype 54.Oo Ar packid Oc 55.Nm disklabel 56.Fl R 57.Fl B 58.Oo 59.Fl b Ar boot1 60.Op Fl s Ar boot2 61.Oc 62.Ar disk Ar protofile 63.Oo Ar disktype Oc 64.Sh DESCRIPTION 65.Nm Disklabel 66can be used to install, examine or modify the label on a disk drive or pack. 67When writing the label, it can be used 68to change the drive identification, 69the disk partitions on the drive, 70or to replace a damaged label. 71On some systems, 72.Nm disklabel 73can be used to install bootstrap code as well. 74There are several forms of the command that read (display), install or edit 75the label on a disk. 76Each form has an additional option, 77.Fl r , 78which causes the label to be read from or written to the disk directly, 79rather than going through the system's in-core copy of the label. 80This option may allow a label to be installed on a disk 81without kernel support for a label, such as when labels are first installed 82on a system; it must be used when first installing a label on a disk. 83The specific effect of 84.Fl r 85is described under each command. 86The read and install forms also support the 87.Fl B 88option to install bootstrap code. 89These variants are described later. 90.Pp 91The first form of the command (read) is used to examine the label on the named 92disk drive (e.g. sd0 or /dev/rsd0c). 93It will display all of the parameters associated with the drive 94and its partition layout. 95Unless the 96.Fl r 97flag is given, 98the kernel's in-core copy of the label is displayed; 99if the disk has no label, or the partition types on the disk are incorrect, 100the kernel may have constructed or modified the label. 101If the 102.Fl r 103flag is given, the label from the raw disk will be displayed rather 104than the in-core label. 105.Pp 106The second form of the command, with the 107.Fl w 108flag, is used to write a standard label on the designated drive. 109The required arguments to 110.Nm disklabel 111are the drive to be labelled (e.g. sd0), and 112the drive type as described in the 113.Xr disktab 5 114file. 115The drive parameters and partitions are taken from that file. 116If different disks of the same physical type are to have different 117partitions, it will be necessary to have separate disktab entries 118describing each, or to edit the label after installation as described below. 119The optional argument is a pack identification string, 120up to 16 characters long. 121The pack id must be quoted if it contains blanks. 122If the 123.Fl r 124flag is given, the disk sectors containing the label and bootstrap 125will be written directly. 126A side-effect of this is that any existing bootstrap code will be overwritten 127and the disk rendered unbootable. 128If 129.Fl r 130is not specified, 131the existing label will be updated via the in-core copy and any bootstrap 132code will be unaffected. 133If the disk does not already have a label, the 134.Fl r 135flag must be used. 136In either case, the kernel's in-core label is replaced. 137.Pp 138An existing disk label may be edited by using the 139.Fl e 140flag. 141The label is read from the in-core kernel copy, 142or directly from the disk if the 143.Fl r 144flag is also given. 145The label is formatted and then supplied to an editor for changes. 146If no editor is specified in an 147.Ev EDITOR 148environment variable, 149.Xr vi 1 150is used. 151When the editor terminates, the formatted label is reread 152and used to rewrite the disk label. 153Existing bootstrap code is unchanged regardless of whether 154.Fl r 155was specified. 156.Pp 157With the 158.Fl R 159flag, 160.Nm disklabel 161is capable of restoring a disk label that was formatted 162in a prior operation and saved in an ascii file. 163The prototype file used to create the label should be in the same format 164as that produced when reading or editing a label. 165Comments are delimited by 166.Ar \&# 167and newline. 168As with 169.Fl w , 170any existing bootstrap code will be clobbered if 171.Fl r 172is specified and will be unaffected otherwise. 173.Pp 174The 175.Fl NW 176flags for 177.Nm disklabel 178explicitly disallow and 179allow, respectively, writing of the pack label area on the selected disk. 180.Pp 181The final three forms of 182.Nm disklabel 183are used to install boostrap code on machines where the bootstrap is part 184of the label. 185The bootstrap code is comprised of one or two boot programs depending on 186the machine. 187The 188.Fl B 189option is used to denote that bootstrap code is to be installed. 190The 191.Fl r 192flag is implied by 193.Fl B 194and never needs to be specified. 195The name of the boot program(s) to be installed can be selected in a 196variety of ways. 197First, the names can be specified explicitly via the 198.Fl b 199and 200.Fl s 201flags. 202On machines with only a single level of boot program, 203.Fl b 204is the name of that program. 205For machines with a two-level bootstrap, 206.Fl b 207indicates the primary boot program and 208.Fl s 209the secondary boot program. 210If the names are not explicitly given, standard boot programs will be used. 211The boot programs are located in 212.Pa /usr/mdec . 213The names of the programs are taken from the ``b0'' and ``b1'' parameters 214of the 215.Xr disktab 5 216entry for the disk if 217.Ar disktype 218was given and its disktab entry exists and includes those parameters. 219Otherwise, boot program names are derived from the name of the disk. 220These names are of the form 221.Pa basename Ns boot 222for the primary (or only) bootstrap, and 223.Pf boot Pa basename 224for the secondary bootstrap; 225for example, 226.Pa /usr/mdec/sdboot 227and 228.Pa /usr/mdec/bootsd 229if the disk device is 230.Em sd0 . 231.Pp 232The first of the three boot-installation forms is used to install 233bootstrap code without changing the existing label. 234It is essentially a read command with respect to the disk label 235itself and all options are related to the specification of the boot 236program as described previously. 237The final two forms are analogous to the basic write and restore versions 238except that they will install bootstrap code in addition to a new label. 239.Sh FILES 240.Bl -tag -width Pa -compact 241.It Pa /etc/disktab 242.It Pa /usr/mdec/ Ns Em xx Ns boot 243.It Pa /usr/mdec/boot Ns Em xx 244.El 245.Sh EXAMPLES 246.Dl disklabel sd0 247.Pp 248Display the in-core label for sd0 as obtained via 249.Pa /dev/rsd0c . 250.Pp 251.Dl disklabel -w -r /dev/rsd0c sd2212 foo 252.Pp 253Create a label for sd0 based on information for ``sd2212'' found in 254.Pa /etc/disktab . 255Any existing bootstrap code will be clobbered. 256.Pp 257.Dl disklabel -e -r sd0 258.Pp 259Read the on-disk label for sd0, edit it and reinstall in-core as well 260as on-disk. 261Existing bootstrap code is unaffected. 262.Pp 263.Dl disklabel -R sd0 mylabel 264.Pp 265Restore the on-disk and in-core label for sd0 from information in 266.Pa mylabel . 267Existing bootstrap code is unaffected. 268.Pp 269.Dl disklabel -B sd0 270.Pp 271Install a new bootstrap on sd0. 272The boot code comes from 273.Pa /usr/mdec/sdboot 274and possibly 275.Pa /usr/mdec/bootsd . 276On-disk and in-core labels are unchanged. 277.Pp 278.Dl disklabel -w -B /dev/rsd0c -b newboot sd2212 279.Pp 280Install a new label and bootstrap. 281The label is derived from disktab information for ``sd2212'' and 282installed both in-core and on-disk. 283The bootstrap code comes from the file 284.Pa /usr/mdec/newboot . 285.Sh SEE ALSO 286.Xr disktab 5 , 287.Xr disklabel 5 288.Sh DIAGNOSTICS 289The kernel device drivers will not allow the size of a disk partition 290to be decreased or the offset of a partition to be changed while it is open. 291Some device drivers create a label containing only a single large partition 292if a disk is unlabeled; thus, the label must be written to the ``a'' 293partition of the disk while it is open. 294This sometimes requires the desired label to be set in two steps, 295the first one creating at least one other partition, 296and the second setting the label on the new partition 297while shrinking the ``a'' partition. 298.Pp 299On some machines the bootstrap code may not fit entirely in the area 300allocated for it by some filesystems. 301As a result, it may not be possible to have filesystems on some partitions 302of a ``bootable'' disk. 303When installing bootstrap code, 304.Nm disklabel 305checks for these cases. 306If the installed boot code would overlap a partition of type FS_UNUSED 307it is marked as type FS_BOOT. 308The 309.Xr newfs 8 310utility will disallow creation of filesystems on FS_BOOT partitions. 311Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT, 312.Nm disklabel 313will not install bootstrap code that overlaps it. 314.Sh BUGS 315When a disk name is given without a full pathname, 316the constructed device name uses the ``a'' partition on the tahoe, 317the ``c'' partition on all others. 318