1.\" $MirOS: src/sbin/disklabel/disklabel.8,v 1.3 2005/04/29 18:34:53 tg Exp $ 2.\" $OpenBSD: disklabel.8,v 1.59 2005/03/07 23:41:53 jmc Exp $ 3.\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $ 4.\" 5.\" Copyright (c) 1987, 1988, 1991, 1993 6.\" The Regents of the University of California. All rights reserved. 7.\" 8.\" This code is derived from software contributed to Berkeley by 9.\" Symmetric Computer Systems. 10.\" 11.\" Redistribution and use in source and binary forms, with or without 12.\" modification, are permitted provided that the following conditions 13.\" are met: 14.\" 1. Redistributions of source code must retain the above copyright 15.\" notice, this list of conditions and the following disclaimer. 16.\" 2. Redistributions in binary form must reproduce the above copyright 17.\" notice, this list of conditions and the following disclaimer in the 18.\" documentation and/or other materials provided with the distribution. 19.\" 3. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 36.\" 37.Dd October 27, 1997 38.Dt DISKLABEL 8 39.Os 40.Sh NAME 41.Nm disklabel 42.Nd read and write disk pack label 43.Sh SYNOPSIS 44.Nm disklabel 45.Op Fl c | d | r | t 46.Op Fl v 47.Op Fl p Ar unit 48.Ar disk 49.Nm disklabel 50.Fl w 51.Op Fl c | d | r 52.Op Fl nv 53.Ar disk Ar disktype 54.Op Ar packid 55.Nm disklabel 56.Fl e 57.Op Fl c | d | r 58.Op Fl nv 59.Ar disk 60.Nm disklabel 61.Fl E 62.Op Fl c | d | r 63.Op Fl nv 64.Op Fl f Ar tempfile 65.Ar disk 66.Nm disklabel 67.Fl R 68.Op Fl nrv 69.Ar disk Ar protofile 70.Nm disklabel 71.Fl N | W 72.Op Fl nv 73.Ar disk 74.Pp 75.Nm disklabel 76.Fl B\ \& 77.Op Fl nv 78.Op Fl b Ar boot1 79.Op Fl s Ar boot2 80.Ar disk 81.Op Ar disktype 82.Nm disklabel 83.Fl Bw 84.Op Fl nv 85.Op Fl b Ar boot1 86.Op Fl s Ar boot2 87.Ar disk Ar disktype 88.Op Ar packid 89.Nm disklabel 90.Fl BR 91.Op Fl nv 92.Op Fl b Ar boot1 93.Op Fl s Ar boot2 94.Ar disk Ar protofile 95.Op Ar disktype 96.Sh DESCRIPTION 97The 98.Nm 99utility can be used to install, examine, or modify the label on a disk drive or 100pack. 101The disk label contains information about disk characteristics 102.Pq size, type, etc. 103and the slice layout, stored on the disk itself. 104It is used by the operating system to optimize disk I/O and 105locate the filesystems resident on the disk. 106.Pp 107The options are as follows: 108.Bl -tag -width Ds 109.It Fl B 110Install bootstrap code. 111The 112.Fl r 113flag is implied by 114.Fl B 115and never needs to be specified. 116.It Fl b 117Specify the single level boot program, or the primary boot program, 118depending on the system boot architecture 119.Pq single or two-level . 120.It Fl c 121Clear the system's in-core copy of the label and update it based on 122the on-disk label. 123May not be used in conjunction with the 124.Fl r 125flag. 126.It Fl d 127Use the 128.Em default 129label. 130This ignores any existing 131.Mx 132slices on the disk. 133Note that this option will only work for disks 134that are capable of reporting their geometry, such as SCSI, IDE, and ESDI. 135May not be used in conjunction with the 136.Fl r 137flag. 138.It Fl E 139Use a simple initial label editor, using the command-driven built-in 140editor described below. 141.It Fl e 142Edit an existing disk label using the editor specified in the 143.Ev EDITOR 144environment variable, or 145.Xr vi 1 146if none is specified. 147.It Fl f Ar tempfile 148Write entries to 149.Ar tempfile 150in 151.Xr fstab 5 152format for any slices for which mount point information has been 153specified. 154The 155.Fl f 156flag is only valid when used in conjunction with the 157.Fl E 158flag. 159If 160.Ar tempfile 161already exists, it will be overwritten. 162.It Fl N 163Disallow writing of the pack label area on the selected disk. 164.It Fl n 165Make no permanent changes to the disklabel 166.Pq useful for debugging purposes . 167.It Fl p Ar unit 168Print slice sizes and offsets in 169.Ar unit 170instead of sectors. 171Valid units are b(ytes), c(ylinders), k(ilobytes), m(egabytes) and g(igabytes). 172For operations other than displaying a slice the 173.Ql % 174(percent of total) and 175.Ql & 176(percent of free) units are also accepted. 177.It Fl R 178Restore a disk label that was formatted in a prior operation and 179saved in an 180.Tn ASCII 181file. 182.It Fl r 183Causes the label to be read from or written to the disk directly, 184rather than going through the system's in-core copy of the label. 185This option may allow a label to be installed on a disk without kernel 186support for a label, such as when labels are first installed on a 187system. 188This flag does not work on a number of architectures, thus it is 189not considered the right way to put a new label on a disk. 190Its use is discouraged. 191.It Fl s 192On machines with a two-level bootstrap 193.Pq such as i386-based systems , 194specify the secondary boot program. 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 203Allow writing of the pack label area on the selected disk. 204.It Fl w 205Write a standard label on the designated drive. 206.It Ar disk 207Specify the 208.Ar disk 209to operate on. 210It can be specified either by its full pathname or an abbreviated disk form. 211In its abbreviated form, the path to the device, the 212.Sq r 213denoting 214.Qq raw device , 215and the slice, can all be omitted. 216For example, the first IDE disk can be specified as either 217.Pa /dev/rwd0c , 218.Pa /dev/wd0c , 219or 220.Ar wd0 . 221.It Ar disktype 222Specify a 223.Ar disktype 224entry from the 225.Xr disktab 5 226database. 227.It Ar packid 228Specify a pack identification string for the device 229.Pq see below . 230.It Ar protofile 231Used with the restore option 232.Pq Fl R 233to specify a file to read an ASCII label from. 234.El 235.Pp 236The first form of the command 237.Pq read 238is used to examine the label on the named disk drive. 239It will display all of the parameters associated with the drive 240and its slice layout. 241Unless the 242.Fl r 243flag is given, the kernel's in-core copy of the label is displayed; if 244the disk has no label, or the slice types on the disk are 245incorrect, the kernel may have constructed or modified the label. 246.Pp 247The second form of the command 248.Pq write 249is used to write a standard label on the designated drive. 250The drive parameters and slices are taken from that file. 251If different disks of the same physical type are 252to have different slices, it will be necessary to have separate 253disktab entries describing each, or to edit the label after 254installation as described below. 255The optional argument is a pack 256identification string, up to 16 characters long. 257The pack ID must be quoted if it contains blanks. 258If the 259.Fl r 260flag is given, the disk sectors containing the label and bootstrap 261will be written directly. 262A side-effect of this is that any existing 263bootstrap code will be overwritten and the disk rendered unbootable. 264If 265.Fl r 266is not specified, the existing label will be updated via the in-core 267copy and any bootstrap code will be unaffected. 268If the disk does not already have a label, the 269.Fl r 270flag must be used. 271In either case, the kernel's in-core label is replaced. 272.Pp 273In the third form of the command 274.Pq edit , 275the label is read from the in-core kernel copy, or directly from the disk if the 276.Fl r 277flag is also given. 278The label is formatted and then supplied to an editor for changes. 279If no editor is specified in an 280.Ev EDITOR 281environment variable, 282.Xr vi 1 283is used. 284When the editor terminates, the formatted label is reread and 285used to rewrite the disk label. 286Existing bootstrap code is unchanged regardless of whether 287.Fl r 288was specified. 289.Pp 290The initial label editor mode 291.Pq fourth form 292is only intended for new disks as it will move slices around as necessary 293to maintain a contiguous pool of free blocks. 294Some commands or prompts take an optional unit. 295Available units are 296.Sq b 297for bytes, 298.Sq c 299for cylinders, 300.Sq k 301for kilobytes, 302.Sq m 303for megabytes, 304and 305.Sq g 306for gigabytes. 307Quantities will be rounded to the nearest 308cylinder when units are specified for sizes 309.Pq or offsets . 310Commands may be aborted by entering 311.Ql ^D 312.Pq Control-D . 313Entering 314.Ql ^D 315at the main 316.Ql > 317prompt will exit the editor. 318At prompts that request a size, 319.Ql * 320may be entered to indicate the rest of the available space. 321The editor commands are as follows: 322.Bl -tag -width "p [unit] " 323.It Cm \&? Op Ar command 324Display help message with all available commands. 325A 326.Em command 327may be specified to get more detailed help. 328There is also 329.Pq simple 330context-sensitive help available at most prompts. 331.It Cm a Op Ar part 332Add new slice. 333This option adds a new BSD slice. 334If no letter is specified 335.Pq a\-p , 336the user will be prompted for one. 337.It Cm b 338Set 339.Mx 340disk boundaries. 341This option tells 342.Nm 343which parts of the disk it is allowed to modify. 344This option is probably only useful for ports with 345.Xr fdisk 8 346partition tables where the ending sector in the MBR is incorrect. 347The user may enter 348.Ql * 349at the 350.Dq Size 351prompt to indicate the entire size of the disk 352.Pq minus the starting sector . 353This is useful for disks larger than 8 gigabytes where the 354fdisk partition table is incapable of storing the real size. 355.It Cm c Op Ar part 356Change the size of an existing slice. 357If no slice is specified, the user will be prompted for one. 358The new size may be 359in terms of the aforementioned units and may also be prefixed with 360.Ql + 361or 362.Ql - 363to change the size by a relative amount. 364.It Cm D 365Sets the disk label to the default values as reported by the kernel. 366This simulates the case where there is no disk label. 367.It Cm d Op Ar part 368Delete an existing slice (or 369.Ql * 370to delete all slices). 371If no slice is specified, the user will be prompted for one. 372The 373.Ql c 374slice cannot be deleted. 375.It Cm e 376Edit drive parameters. 377This option is used to set the following parameters: 378disk type, a descriptive label string, sectors/track, 379tracks/cylinder, sectors/cylinder, number of cylinders, 380total sectors, rpm, and interleave. 381.It Xo 382.Cm g 383.Sm off 384.Op Ar b | d | u 385.Sm on 386.Xc 387Set disk geometry based on what the 388.Em BIOS , 389.Em disk , 390or 391.Em user 392thinks (the 393.Em user 394geometry is simply what the label said before 395.Nm 396made any changes). 397.It Cm M 398Display this manual page. 399.It Cm m Op Ar part 400Modify parameters for an existing slice. 401If no slice is specified, the user will be prompted for one. 402This option allows 403the user to change the filesystem type, starting offset, size, 404and mount point for the specified slice. 405If expert mode is enabled (see 406.Cm X 407below), then block fragment size, block size, and cylinders per group 408can also be modified. 409Note that not all parameters are configurable for non-BSD slices. 410.It Cm n Op Ar part 411Name the mount point for an existing slice. 412If no slice is specified, the user will be prompted for one. 413This option is only valid if 414.Nm 415was invoked with the 416.Fl f 417flag. 418.It Cm p Op Ar unit 419Print the current disk label. 420If a 421.Em unit 422is given, the size and offsets are displayed in terms of the 423specified unit. 424.It Cm q 425Quit the editor. 426If any changes have been made, the user will be 427asked whether or not to save the changes to the on-disk label. 428.It Cm r 429Recalculate free space. 430This option should really not be necessary under normal circumstances. 431.It Cm s Op Ar path 432Save the label to a file in 433.Tn ASCII 434format (suitable for loading via the 435.Fl R 436option). 437If no path is specified, the user will be prompted for one. 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 filesystems). 454.It Cm x 455Exit the editor without saving any changes to the label. 456.It Cm z 457Zeroes out the existing disklabel, leaving only the 458.Sq c 459slice. 460The drive parameters are not changed. 461.El 462.Pp 463In the restore form of the command 464.Pq fifth form , 465the prototype file used to create the label should be in the same format 466as that produced when reading or editing a label. 467Comments are delimited by 468.Ar # 469and newline. 470As with 471.Fl w , 472any existing bootstrap code will be clobbered if 473.Fl r 474is specified and will be unaffected otherwise. 475.Pp 476The sixth form of the command 477.Pq protect 478is used to control write access to the label area of a disk 479so that the label cannot be inadvertently overwritten. 480The 481.Fl N 482and 483.Fl W 484options are only available on architectures that support this feature, 485such as vax, hp300 and some sparc models. 486.Pp 487The final three forms of 488.Nm 489are used to install bootstrap code on machines where the bootstrap is 490part of the label. 491The bootstrap code is comprised of one or two boot programs, 492depending on the machine. 493.Pp 494When installing bootstrap code with the 495.Fl B 496flag, if the names are not explicitly given, standard boot programs 497will be used. 498The boot programs are located in 499.Pa /usr/mdec . 500The names of the programs are taken from the 501.Dq b0 502and 503.Dq b1 504parameters of the 505.Xr disktab 5 506entry for the disk if 507.Ar disktype 508was given and its disktab entry exists and includes those parameters. 509Otherwise, boot program names are derived from the name of the 510disk. 511These names are of the form 512.Pa basename Ns boot 513for the primary 514.Pq or only 515bootstrap, and 516.Pf boot Pa basename 517for the secondary bootstrap; for example, 518.Pa /usr/mdec/sdboot 519and 520.Pa /usr/mdec/bootsd 521if the disk device is 522.Em sd0 . 523.Pp 524The first of the three boot-installation forms is used to install 525bootstrap code without changing the existing label. 526It is essentially a read command with respect to the disk label itself 527and all options are related to the specification of the boot program 528as described previously. 529The final two forms are analogous to the basic write and restore versions 530except that they will install bootstrap code in addition to a new label. 531.Pp 532Note that when a disk has no real BSD disklabel, the kernel creates a 533default label so that the disk can be used. 534This default label will include other slices found on the disk if 535they are supported on your architecture. 536For example, on systems that support 537.Xr fdisk 8 538partitions the default label will also include DOS and Linux partitions. 539However, these entries are not dynamic, they are fixed at the time 540.Nm 541is run. 542That means that subsequent changes that affect non-MirBSD 543slices will not be present in the default label, 544though they may be updated by hand. 545To see the default label, run 546.Nm 547with the 548.Fl d 549flag. 550.Nm 551can then be run with the 552.Fl e 553flag and any entries pasted as desired from the default label into the real one. 554.Sh FILES 555.Bl -tag -width Pa -compact 556.It Pa /etc/disklabels 557Directory for backup labels. 558.It Pa /etc/disktab 559Disk description file. 560.It Pa /usr/mdec/ Ns Em xx Ns boot 561Primary bootstrap. 562.It Pa /usr/mdec/boot Ns Em xx 563Secondary bootstrap. 564.El 565.Sh EXAMPLES 566Display the in-core label for sd0 as obtained via 567.Pa /dev/rsd0c : 568.Pp 569.Dl # disklabel sd0 570.Pp 571Create a label for sd0 based on information for 572.Dq sd2212 573found in 574.Pa /etc/disktab . 575Any existing bootstrap code will be clobbered. 576(Normally you do not want to use the 577.Fl r 578flag though.) 579.Pp 580.Dl # disklabel -w -r /dev/rsd0c sd2212 foo 581.Pp 582Read the on-disk label for sd0, edit it and reinstall in-core as 583well as on-disk. 584(Normally you do not want to use the 585.Fl r 586flag 587though.) 588Existing bootstrap code is unaffected. 589.Pp 590.Dl # disklabel -e -r sd0 591.Pp 592Restore the on-disk and in-core label for sd0 from information in 593.Pa mylabel . 594Existing bootstrap code is unaffected. 595.Pp 596.Dl # disklabel -R sd0 mylabel 597.Pp 598Install a new bootstrap on sd0. 599The boot code comes from 600.Pa /usr/mdec/sdboot 601and possibly 602.Pa /usr/mdec/bootsd . 603On-disk and in-core labels are unchanged, but on some systems other 604information may be destroyed. 605Use with care. 606.Pp 607.Dl # disklabel -B sd0 608.Pp 609Install a new label and bootstrap. 610The label is derived from disktab information for 611.Dq sd2212 612and installed both in-core and 613on-disk. 614The bootstrap code comes from the file 615.Pa /usr/mdec/newboot . 616.Pp 617.Dl # disklabel -w -B /dev/rsd0c -b newboot sd2212 618.Sh DIAGNOSTICS 619The kernel device drivers will not allow the size of a disk slice 620to be decreased or the offset of a slice to be changed while 621it is open. 622Some device drivers create a label containing only a 623single large slice if a disk is unlabeled; thus, the label must 624be written to the 625.Sq a 626slice of the disk while it is open. 627This sometimes requires the desired label to be set in two steps, 628the first one creating at least one other slice, and the second 629setting the label on the new slice while shrinking the 630.Sq a 631slice. 632.Pp 633On some machines the bootstrap code may not fit entirely in the 634area allocated for it by some filesystems. 635As a result, it may 636not be possible to have filesystems on some slices of a 637.Dq bootable 638disk. 639When installing bootstrap code, 640.Nm 641checks for these cases. 642If the installed boot code would overlap a slice of type 643.Dv FS_UNUSED 644it is marked as type 645.Dv FS_BOOT . 646The 647.Xr newfs 8 648utility will disallow creation of filesystems on 649.Dv FS_BOOT 650slices. 651Conversely, if a slice has a type other than 652.Dv FS_UNUSED 653or 654.Dv FS_BOOT , 655.Nm 656will not install bootstrap code that overlaps it. 657.Sh SEE ALSO 658.Xr disklabel 5 , 659.Xr disktab 5 , 660.Xr scan_ffs 8 661.Sh CAVEATS 662On i386 machines, 663.Xr installboot 8 664is normally used to install boot code. 665The 666.Fl B 667option to 668.Nm 669can still be used to install old style boot code, 670but this usage is deprecated. 671.Pp 672On some machines, such as the sparc, disklabels 673may not exhibit the full functionality that is described above. 674.Pp 675.Nm 676only supports up to a maximum of 15 slices, 677.Sq a 678through 679.Sq p , 680excluding 681.Sq c . 682The 683.Sq c 684slice is reserved for the entire physical disk. 685By convention, the 686.Sq a 687slice of the boot disk is the root filesystem, and the 688.Sq b 689slice of the boot disk is the swap partition, 690but all other letters can be used in any order for any other 691slices as desired. 692.Sh BUGS 693When a disk name is given without a full pathname, the constructed 694device name uses the 695.Sq c 696slice. 697In 698.Fl E 699mode, 700.Nm 701is far too quick to shuffle slices around; it should keep a 702free block list and only move slices around with the user's 703permission. 704