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