.\" $OpenBSD: disklabel.8,v 1.40 2001/02/04 15:06:05 deraadt Exp $ .\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $ .\" .\" Copyright (c) 1987, 1988, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Symmetric Computer Systems. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 .\" .Dd October 27, 1997 .Dt DISKLABEL 8 .Os .Sh NAME .Nm disklabel .Nd read and write disk pack label .Sh SYNOPSIS .Nm disklabel .Op Fl n .Op Fl cd Li \&| Fl r .Op Fl t .Op Fl v .Ar disk .Nm disklabel .Fl w .Op Fl n .Op Fl cd Li \&| Fl r .Op Fl v .Ar disk Ar disktype .Oo Ar packid Oc .Nm disklabel .Fl e .Op Fl n .Op Fl cd Li \&| Fl r .Op Fl v .Ar disk .Nm disklabel .Fl E .Op Fl f Ar tempfile .Op Fl n .Op Fl cd Li \&| Fl r .Op Fl v .Ar disk .Nm disklabel .Fl R .Op Fl r .Op Fl n .Op Fl v .Ar disk Ar protofile .Nm disklabel .Op Fl NW .Op Fl n .Op Fl v .Ar disk .Pp .Nm disklabel .Fl B .Op Fl n .Op Fl v .Oo .Fl b Ar boot1 .Op Fl s Ar boot2 .Oc .Ar disk .Oo Ar disktype Oc .Nm disklabel .Fl w .Fl B .Op Fl n .Op Fl v .Oo .Fl b Ar boot1 .Op Fl s Ar boot2 .Oc .Ar disk Ar disktype .Oo Ar packid Oc .Nm disklabel .Fl R .Fl B .Op Fl n .Op Fl v .Oo .Fl b Ar boot1 .Op Fl s Ar boot2 .Oc .Ar disk Ar protofile .Oo Ar disktype Oc .Sh DESCRIPTION The .Nm utility can be used to install, examine, or modify the label on a disk drive or pack. The disk label contains information about disk characteristics (size, type, etc.) and the partition layout, stored on the disk itself. It is used by the operating system to optimize disk I/O and locate the filesystems resident on the disk. .Pp The options are as follows: .Bl -tag -width Ds .It Fl n Make no permanent changes to the disklabel (useful for debugging purposes). .It Fl v Print additional information during operation (verbose mode). .It Fl r Causes the label to be read from or written to the disk directly, rather than going through the system's in-core copy of the label. This option may allow a label to be installed on a disk without kernel support for a label, such as when labels are first installed on a system. This flag does not work on a number of architectures, thus it is not considered the right way to put a new label on a disk. Its use is discouraged. .It Fl B Install bootstrap code. The .Fl r flag is implied by .Fl B and never needs to be specified. .It Fl b Specify the single level boot program, or the primary boot program, depending on the system boot architecture (single or two-level). .It Fl s On machines with a two-level bootstrap (such as i386-based systems), specify the secondary boot program. .It Fl d Use the .Em default label. This ignores any existing .Ox partitions on the disk. Note that this option will only work for disks that are capable of reporting their geometry, such as SCSI, IDE, and ESDI. May not be used in conjunction with the .Fl r flag. .It Fl c Clear the system's in-core copy of the label and update it based on the on-disk label. May not be used in conjunction with the .Fl r flag. .It Fl f Ar tempfile Write entries to .Ar tempfile in .Xr fstab 5 format for any partitions for which mount point information has been specified. The .Fl f flag is only valid when used in conjunction with the .Fl E flag. If .Ar tempfile already exists, it will be overwritten. .It Fl t Format the label as a .Xr disktab 5 entry. .It Fl w Write a standard label on the designated drive. .It Fl e Edit an existing disk label using the editor specified in the .Ev EDITOR environment variable, or .Xr vi 1 if none is specified. .It Fl E Use a simple initial label editor, using the command-driven built-in editor described below. .It Fl R Restore a disk label that was formatted in a prior operation and saved in an .Tn ASCII file. .It Fl N Disallow writing of the pack label area on the selected disk. .It Fl W Allow writing of the pack label area on the selected disk. .El .Pp The first form of the command (read) is used to examine the label on the named disk drive (e.g., sd0 or .Pa /dev/rsd0c Ns ). It will display all of the parameters associated with the drive and its partition layout. Unless the .Fl r flag is given, the kernel's in-core copy of the label is displayed; if the disk has no label, or the partition types on the disk are incorrect, the kernel may have constructed or modified the label. .Pp The second form of the command (write) is used to write a standard label on the designated drive. The drive parameters and partitions are taken from that file. If different disks of the same physical type are to have different partitions, it will be necessary to have separate disktab entries describing each, or to edit the label after installation as described below. The optional argument is a pack identification string, up to 16 characters long. The pack ID must be quoted if it contains blanks. If the .Fl r flag is given, the disk sectors containing the label and bootstrap will be written directly. A side-effect of this is that any existing bootstrap code will be overwritten and the disk rendered unbootable. If .Fl r is not specified, the existing label will be updated via the in-core copy and any bootstrap code will be unaffected. If the disk does not already have a label, the .Fl r flag must be used. In either case, the kernel's in-core label is replaced. .Pp In the third form of the command (edit), the label is read from the in-core kernel copy, or directly from the disk if the .Fl r flag is also given. The label is formatted and then supplied to an editor for changes. If no editor is specified in an .Ev EDITOR environment variable, .Xr vi 1 is used. When the editor terminates, the formatted label is reread and used to rewrite the disk label. Existing bootstrap code is unchanged regardless of whether .Fl r was specified. .Pp The initial label editor mode is only intended for new disks as it will move partitions around as necessary to maintain a contiguous pool of free blocks. Some commands or prompts take an optional unit. Available units are .Sq b for bytes, .Sq c for cylinders, .Sq k for kilobytes, .Sq m for megabytes, and .Sq g for gigabytes. Quantities will be rounded to the nearest cylinder when units are specified for sizes (or offsets). Commands may be aborted by entering .Ql ^D (Control-D). Entering .Ql ^D at the main .Ql > prompt will exit the editor. At prompts that request a size, .Ql * may be entered to indicate the rest of the available space. The editor commands are as follows: .Bl -tag -width "p [unit] " .It ? Op command Display help message with all available commands. You may specify a .Em command for which to get more detailed help. There is also (simple) context-sensitive help available at most prompts. .It M Display this manual page. .It u Undo (or redo) last change. Entering .Em u once will undo your last change. Entering it again will restore the change. .It p Op unit Print the current disk label. If a .Em unit is given, the size and offsets are displayed in terms of the specified unit. .It e Edit drive parameters. This option is used to set the following parameters: sectors/track, tracks/cylinder, sectors/cylinder, number of cylinders on the disk, total sectors on the disk, rpm, interleave, disk type, and a descriptive label string. .It b Set OpenBSD disk boundaries. This option tells .Nm which parts of the disk it is allowed to modify. This option is probably only useful for ports with fdisk partition tables where the ending sector in the MBR is incorrect. The user may enter .Ql * at the .Dq Size prompt to indicate the entire size of the disk (minus the starting sector). This is useful for disks larger than 8 gigabytes where the fdisk partition table is incapable of storing the real size. .It r Recalculate free space. This option should really not be necessary under normal circumstances. .It a Op part Add new partition. This option adds a new BSD partition. If no partition letter is specified (a-p), the user will be prompted for one. .It c Op part Change the size of an existing partition. If no partition is specified, the user will be prompted for one. The new size may be in terms of the aforementioned units and may also be prefixed with .Ql + or .Ql - to change the size by a relative amount. .It d Op part Delete an existing partition (or .Ql * to delete all partitions). If no partition is specified, the user will be prompted for one. You may not delete the .Ql c partition. .It g Op d|b|u Set disk geometry based on what the .Em disk , .Em BIOS , or .Em user thinks (the .Em user geometry is simply what the label said before .Nm made any changes). .It D Sets the disk label to the default values as reported by the kernel. This similates the case where there is no disk label. .It m Op part Modify parameters for an existing partition. If no partition is specified, the user will be prompted for one. This option allows the user to change the filesystem type, starting offset, partition size, block fragment size, block size, and cylinders per group for the specified partition (not all parameters are configurable for non-BSD partitions). .It n Op part Name the mount point for an existing partition. If no partition is specified, the user will be prompted for one. This option is only valid if .Nm was invoked with the .Fl f flag. .It s Op path Save the label to a file in .Tn ASCII format (suitable for loading via the .Fl R option). If no path is specified, the user will be prompted for one. .It w Write the label to disk. This option will commit any changes to the on-disk label. .It q Quit the editor. If any changes have been made, the user will be asked whether or not to save the changes to the on-disk label. .It x Exit the editor without saving any changes to the label. .It X Toggle .Dq expert mode . By default, some settings are reserved for experts only (such as the block and fragment size on ffs partitions). .It z Zeroes out the existing partition table, leaving only the .Dq c partition. The drive parameters are not changed. .El .Pp In the restore form of the command, the prototype file used to create the label should be in the same format as that produced when reading or editing a label. Comments are delimited by .Ar \&# and newline. As with .Fl w , any existing bootstrap code will be clobbered if .Fl r is specified and will be unaffected otherwise. .Pp The final three forms of .Nm are used to install bootstrap code on machines where the bootstrap is part of the label. The bootstrap code is comprised of one or two boot programs depending on the machine. .Pp When installting bootstrap code with the .Fl B flag, if the names are not explicitly given, standard boot programs will be used. The boot programs are located in .Pa /usr/mdec . The names of the programs are taken from the .Dq b0 and .Dq b1 parameters of the .Xr disktab 5 entry for the disk if .Ar disktype was given and its disktab entry exists and includes those parameters. Otherwise, boot program names are derived from the name of the disk. These names are of the form .Pa basename Ns boot for the primary (or only) bootstrap, and .Pf boot Pa basename for the secondary bootstrap; for example, .Pa /usr/mdec/sdboot and .Pa /usr/mdec/bootsd if the disk device is .Em sd0 . .Pp The first of the three boot-installation forms is used to install bootstrap code without changing the existing label. It is essentially a read command with respect to the disk label itself and all options are related to the specification of the boot program as described previously. The final two forms are analogous to the basic write and restore versions except that they will install bootstrap code in addition to a new label. .Sh EXAMPLES .Dl disklabel sd0 .Pp Display the in-core label for sd0 as obtained via .Pa /dev/rsd0c . .Pp .Dl disklabel -w -r /dev/rsd0c sd2212 foo .Pp Create a label for sd0 based on information for .Dq sd2212 found in .Pa /etc/disktab . Any existing bootstrap code will be clobbered. (Normally you do not want to use the .Fl r flag though.) .Pp .Dl disklabel -e -r sd0 .Pp Read the on-disk label for sd0, edit it and reinstall in-core as well as on-disk. (Normally you do not want to use the .Fl r flag though.) Existing bootstrap code is unaffected. .Pp .Dl disklabel -R sd0 mylabel .Pp Restore the on-disk and in-core label for sd0 from information in .Pa mylabel . Existing bootstrap code is unaffected. .Pp .Dl disklabel -B sd0 .Pp Install a new bootstrap on sd0. The boot code comes from .Pa /usr/mdec/sdboot and possibly .Pa /usr/mdec/bootsd . On-disk and in-core labels are unchanged, but on some systems other information may be destroyed. Use with care. .Pp .Dl disklabel -w -B /dev/rsd0c -b newboot sd2212 .Pp Install a new label and bootstrap. The label is derived from disktab information for .Dq sd2212 and installed both in-core and on-disk. The bootstrap code comes from the file .Pa /usr/mdec/newboot . .Sh FILES .Bl -tag -width Pa -compact .It Pa /etc/disktab .It Pa /usr/mdec/ Ns Em xx Ns boot .It Pa /usr/mdec/boot Ns Em xx .El .Sh SEE ALSO .Xr disklabel 5 , .Xr disktab 5 , .Xr scan_ffs 5 .Sh DIAGNOSTICS The kernel device drivers will not allow the size of a disk partition to be decreased or the offset of a partition to be changed while it is open. Some device drivers create a label containing only a single large partition if a disk is unlabeled; thus, the label must be written to the .Sq a partition of the disk while it is open. This sometimes requires the desired label to be set in two steps, the first one creating at least one other partition, and the second setting the label on the new partition while shrinking the .Sq a partition. .Pp On some machines the bootstrap code may not fit entirely in the area allocated for it by some filesystems. As a result, it may not be possible to have filesystems on some partitions of a .Dq bootable disk. When installing bootstrap code, .Nm checks for these cases. If the installed boot code would overlap a partition of type .Dv FS_UNUSED it is marked as type .Dv FS_BOOT . The .Xr newfs 8 utility will disallow creation of filesystems on .Dv FS_BOOT partitions. Conversely, if a partition has a type other than .Dv FS_UNUSED or .Dv FS_BOOT , .Nm will not install bootstrap code that overlaps it. .Sh NOTES On i386 machines, .Xr installboot 8 is normally used to install boot code. The .Fl B option to .Nm can still be used to install old style boot code, but this usage is deprecated. .Pp On some machines, such as the sparc and amiga, partition tables may not exhibit the full functionality that is described above. .Sh BUGS When a disk name is given without a full pathname, the constructed device name uses the .Sq a partition on the tahoe, the .Sq c partition on all others. In .Fl E mode, .Nm is far too quick to shuffle partitions around; it should keep a free block list and only move partitions around with the user's permission. Also, in .Fl E mode, partitions outside the OpenBSD portion of the disk should be changeable.