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