1.\" $OpenBSD: disklabel.8,v 1.144 2021/11/10 20:15:26 otto 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: November 10 2021 $ 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 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 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). 160.It Fl R 161Restore a disk label that was formatted in a prior operation and 162saved in an ASCII file. 163.It Fl T Ar file 164Read the template for automatic allocation from 165.Ar file 166instead of using the builtin one. 167See 168.Sx AUTOMATIC DISK ALLOCATION 169below for the format. 170.It Fl t 171Format the label as a 172.Xr disktab 5 173entry. 174.It Fl v 175Print additional information during operation 176.Pq verbose mode . 177.It Fl w 178Write a standard label on the designated drive. 179.It Ar disk 180Specify the 181.Ar disk 182to operate on. 183It can be specified by its full pathname, by an abbreviated disk form, 184or by its disklabel UID. 185In its abbreviated form, the path to the device, the 186.Sq r 187denoting 188.Qq raw device , 189and the partition letter, can all be omitted. 190For example, the first IDE disk can be specified as either 191.Pa /dev/rwd0c , 192.Pa /dev/wd0c , 193or 194.Ar wd0 . 195.It Ar disktype 196Specify a 197.Ar disktype 198entry from the 199.Xr disktab 5 200database. 201.It Ar packid 202Specify a pack identification string for the device 203.Pq see below . 204.It Ar protofile 205Used with the restore option 206.Pq Fl R 207to specify a file to read an ASCII label from. 208.El 209.Pp 210The first form of the command 211.Pq read 212is used to examine the label on the named disk drive. 213It will display all of the parameters associated with the drive 214and its partition layout. 215The kernel's in-core copy of the label is displayed; if 216the disk has no label, or the partition types on the disk are 217incorrect, the kernel may have constructed or modified the label. 218.Pp 219The second form of the command 220.Pq write 221is used to write a standard label on the designated drive. 222The drive parameters and partitions are taken from that file. 223If different disks of the same physical type are 224to have different partitions, it will be necessary to have separate 225disktab entries describing each, or to edit the label after 226installation as described below. 227The optional argument is a pack 228identification string, up to 16 characters long. 229The pack ID must be quoted if it contains blanks. 230The existing label will be updated via the in-core 231copy. 232.Pp 233In the third form of the command 234.Pq edit , 235the label is read from the in-core kernel copy 236and then supplied to an editor for changes. 237If no editor is specified in an 238.Ev EDITOR 239environment variable, 240.Xr vi 1 241is used. 242When the editor terminates, the formatted label is reread and 243used to rewrite the disk label. 244.Pp 245The built-in label editor 246.Pq fourth form 247provides a simple interactive label editor. 248The editor prompt contains information about the state of the edit 249process. 250.Pp 251.Dl Ar disk Ns *> 252.Pp 253Where 254.Ar disk 255is the name of the disk being edited, 256.Sq * 257means that the in-memory copy of the partition table has been modified but 258not yet written to disk and the 259.Sq > 260is replaced by 261.Sq # 262when the editor is in expert mode. 263.Pp 264Some commands or prompts take an optional unit. 265Available units are 266.Sq b 267for bytes, 268.Sq c 269for cylinders, 270.Sq k 271for kilobytes, 272.Sq m 273for megabytes, 274.Sq g 275for gigabytes, 276and 277.Sq t 278for terabytes. 279If no unit is given, the default is to use sectors 280(usually 512 bytes). 281.Pp 282Quantities are rounded to the nearest 283cylinder when units are specified for sizes 284.Pq or offsets . 285At prompts that request a size, 286.Ql * 287may be entered to indicate the rest of the available space, 288.Sq % 289for percentage of total, and 290.Sq & 291for percentage free. 292Commands may be aborted by entering 293.Ql ^D 294.Pq Control-D . 295Entering 296.Ql ^D 297at the main prompt will exit the editor. 298.Pp 299The editor commands are as follows: 300.Bl -tag -width "p [unit] " 301.It Cm \&? | h 302Display help message with all available commands. 303There is also 304.Pq simple 305context-sensitive help available at most prompts. 306.It Cm A 307Allocate all the disk space in the recommended manner. 308See 309.Sx AUTOMATIC DISK ALLOCATION , 310below. 311.It Cm a Op Ar part 312Add new partition. 313This option adds a new partition to the disk label. 314If no partition letter is specified 315.Pq a\-p , 316the user will be prompted for one. 317.It Cm b 318Set 319.Ox 320disk boundaries. 321This option tells 322.Nm 323which parts of the disk it is allowed to modify. 324This option is probably only useful for ports with 325.Xr fdisk 8 326partition tables where the ending sector in the MBR is incorrect. 327The user may enter 328.Ql * 329at the 330.Dq Size 331prompt to indicate the entire size of the disk 332.Pq minus the starting sector . 333This is useful for disks where the 334fdisk partition table is incapable of storing the real size. 335Note: data may become corrupted if boundaries are extended such 336that they overlap with other resident operating systems. 337.It Cm c Op Ar part 338Change the size of an existing partition. 339If no partition is specified, the user will be prompted for one. 340The new size may be 341in terms of the aforementioned units and may also be prefixed with 342.Ql + 343or 344.Ql - 345to change the size by a relative amount. 346.It Cm D 347Sets the disk label to the default values as reported by the kernel. 348This simulates the case where there is no disk label. 349.It Cm d Op Ar part 350Delete an existing partition (or 351.Ql * 352to delete all partitions). 353If no partition is specified, the user will be prompted for one. 354.It Cm e 355Edit drive parameters. 356This option is used to set the following parameters: 357disk type, a descriptive label string, sectors/track, 358tracks/cylinder, sectors/cylinder, number of cylinders, 359total sectors, rpm, and interleave. 360.It Xo 361.Cm g 362.Op Ar d | u 363.Xc 364Set disk geometry based on what the 365.Em disk 366or 367.Em user 368thinks (the 369.Em user 370geometry is simply what the label said before 371.Nm 372made any changes). 373.It Cm i 374Change the disklabel UID, specified as a 16-character hexadecimal string. 375If set to all zeros, a new UID will automatically be allocated when the 376disklabel is written to disk. 377.It Cm l Op Ar unit 378Print the disk label header. 379.It Cm M 380Display this manual page. 381The manual page is piped through the pager specified by the 382.Ev PAGER 383environment variable or 'less' if 384.Ev PAGER 385is not set. 386.It Cm m Op Ar part 387Modify parameters for an existing partition. 388If no partition is specified, the user will be prompted for one. 389This option allows 390the user to change the filesystem type, starting offset, partition size, 391and mount point for the specified partition. 392If expert mode is enabled (see 393.Cm X 394below), then block fragment size, block size, and cylinders per group 395can also be modified. 396Note that not all parameters are configurable for 397.Pf non- Bx 398partitions. 399.It Cm n Op Ar part 400Name the mount point for an existing partition. 401If no partition is specified, the user will be prompted for one. 402This option is only valid if 403.Nm 404was invoked with the 405.Fl f 406flag. 407.It Cm p Op Ar unit 408Print the current partition list. 409If a 410.Em unit 411is given, the size and offsets are displayed in terms of the 412specified unit. 413If the unit is 414.Sq * 415it is automatically determined by the size of the smallest 416partition. 417.It Cm q 418Quit the editor. 419If any changes have been made, the user will be 420asked whether or not to save the changes to the on-disk label. 421.It Cm R Op Ar part 422Resize a partition in an automatically allocated label, 423compacting unused space between partitions with a higher offset. 424The last partition will be shrunk if necessary. 425Works only for automatically allocated labels with no spoofed partitions. 426.It Cm r 427Recalculate free space. 428This command displays all the free areas on the disk and the total 429number of free sectors. 430.It Cm s Op Ar path 431Save the label to a file in ASCII format (suitable for loading via the 432.Fl R 433option). 434If no path is specified, the user will be prompted for one. 435.It Cm U 436Undo all changes made since entering the editor. 437.It Cm u 438Undo 439.Pq or redo 440last change. 441Entering 442.Em u 443once will undo the last change. 444Entering it again will restore the change. 445.It Cm w 446Write the label to disk. 447This option will commit any changes to the on-disk label. 448.It Cm X 449Toggle 450.Dq expert mode . 451By default, some settings are reserved for experts only 452(such as the block and fragment size on ffs partitions). 453While in expert mode the command line prompt will end 454with 455.Ql # 456instead of 457.Ql > . 458.It Cm x 459Exit the editor without saving any changes to the on-disk label. 460.It Cm z 461Zero out the existing partition table and mount point information, 462leaving only the 'c' partition. 463The drive parameters are not changed. 464.El 465.Pp 466In the restore form of the command 467.Pq fifth form , 468the prototype file used to create the label should be in the same format 469as that produced when reading or editing a label. 470Comments are delimited by 471.Ar # 472and newline. 473.Pp 474Note that when a disk has no real 475.Bx 476disklabel, the kernel creates a 477default label so that the disk can be used. 478This default label will include other partitions found on the disk if 479they are supported on your architecture. 480For example, on systems that support 481.Xr fdisk 8 482partitions the default label will also include DOS and Linux partitions. 483However, these entries are not dynamic, they are fixed at the time 484.Nm 485is run. 486That means that subsequent changes that affect 487.Pf non- Ox 488partitions will not be present in the default label, 489though they may be updated by hand. 490To see the default label, run 491.Nm 492with the 493.Fl d 494flag. 495.Nm 496can then be run with the 497.Fl e 498flag and any entries pasted as desired from the default label into the real one. 499.Sh AUTOMATIC DISK ALLOCATION 500The 501.Fl A 502option and the editor command 503.Cm A 504automatically create a disklabel with a set of partitions 505suitable for a majority of 506.Ox 507installations. 508Any existing 509.Ox 510disklabel on the disk is ignored, but native partitions 511that would normally be spoofed are preserved in the disklabel, 512and are not modified during the allocation process. 513.Pp 514Disk size determines the set of partitions which are created. 515Each partition is allocated space between a specified minimum 516and maximum. 517Initially, each partition is allocated its minimum space; 518remaining space is split between the partitions according to the 519given percentages, 520up to their maximum allowed space. 521Space left after all partitions have reached their maximum size 522is left unallocated. 523The sizes below are approximations, 524and may vary from architecture to architecture. 525.Pp 526.Sy Disks >= 10 Gigabytes 527.Bd -literal -offset indent -compact 528/ 5% of disk. 150M \(en 1G 529swap 10% of disk. 80M \(en 2x max physical memory 530/tmp 8% of disk. 120M \(en 4G 531/var 13% of disk. 80M \(en 4G + 2x size of crash dump 532/usr 10% of disk. 1500M \(en 6G 533/usr/X11R6 3% of disk. 384M \(en 1G 534/usr/local 15% of disk. 1G \(en 20G 535/usr/src 2% of disk. 1500M \(en 3G 536/usr/obj 4% of disk. 5G \(en 6G 537/home 30% of disk. 1G \(en 300G 538.Ed 539.Pp 540.Sy Disks > 2.5 Gigabytes 541.Bd -literal -offset indent -compact 542/ 5% of disk. 800M \(en 2G 543swap 10% of disk. 80M \(en 2x max physical memory 544/usr 78% of disk. 1300M \(en 3G 545/home 7% of disk. 256M \(en 2G 546.Ed 547.Pp 548.Sy Disks > 700 Megabytes 549.Bd -literal -offset indent -compact 550/ 95% of disk. 700M \(en 4G 551swap 5% of disk. 1M \(en 2x max physical memory 552.Ed 553.Pp 554A template for the automatic allocation can be passed to disklabel using 555the 556.Fl T 557option. 558The template consists of one line per partition, with each line giving 559mount point, min-max size range, and percentage of disk, space-separated. 560Max can be unlimited by specifying '*'. 561If only mount point and min size are given, the partition is created with that 562exact size. 563.Bd -literal -offset indent 564/ 250M 565swap 80M-256M 10% 566/tmp 120M-4G 8% 567/var 80M-4G 13% 568/usr 1.5G-3G 5% 569/usr/X11R6 512M-1G 3% 570/usr/local 2G-10G 10% 571/usr/src 1.5G-3G 2% 572/usr/obj 1.3G-2G 4% 573/home 1G-* 45% 574.Ed 575.Sh FILES 576.Bl -tag -width Pa -compact 577.It Pa /etc/disktab 578Disk description file. 579.El 580.Sh EXAMPLES 581Display the in-core label for sd0 as obtained via 582.Pa /dev/rsd0c : 583.Pp 584.Dl # disklabel sd0 585.Pp 586Create a label for sd0 based on information for 587.Dq sd2212 588found in 589.Pa /etc/disktab : 590.Pp 591.Dl # disklabel -w /dev/rsd0c sd2212 foo 592.Pp 593Read the on-disk label from a disk with DUID 3eb7f9da875cb9ee, 594edit it and reinstall in-core as well as on-disk: 595.Pp 596.Dl # disklabel -E 3eb7f9da875cb9ee 597.Pp 598Restore the on-disk and in-core label for sd0 from information in 599.Pa mylabel : 600.Pp 601.Dl # disklabel -R sd0 mylabel 602.Sh DIAGNOSTICS 603The kernel device drivers will not allow the size of a disk partition 604to be decreased or the offset of a partition to be changed while 605it is open. 606Some device drivers create a label containing only a 607single large partition if a disk is unlabeled; thus, the label must 608be written to the 609.Sq a 610partition of the disk while it is open. 611This sometimes requires the desired label to be set in two steps, 612the first one creating at least one other partition, and the second 613setting the label on the new partition while shrinking the 614.Sq a 615partition. 616.Sh SEE ALSO 617.Xr disklabel 5 , 618.Xr disktab 5 , 619.Xr installboot 8 , 620.Xr scan_ffs 8 621.Sh CAVEATS 622The maximum disk and partition size is 64PB. 623.Pp 624On some machines, such as Sparc64, partition tables 625may not exhibit the full functionality described above. 626