1.\" $OpenBSD: disklabel.8,v 1.86 2009/07/27 12:39:50 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: July 27 2009 $ 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 c | d | t 45.Op Fl Av 46.Op Fl h | p Ar unit 47.Ar disk 48.Nm disklabel 49.Fl w 50.Op Fl c | d 51.Op Fl Anv 52.Ar disk Ar disktype 53.Op Ar packid 54.Nm disklabel 55.Fl e 56.Op Fl c | d 57.Op Fl Anv 58.Ar disk 59.Nm disklabel 60.Fl E 61.Op Fl c | d 62.Op Fl Anv 63.Op Fl f Ar tempfile 64.Ar disk 65.Nm disklabel 66.Fl R 67.Op Fl nv 68.Ar disk Ar protofile 69.Nm disklabel 70.Fl N | W 71.Op Fl nv 72.Ar disk 73.Pp 74.Nm disklabel 75.Fl B\ \& 76.Op Fl nv 77.Op Fl b Ar boot1 78.Op Fl s Ar boot2 79.Ar disk 80.Op Ar disktype 81.Nm disklabel 82.Fl Bw 83.Op Fl nv 84.Op Fl b Ar boot1 85.Op Fl s Ar boot2 86.Ar disk Ar disktype 87.Op Ar packid 88.Nm disklabel 89.Fl BR 90.Op Fl nv 91.Op Fl b Ar boot1 92.Op Fl s Ar boot2 93.Ar disk Ar protofile 94.Op Ar disktype 95.Sh DESCRIPTION 96The 97.Nm 98utility can be used to install, examine, or modify the label on a disk drive or 99pack. 100The disk label contains information about disk characteristics 101.Pq size, type, etc. 102and the partition layout, stored on the disk itself. 103It is used by the operating system to optimize disk I/O and 104locate the filesystems resident on the disk. 105.Pp 106.Nm 107supports 15 configurable partitions, 108.Sq a 109through 110.Sq p , 111excluding 112.Sq c . 113The 114.Sq c 115partition describes the entire physical disk, is automatically created 116by the kernel, and cannot be modified or deleted by 117.Nm . 118By convention, the 119.Sq a 120partition of the boot disk is the root partition, and the 121.Sq b 122partition of the boot disk is the swap partition, 123but all other letters can be used in any order for any other 124partitions as desired. 125.Pp 126The options are as follows: 127.Bl -tag -width Ds 128.It Fl A 129Automatically allocate all the disk space in the 130.Ox 131portion of the disk in the recommended manner. 132See 133.Sx AUTOMATIC DISK ALLOCATION , 134below. 135.It Fl B 136Install bootstrap code. 137Some architectures instead require bootstrap code installation to be 138done using an 139.Xr installboot 8 140type program, as described in 141.Xr boot 8 . 142.It Fl b Ar boot1 143Specify the single level boot program, or the primary boot program, 144depending on the system boot architecture 145.Pq single or two-level . 146.It Fl c 147Clear the system's in-core copy of the label and update it based on 148the on-disk label. 149.It Fl d 150Use the 151.Em default 152label. 153This ignores any existing 154.Ox 155disk label on the disk. 156.It Fl E 157Use the built-in command-driven label editor described below. 158.It Fl e 159Edit an existing disk label using the editor specified in the 160.Ev EDITOR 161environment variable, or 162.Xr vi 1 163if none is specified. 164.It Fl f Ar tempfile 165Write entries to 166.Ar tempfile 167in 168.Xr fstab 5 169format for any partitions for which mount point information has been 170specified. 171The 172.Fl f 173flag is only valid when used in conjunction with the 174.Fl E 175flag. 176If 177.Ar tempfile 178already exists, it will be overwritten. 179.It Fl h 180Print partition sizes in human readable format. 181.It Fl N 182Disallow writing of the pack label area on the selected disk. 183.It Fl n 184Make no permanent changes to the disklabel 185.Pq useful for debugging purposes . 186.It Fl p Ar unit 187Print partition sizes in 188.Ar unit 189instead of sectors. 190Valid units are b(ytes), c(ylinders), k(ilobytes), m(egabytes), g(igabytes) 191and t(erabytes). 192For operations other than displaying a partition the 193.Ql % 194(percent of total) and 195.Ql & 196(percent of free) units are also accepted. 197.It Fl R 198Restore a disk label that was formatted in a prior operation and 199saved in an 200.Tn ASCII 201file. 202.It Fl s Ar boot2 203On machines with a two-level bootstrap 204.Pq such as i386-based systems , 205specify the secondary boot program. 206.It Fl t 207Format the label as a 208.Xr disktab 5 209entry. 210.It Fl v 211Print additional information during operation 212.Pq verbose mode . 213.It Fl W 214Allow writing of the pack label area on the selected disk. 215.It Fl w 216Write a standard label on the designated drive. 217.It Ar disk 218Specify the 219.Ar disk 220to operate on. 221It can be specified either by its full pathname or an abbreviated disk form. 222In its abbreviated form, the path to the device, the 223.Sq r 224denoting 225.Qq raw device , 226and the partition letter, can all be omitted. 227For example, the first IDE disk can be specified as either 228.Pa /dev/rwd0c , 229.Pa /dev/wd0c , 230or 231.Ar wd0 . 232.It Ar disktype 233Specify a 234.Ar disktype 235entry from the 236.Xr disktab 5 237database. 238.It Ar packid 239Specify a pack identification string for the device 240.Pq see below . 241.It Ar protofile 242Used with the restore option 243.Pq Fl R 244to specify a file to read an ASCII label from. 245.El 246.Pp 247The first form of the command 248.Pq read 249is used to examine the label on the named disk drive. 250It will display all of the parameters associated with the drive 251and its partition layout. 252The kernel's in-core copy of the label is displayed; if 253the disk has no label, or the partition types on the disk are 254incorrect, the kernel may have constructed or modified the label. 255.Pp 256The second form of the command 257.Pq write 258is used to write a standard label on the designated drive. 259The drive parameters and partitions are taken from that file. 260If different disks of the same physical type are 261to have different partitions, it will be necessary to have separate 262disktab entries describing each, or to edit the label after 263installation as described below. 264The optional argument is a pack 265identification string, up to 16 characters long. 266The pack ID must be quoted if it contains blanks. 267The existing label will be updated via the in-core 268copy and any bootstrap code will be unaffected. 269.Pp 270In the third form of the command 271.Pq edit , 272the label is read from the in-core kernel copy 273and then supplied to an editor for changes. 274If no editor is specified in an 275.Ev EDITOR 276environment variable, 277.Xr vi 1 278is used. 279When the editor terminates, the formatted label is reread and 280used to rewrite the disk label. 281Existing bootstrap code is unchanged. 282.Pp 283The built-in label editor 284.Pq fourth form 285provides a simple interactive label editor. 286Some commands or prompts take an optional unit. 287Available units are 288.Sq b 289for bytes, 290.Sq c 291for cylinders, 292.Sq k 293for kilobytes, 294.Sq m 295for megabytes, 296and 297.Sq g 298for gigabytes. 299Quantities will be rounded to the nearest 300cylinder when units are specified for sizes 301.Pq or offsets . 302Commands may be aborted by entering 303.Ql ^D 304.Pq Control-D . 305Entering 306.Ql ^D 307at the main 308.Ql > 309prompt will exit the editor. 310At prompts that request a size, 311.Ql * 312may be entered to indicate the rest of the available space. 313The editor commands are as follows: 314.Bl -tag -width "p [unit] " 315.It Cm ?\& Op Ar command 316Display help message with all available commands. 317A 318.Em command 319may be specified to get more detailed help. 320There is also 321.Pq simple 322context-sensitive help available at most prompts. 323.It Cm A 324Allocate all the disk space in the recommended manner. 325See 326.Sx AUTOMATIC DISK ALLOCATION , 327below. 328.It Cm a Op Ar part 329Add new partition. 330This option adds a new BSD partition. 331If no partition letter is specified 332.Pq a\-p , 333the user will be prompted for one. 334.It Cm b 335Set 336.Ox 337disk boundaries. 338This option tells 339.Nm 340which parts of the disk it is allowed to modify. 341This option is probably only useful for ports with 342.Xr fdisk 8 343partition tables where the ending sector in the MBR is incorrect. 344The user may enter 345.Ql * 346at the 347.Dq Size 348prompt to indicate the entire size of the disk 349.Pq minus the starting sector . 350This is useful for disks larger than 8 gigabytes where the 351fdisk partition table is incapable of storing the real size. 352.It Cm c Op Ar part 353Change the size of an existing partition. 354If no partition is specified, the user will be prompted for one. 355The new size may be 356in terms of the aforementioned units and may also be prefixed with 357.Ql + 358or 359.Ql - 360to change the size by a relative amount. 361.It Cm D 362Sets the disk label to the default values as reported by the kernel. 363This simulates the case where there is no disk label. 364.It Cm d Op Ar part 365Delete an existing partition (or 366.Ql * 367to delete all partitions). 368If no partition is specified, the user will be prompted for one. 369.It Cm e 370Edit drive parameters. 371This option is used to set the following parameters: 372disk type, a descriptive label string, sectors/track, 373tracks/cylinder, sectors/cylinder, number of cylinders, 374total sectors, rpm, and interleave. 375.It Xo 376.Cm g 377.Op Ar d | u 378.Xc 379Set disk geometry based on what the 380.Em disk 381or 382.Em user 383thinks (the 384.Em user 385geometry is simply what the label said before 386.Nm 387made any changes). 388.It Cm l Op Ar unit 389Print the disk label header. 390.It Cm M 391Display this manual page. 392.It Cm m Op Ar part 393Modify parameters for an existing partition. 394If no partition is specified, the user will be prompted for one. 395This option allows 396the user to change the filesystem type, starting offset, partition size, 397and mount point for the specified partition. 398If expert mode is enabled (see 399.Cm X 400below), then block fragment size, block size, and cylinders per group 401can also be modified. 402Note that not all parameters are configurable for non-BSD partitions. 403.It Cm n Op Ar part 404Name the mount point for an existing partition. 405If no partition is specified, the user will be prompted for one. 406This option is only valid if 407.Nm 408was invoked with the 409.Fl f 410flag. 411.It Cm p Op Ar unit 412Print the current partition list. 413If a 414.Em unit 415is given, the size and offsets are displayed in terms of the 416specified unit. 417If the unit is 418.Sq * 419it is automatically determined by the size of the smallest 420partition. 421.It Cm q 422Quit the editor. 423If any changes have been made, the user will be 424asked whether or not to save the changes to the on-disk label. 425.It Cm r 426Recalculate free space. 427This command displays all the free areas on the disk and the total 428number of free sectors. 429.It Cm s Op Ar path 430Save the label to a file in 431.Tn ASCII 432format (suitable for loading via the 433.Fl R 434option). 435If no path is specified, the user will be prompted for one. 436.It Cm U 437Undo all changes made since entering the editor. 438.It Cm u 439Undo 440.Pq or redo 441last change. 442Entering 443.Em u 444once will undo the last change. 445Entering it again will restore the change. 446.It Cm w 447Write the label to disk. 448This option will commit any changes to the on-disk label. 449.It Cm X 450Toggle 451.Dq expert mode . 452By default, some settings are reserved for experts only 453(such as the block and fragment size on ffs partitions). 454.It Cm x 455Exit the editor without saving any changes to the label. 456.It Cm z 457Zero out the existing partition table and mountpoint information. 458The drive parameters are not changed. 459.El 460.Pp 461In the restore form of the command 462.Pq fifth form , 463the prototype file used to create the label should be in the same format 464as that produced when reading or editing a label. 465Comments are delimited by 466.Ar # 467and newline. 468Any existing bootstrap code will be unaffected. 469.Pp 470The sixth form of the command 471.Pq protect 472is used to control write access to the label area of a disk 473so that the label cannot be inadvertently overwritten. 474The 475.Fl N 476and 477.Fl W 478options are only available on architectures that support this feature, 479such as vax, hp300 and some sparc models. 480.Pp 481The final three forms of 482.Nm 483are used to install bootstrap code on machines where the bootstrap is 484part of the label. 485The bootstrap code is comprised of one or two boot programs, 486depending on the machine. 487.Pp 488When installing bootstrap code with the 489.Fl B 490flag, if the names are not explicitly given, standard boot programs 491will be used. 492The boot programs are located in 493.Pa /usr/mdec . 494The names of the programs are taken from the 495.Dq b0 496and 497.Dq b1 498parameters of the 499.Xr disktab 5 500entry for the disk if 501.Ar disktype 502was given and its disktab entry exists and includes those parameters. 503Otherwise, boot program names are derived from the name of the 504disk. 505These names are of the form 506.Pa basename Ns boot 507for the primary 508.Pq or only 509bootstrap, and 510.Pf boot Pa basename 511for the secondary bootstrap; for example, 512.Pa /usr/mdec/sdboot 513and 514.Pa /usr/mdec/bootsd 515if the disk device is 516.Em sd0 . 517.Pp 518The first of the three boot-installation forms is used to install 519bootstrap code without changing the existing label. 520It is essentially a read command with respect to the disk label itself 521and all options are related to the specification of the boot program 522as described previously. 523The final two forms are analogous to the basic write and restore versions 524except that they will install bootstrap code in addition to a new label. 525.Pp 526Note that when a disk has no real BSD disklabel, the kernel creates a 527default label so that the disk can be used. 528This default label will include other partitions found on the disk if 529they are supported on your architecture. 530For example, on systems that support 531.Xr fdisk 8 532partitions the default label will also include DOS and Linux partitions. 533However, these entries are not dynamic, they are fixed at the time 534.Nm 535is run. 536That means that subsequent changes that affect non-OpenBSD 537partitions will not be present in the default label, 538though they may be updated by hand. 539To see the default label, run 540.Nm 541with the 542.Fl d 543flag. 544.Nm 545can then be run with the 546.Fl e 547flag and any entries pasted as desired from the default label into the real one. 548.Sh AUTOMATIC DISK ALLOCATION 549The 550.Fl A 551option and the editor command 552.Cm A 553automatically create a disklabel with a set of partitions 554suitable for a majority of 555.Ox 556installations. 557Any existing 558.Ox 559disklabel on the disk is ignored, but native partitions 560that would normally be spoofed are preserved in the disklabel, 561and are not modified during the allocation process. 562.Pp 563Disk size determines the set of partitions which are created. 564Each partition is allocated space between a specified minimum 565and maximum. 566Each partition is allocated its minimum and remaining space 567is split between the partitions up to their maximum allowed space, 568which is a fixed percentage. 569Space left after all partitions have reached their maximum size 570is left unallocated. 571The sizes below are approximations, 572and may vary from architecture to architecture. 573.Pp 574.Sy Disks \*(Gt 6.5 Gigabytes 575.Bd -literal -offset indent -compact 576/ 5% of disk. 80M \(en 1G 577swap 5% of disk. 80M \(en 2x max physical memory 578/tmp 8% of disk. 120M \(en 4G 579/var 13% of disk. 80M \(en 2x size of crash dump 580/usr 2% of disk. 600M \(en 2G 581/usr/X11R6 3% of disk. 512M \(en 1G 582/usr/local 5% of disk. 2G \(en 6G 583/usr/src 3% of disk. 1G \(en 2G 584/usr/obj 3% of disk. 1G \(en 2G 585/home 53% of disk. 1G \(en 300G 586.Ed 587.Pp 588.Sy Disks \*(Gt 2 Gigabytes 589.Bd -literal -offset indent -compact 590/ 5% of disk. 800M \(en 2G 591swap 10% of disk. 80M \(en 2x max physical memory 592/usr 78% of disk. 900M \(en 3G 593/home 7% of disk. 256M \(en 2G 594.Ed 595.Pp 596.Sy Disks \*(Gt 700 Megabytes 597.Bd -literal -offset indent -compact 598/ 95% of disk. 700M \(en 4G 599swap 5% of disk. 1M \(en 2x max physical memory 600.Ed 601.Sh FILES 602.Bl -tag -width Pa -compact 603.It Pa /etc/disklabels 604Directory for backup labels. 605.It Pa /etc/disktab 606Disk description file. 607.It Pa /usr/mdec/ Ns Em xx Ns boot 608Primary bootstrap. 609.It Pa /usr/mdec/boot Ns Em xx 610Secondary bootstrap. 611.El 612.Sh EXAMPLES 613Display the in-core label for sd0 as obtained via 614.Pa /dev/rsd0c : 615.Pp 616.Dl # disklabel sd0 617.Pp 618Create a label for sd0 based on information for 619.Dq sd2212 620found in 621.Pa /etc/disktab . 622Any existing bootstrap code will be clobbered. 623.Pp 624.Dl # disklabel -w /dev/rsd0c sd2212 foo 625.Pp 626Read the on-disk label for sd0, edit it and reinstall in-core as 627well as on-disk. 628Existing bootstrap code is unaffected. 629.Pp 630.Dl # disklabel -e sd0 631.Pp 632Restore the on-disk and in-core label for sd0 from information in 633.Pa mylabel . 634Existing bootstrap code is unaffected. 635.Pp 636.Dl # disklabel -R sd0 mylabel 637.Pp 638Install a new bootstrap on sd0. 639The boot code comes from 640.Pa /usr/mdec/sdboot 641and possibly 642.Pa /usr/mdec/bootsd . 643On-disk and in-core labels are unchanged, but on some systems other 644information may be destroyed. 645Use with care. 646.Pp 647.Dl # disklabel -B sd0 648.Pp 649Install a new label and bootstrap. 650The label is derived from disktab information for 651.Dq sd2212 652and installed both in-core and 653on-disk. 654The bootstrap code comes from the file 655.Pa /usr/mdec/newboot . 656.Pp 657.Dl # disklabel -w -B /dev/rsd0c -b newboot sd2212 658.Sh DIAGNOSTICS 659The kernel device drivers will not allow the size of a disk partition 660to be decreased or the offset of a partition to be changed while 661it is open. 662Some device drivers create a label containing only a 663single large partition if a disk is unlabeled; thus, the label must 664be written to the 665.Sq a 666partition of the disk while it is open. 667This sometimes requires the desired label to be set in two steps, 668the first one creating at least one other partition, and the second 669setting the label on the new partition while shrinking the 670.Sq a 671partition. 672.Pp 673On some machines the bootstrap code may not fit entirely in the 674area allocated for it by some filesystems. 675As a result, it may 676not be possible to have filesystems on some partitions of a 677.Dq bootable 678disk. 679When installing bootstrap code, 680.Nm 681checks for these cases. 682If the installed boot code would overlap a partition of type 683.Dv FS_UNUSED 684it is marked as type 685.Dv FS_BOOT . 686The 687.Xr newfs 8 688utility will disallow creation of filesystems on 689.Dv FS_BOOT 690partitions. 691Conversely, if a partition has a type other than 692.Dv FS_UNUSED 693or 694.Dv FS_BOOT , 695.Nm 696will not install bootstrap code that overlaps it. 697.Sh SEE ALSO 698.Xr disklabel 5 , 699.Xr disktab 5 , 700.Xr scan_ffs 8 701.Sh CAVEATS 702The maximum disk and partition size is 64PB. 703.Pp 704On some machines, such as Sparc and Sparc64, partition tables 705may not exhibit the full functionality described above. 706