1.\" $OpenBSD: disklabel.8,v 1.119 2016/09/01 12:19:35 jmc Exp $ 2.\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $ 3.\" 4.\" Copyright (c) 1987, 1988, 1991, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" This code is derived from software contributed to Berkeley by 8.\" Symmetric Computer Systems. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 35.\" 36.Dd $Mdocdate: September 1 2016 $ 37.Dt DISKLABEL 8 38.Os 39.Sh NAME 40.Nm disklabel 41.Nd read and write disk pack label 42.Sh SYNOPSIS 43.Nm disklabel 44.Op Fl Acdtv 45.Op Fl h | p Ar unit 46.Op Fl T Ar file 47.Ar disk 48.Nm disklabel 49.Fl w 50.Op Fl Acdnv 51.Op Fl T Ar file 52.Ar disk Ar disktype 53.Op Ar packid 54.Nm disklabel 55.Fl e 56.Op Fl Acdnv 57.Op Fl T Ar file 58.Ar disk 59.Nm disklabel 60.Fl E 61.Op Fl Acdnv 62.Op Fl F Ns | Ns Fl f Ar file 63.Op Fl T Ar file 64.Ar disk 65.Nm disklabel 66.Fl R 67.Op Fl nv 68.Op Fl F Ns | Ns Fl f Ar file 69.Ar disk Ar protofile 70.Sh DESCRIPTION 71The 72.Nm 73utility can be used to install, examine, or modify the label on a disk drive or 74pack. 75The disk label contains information about disk characteristics 76.Pq size, type, etc. 77and the partition layout, stored on the disk itself. 78It is used by the operating system to optimize disk I/O and 79locate the filesystems resident on the disk. 80.Pp 81.Nm 82supports 15 configurable partitions, 83.Sq a 84through 85.Sq p , 86excluding 87.Sq c . 88The 89.Sq c 90partition describes the entire physical disk, is automatically created 91by the kernel, and cannot be modified or deleted by 92.Nm . 93By convention, the 94.Sq a 95partition of the boot disk is the root partition, and the 96.Sq b 97partition of the boot disk is the swap partition, 98but all other letters can be used in any order for any other 99partitions as desired. 100.Pp 101The options are as follows: 102.Bl -tag -width Ds 103.It Fl A 104Automatically allocate all the disk space in the 105.Ox 106portion of the disk in the recommended manner. 107See 108.Sx AUTOMATIC DISK ALLOCATION , 109below. 110.It Fl c 111Clear the system's in-core copy of the label and update it based on 112the on-disk label. 113.It Fl d 114Use the 115.Em default 116label. 117This ignores any existing 118.Ox 119disk label on the disk. 120.It Fl E 121Use the built-in command-driven label editor described below. 122.It Fl e 123Edit an existing disk label using the editor specified in the 124.Ev EDITOR 125environment variable, or 126.Xr vi 1 127if none is specified. 128.It Fl F Ar file 129Write entries to 130.Ar file 131in 132.Xr fstab 5 133format for any partitions for which mount point information is known. 134The entries will be written using disklabel UIDs. 135The 136.Fl F 137flag is only valid when used in conjunction with the 138.Fl E 139or 140.Fl R 141flags. 142If 143.Ar file 144already exists, it will be overwritten. 145.It Fl f Ar file 146The same as 147.Fl F 148except that entries will be written using disk device names. 149.It Fl h 150Print partition sizes in human readable format. 151.It Fl n 152Make no permanent changes to the disklabel 153.Pq useful for debugging purposes . 154.It Fl p Ar unit 155Print partition sizes in 156.Ar unit 157instead of sectors. 158Valid units are b(ytes), c(ylinders), k(ilobytes), m(egabytes), g(igabytes) 159and t(erabytes). 160For operations other than displaying a partition the 161.Ql % 162(percent of total) and 163.Ql & 164(percent of free) units are also accepted. 165.It Fl R 166Restore a disk label that was formatted in a prior operation and 167saved in an 168.Tn ASCII 169file. 170.It Fl T Ar file 171Read the template for automatic allocation from 172.Ar file 173instead of using the builtin one. 174See 175.Sx AUTOMATIC DISK ALLOCATION 176below for the format. 177.It Fl t 178Format the label as a 179.Xr disktab 5 180entry. 181.It Fl v 182Print additional information during operation 183.Pq verbose mode . 184.It Fl w 185Write a standard label on the designated drive. 186.It Ar disk 187Specify the 188.Ar disk 189to operate on. 190It can be specified by its full pathname, by an abbreviated disk form, 191or by its disklabel UID. 192In its abbreviated form, the path to the device, the 193.Sq r 194denoting 195.Qq raw device , 196and the partition letter, can all be omitted. 197For example, the first IDE disk can be specified as either 198.Pa /dev/rwd0c , 199.Pa /dev/wd0c , 200or 201.Ar wd0 . 202.It Ar disktype 203Specify a 204.Ar disktype 205entry from the 206.Xr disktab 5 207database. 208.It Ar packid 209Specify a pack identification string for the device 210.Pq see below . 211.It Ar protofile 212Used with the restore option 213.Pq Fl R 214to specify a file to read an ASCII label from. 215.El 216.Pp 217The first form of the command 218.Pq read 219is used to examine the label on the named disk drive. 220It will display all of the parameters associated with the drive 221and its partition layout. 222The kernel's in-core copy of the label is displayed; if 223the disk has no label, or the partition types on the disk are 224incorrect, the kernel may have constructed or modified the label. 225.Pp 226The second form of the command 227.Pq write 228is used to write a standard label on the designated drive. 229The drive parameters and partitions are taken from that file. 230If different disks of the same physical type are 231to have different partitions, it will be necessary to have separate 232disktab entries describing each, or to edit the label after 233installation as described below. 234The optional argument is a pack 235identification string, up to 16 characters long. 236The pack ID must be quoted if it contains blanks. 237The existing label will be updated via the in-core 238copy and any bootstrap code will be unaffected. 239.Pp 240In the third form of the command 241.Pq edit , 242the label is read from the in-core kernel copy 243and then supplied to an editor for changes. 244If no editor is specified in an 245.Ev EDITOR 246environment variable, 247.Xr vi 1 248is used. 249When the editor terminates, the formatted label is reread and 250used to rewrite the disk label. 251Existing bootstrap code is unchanged. 252.Pp 253The built-in label editor 254.Pq fourth form 255provides a simple interactive label editor. 256Some commands or prompts take an optional unit. 257Available units are 258.Sq b 259for bytes, 260.Sq c 261for cylinders, 262.Sq k 263for kilobytes, 264.Sq m 265for megabytes, 266.Sq g 267for gigabytes, 268and 269.Sq t 270for terabytes. 271If no unit is given, the default is to use sectors 272(usually 512 bytes). 273Quantities will be rounded to the nearest 274cylinder when units are specified for sizes 275.Pq or offsets . 276Commands may be aborted by entering 277.Ql ^D 278.Pq Control-D . 279Entering 280.Ql ^D 281at the main 282.Ql > 283prompt will exit the editor. 284At prompts that request a size, 285.Ql * 286may be entered to indicate the rest of the available space. 287The editor commands are as follows: 288.Bl -tag -width "p [unit] " 289.It Cm \&? | h 290Display help message with all available commands. 291There is also 292.Pq simple 293context-sensitive help available at most prompts. 294.It Cm A 295Allocate all the disk space in the recommended manner. 296See 297.Sx AUTOMATIC DISK ALLOCATION , 298below. 299.It Cm a Op Ar part 300Add new partition. 301This option adds a new partition to the disk label. 302If no partition letter is specified 303.Pq a\-p , 304the user will be prompted for one. 305.It Cm b 306Set 307.Ox 308disk boundaries. 309This option tells 310.Nm 311which parts of the disk it is allowed to modify. 312This option is probably only useful for ports with 313.Xr fdisk 8 314partition tables where the ending sector in the MBR is incorrect. 315The user may enter 316.Ql * 317at the 318.Dq Size 319prompt to indicate the entire size of the disk 320.Pq minus the starting sector . 321This is useful for disks where the 322fdisk partition table is incapable of storing the real size. 323Note: data may become corrupted if boundaries are extended such 324that they overlap with other resident operating systems. 325.It Cm c Op Ar part 326Change the size of an existing partition. 327If no partition is specified, the user will be prompted for one. 328The new size may be 329in terms of the aforementioned units and may also be prefixed with 330.Ql + 331or 332.Ql - 333to change the size by a relative amount. 334.It Cm D 335Sets the disk label to the default values as reported by the kernel. 336This simulates the case where there is no disk label. 337.It Cm d Op Ar part 338Delete an existing partition (or 339.Ql * 340to delete all partitions). 341If no partition is specified, the user will be prompted for one. 342.It Cm e 343Edit drive parameters. 344This option is used to set the following parameters: 345disk type, a descriptive label string, sectors/track, 346tracks/cylinder, sectors/cylinder, number of cylinders, 347total sectors, rpm, and interleave. 348.It Xo 349.Cm g 350.Op Ar d | u 351.Xc 352Set disk geometry based on what the 353.Em disk 354or 355.Em user 356thinks (the 357.Em user 358geometry is simply what the label said before 359.Nm 360made any changes). 361.It Cm i 362Change the disklabel UID, specified as a 16-character hexadecimal string. 363If set to all zeros, a new UID will automatically be allocated when the 364disklabel is written to disk. 365.It Cm l Op Ar unit 366Print the disk label header. 367.It Cm M 368Display this manual page. 369The manual page is piped through the pager specified by the 370.Ev PAGER 371environment variable or 'less' if 372.Ev PAGER 373is not set. 374.It Cm m Op Ar part 375Modify parameters for an existing partition. 376If no partition is specified, the user will be prompted for one. 377This option allows 378the user to change the filesystem type, starting offset, partition size, 379and mount point for the specified partition. 380If expert mode is enabled (see 381.Cm X 382below), then block fragment size, block size, and cylinders per group 383can also be modified. 384Note that not all parameters are configurable for 385.Pf non- Bx 386partitions. 387.It Cm n Op Ar part 388Name the mount point for an existing partition. 389If no partition is specified, the user will be prompted for one. 390This option is only valid if 391.Nm 392was invoked with the 393.Fl f 394flag. 395.It Cm p Op Ar unit 396Print the current partition list. 397If a 398.Em unit 399is given, the size and offsets are displayed in terms of the 400specified unit. 401If the unit is 402.Sq * 403it is automatically determined by the size of the smallest 404partition. 405.It Cm q 406Quit the editor. 407If any changes have been made, the user will be 408asked whether or not to save the changes to the on-disk label. 409.It Cm R Op Ar part 410Resize a partition in an automatically allocated label, 411compacting unused space between partitions with a higher offset. 412The last partition will be shrunk if necessary. 413Works only for automatically allocated labels with no spoofed partitions. 414.It Cm r 415Recalculate free space. 416This command displays all the free areas on the disk and the total 417number of free sectors. 418.It Cm s Op Ar path 419Save the label to a file in 420.Tn ASCII 421format (suitable for loading via the 422.Fl R 423option). 424If no path is specified, the user will be prompted for one. 425.It Cm U 426Undo all changes made since entering the editor. 427.It Cm u 428Undo 429.Pq or redo 430last change. 431Entering 432.Em u 433once will undo the last change. 434Entering it again will restore the change. 435.It Cm w 436Write the label to disk. 437This option will commit any changes to the on-disk label. 438.It Cm X 439Toggle 440.Dq expert mode . 441By default, some settings are reserved for experts only 442(such as the block and fragment size on ffs partitions). 443.It Cm x 444Exit the editor without saving any changes to the on-disk label. 445.It Cm z 446Zero out the existing partition table and mountpoint information, 447leaving only the 'c' partition. 448The drive parameters are not changed. 449.El 450.Pp 451In the restore form of the command 452.Pq fifth form , 453the prototype file used to create the label should be in the same format 454as that produced when reading or editing a label. 455Comments are delimited by 456.Ar # 457and newline. 458Any existing bootstrap code will be unaffected. 459.Pp 460The final three forms of 461.Nm 462are used to install bootstrap code on machines where the bootstrap is 463part of the label. 464.Pp 465Note that when a disk has no real 466.Bx 467disklabel, the kernel creates a 468default label so that the disk can be used. 469This default label will include other partitions found on the disk if 470they are supported on your architecture. 471For example, on systems that support 472.Xr fdisk 8 473partitions the default label will also include DOS and Linux partitions. 474However, these entries are not dynamic, they are fixed at the time 475.Nm 476is run. 477That means that subsequent changes that affect 478.Pf non- Ox 479partitions will not be present in the default label, 480though they may be updated by hand. 481To see the default label, run 482.Nm 483with the 484.Fl d 485flag. 486.Nm 487can then be run with the 488.Fl e 489flag and any entries pasted as desired from the default label into the real one. 490.Sh AUTOMATIC DISK ALLOCATION 491The 492.Fl A 493option and the editor command 494.Cm A 495automatically create a disklabel with a set of partitions 496suitable for a majority of 497.Ox 498installations. 499Any existing 500.Ox 501disklabel on the disk is ignored, but native partitions 502that would normally be spoofed are preserved in the disklabel, 503and are not modified during the allocation process. 504.Pp 505Disk size determines the set of partitions which are created. 506Each partition is allocated space between a specified minimum 507and maximum. 508Initially, each partition is allocated its minimum space; 509remaining space is split between the partitions according to the 510given percentages, 511up to their maximum allowed space. 512Space left after all partitions have reached their maximum size 513is left unallocated. 514The sizes below are approximations, 515and may vary from architecture to architecture. 516.Pp 517.Sy Disks \*(Gt 7 Gigabytes 518.Bd -literal -offset indent -compact 519/ 5% of disk. 80M \(en 1G 520swap 5% of disk. 80M \(en 2x max physical memory 521/tmp 8% of disk. 120M \(en 4G 522/var 13% of disk. 80M \(en 2x size of crash dump 523/usr 5% of disk. 900M \(en 2G 524/usr/X11R6 3% of disk. 512M \(en 1G 525/usr/local 10% of disk. 2G \(en 10G 526/usr/src 2% of disk. 1G \(en 2G 527/usr/obj 4% of disk. 1.3G \(en 2G 528/home 45% of disk. 1G \(en 300G 529.Ed 530.Pp 531.Sy Disks \*(Gt 2 Gigabytes 532.Bd -literal -offset indent -compact 533/ 5% of disk. 800M \(en 2G 534swap 10% of disk. 80M \(en 2x max physical memory 535/usr 78% of disk. 900M \(en 3G 536/home 7% of disk. 256M \(en 2G 537.Ed 538.Pp 539.Sy Disks \*(Gt 700 Megabytes 540.Bd -literal -offset indent -compact 541/ 95% of disk. 700M \(en 4G 542swap 5% of disk. 1M \(en 2x max physical memory 543.Ed 544.Pp 545A template for the automatic allocation can be passed to disklabel using 546the 547.Fl T 548option. 549The template consists of one line per partition, with each line giving 550mountpoint, min-max size range, and percentage of disk, space-separated. 551Max can be unlimited by specifying '*'. 552If only mountpoint and min size are given, the partition is created with that 553exact size. 554.Pp 555.Bd -literal -offset indent -compact 556/ 250M 557swap 80-256M 10% 558/tmp 120M-4G 8% 559/var 80M-4G 13% 560/usr 900M-2G 5% 561/usr/X11R6 512M-1G 3% 562/usr/local 2G-10G 10% 563/usr/src 1-2G 2% 564/usr/obj 1.3G-2G 4% 565/home 1G-* 45% 566.Ed 567.Sh FILES 568.Bl -tag -width Pa -compact 569.It Pa /etc/disktab 570Disk description file. 571.It Pa /usr/mdec/ Ns Em xx Ns boot 572Primary bootstrap. 573.It Pa /usr/mdec/boot Ns Em xx 574Secondary bootstrap. 575.El 576.Sh EXAMPLES 577Display the in-core label for sd0 as obtained via 578.Pa /dev/rsd0c : 579.Pp 580.Dl # disklabel sd0 581.Pp 582Create a label for sd0 based on information for 583.Dq sd2212 584found in 585.Pa /etc/disktab . 586Any existing bootstrap code will be clobbered. 587.Pp 588.Dl # disklabel -w /dev/rsd0c sd2212 foo 589.Pp 590Read the on-disk label from a disk with DUID 3eb7f9da875cb9ee, 591edit it and reinstall in-core as well as on-disk. 592Existing bootstrap code is unaffected. 593.Pp 594.Dl # disklabel -E 3eb7f9da875cb9ee 595.Pp 596Restore the on-disk and in-core label for sd0 from information in 597.Pa mylabel . 598Existing bootstrap code is unaffected. 599.Pp 600.Dl # disklabel -R sd0 mylabel 601.Sh DIAGNOSTICS 602The kernel device drivers will not allow the size of a disk partition 603to be decreased or the offset of a partition to be changed while 604it is open. 605Some device drivers create a label containing only a 606single large partition if a disk is unlabeled; thus, the label must 607be written to the 608.Sq a 609partition of the disk while it is open. 610This sometimes requires the desired label to be set in two steps, 611the first one creating at least one other partition, and the second 612setting the label on the new partition while shrinking the 613.Sq a 614partition. 615.Pp 616On some machines the bootstrap code may not fit entirely in the 617area allocated for it by some filesystems. 618As a result, it may 619not be possible to have filesystems on some partitions of a 620.Dq bootable 621disk. 622When installing bootstrap code, 623.Nm 624checks for these cases. 625If the installed boot code would overlap a partition of type 626.Dv FS_UNUSED 627it is marked as type 628.Dv FS_BOOT . 629The 630.Xr newfs 8 631utility will disallow creation of filesystems on 632.Dv FS_BOOT 633partitions. 634Conversely, if a partition has a type other than 635.Dv FS_UNUSED 636or 637.Dv FS_BOOT , 638.Nm 639will not install bootstrap code that overlaps it. 640.Sh SEE ALSO 641.Xr disklabel 5 , 642.Xr disktab 5 , 643.Xr scan_ffs 8 644.Sh CAVEATS 645The maximum disk and partition size is 64PB. 646.Pp 647On some machines, such as Sparc64, partition tables 648may not exhibit the full functionality described above. 649