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