xref: /freebsd/sbin/bsdlabel/bsdlabel.8 (revision afe61c15161c324a7af299a9b8457aba5afc92db)
1.\" Copyright (c) 1987, 1988, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Symmetric Computer Systems.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"	This product includes software developed by the University of
18.\"	California, Berkeley and its contributors.
19.\" 4. 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 "April 19, 1994"
38.Dt DISKLABEL 8
39.Os BSD 4.2
40.Sh NAME
41.Nm disklabel
42.Nd read and write disk pack label
43.Sh SYNOPSIS
44.Nm disklabel
45.Op Fl r
46.Ar disk
47.Nm disklabel
48.Fl w
49.Op Fl r
50.Ar disk Ar disktype
51.Oo Ar packid Oc
52.Nm disklabel
53.Fl e
54.Op Fl r
55.Ar disk
56.Nm disklabel
57.Fl R
58.Op Fl r
59.Ar disk Ar protofile
60.Nm disklabel
61.Op Fl NW
62.Ar disk
63.sp
64.Nm disklabel
65.Fl B
66.Oo
67.Fl b Ar boot1
68.Op Fl s Ar boot2
69.Oc
70.Ar disk
71.Oo Ar disktype Oc
72.Nm disklabel
73.Fl w
74.Fl B
75.Oo
76.Fl b Ar boot1
77.Op Fl s Ar boot2
78.Oc
79.Ar disk Ar disktype
80.Oo Ar packid Oc
81.Nm disklabel
82.Fl R
83.Fl B
84.Oo
85.Fl b Ar boot1
86.Op Fl s Ar boot2
87.Oc
88.Ar disk Ar protofile
89.Oo Ar disktype Oc
90.Sh DESCRIPTION
91.Nm Disklabel
92can be used to install, examine or modify the label on a disk drive or pack.
93When writing the label, it can be used
94to change the drive identification,
95the disk partitions on the drive,
96or to replace a damaged label.
97On some systems,
98.Nm disklabel
99can be used to install bootstrap code as well.
100There are several forms of the command that read (display), install or edit
101the label on a disk.
102Each form has an additional option,
103.Fl r ,
104which causes the label to be read from or written to the disk directly,
105rather than going through the system's in-core copy of the label.
106This option may allow a label to be installed on a disk
107without kernel support for a label, such as when labels are first installed
108on a system; it must be used when first installing a label on a disk.
109The specific effect of
110.Fl r
111is described under each command.
112The read and install forms also support the
113.Fl B
114option to install bootstrap code.
115These variants are described later.
116.Pp
117The first form of the command (read) is used to examine the label on the named
118disk drive (e.g. sd0 or /dev/rsd0c).
119It will display all of the parameters associated with the drive
120and its partition layout.
121Unless the
122.Fl r
123flag is given,
124the kernel's in-core copy of the label is displayed;
125if the disk has no label, or the partition types on the disk are incorrect,
126the kernel may have constructed or modified the label.
127If the
128.Fl r
129flag is given, the label from the raw disk will be displayed rather
130than the in-core label.
131.Pp
132The second form of the command, with the
133.Fl w
134flag, is used to write a standard label on the designated drive.
135The required arguments to
136.Nm disklabel
137are the drive to be labelled (e.g. sd0), and
138the drive type as described in the
139.Xr disktab 5
140file.
141The drive parameters and partitions are taken from that file.
142If different disks of the same physical type are to have different
143partitions, it will be necessary to have separate disktab entries
144describing each, or to edit the label after installation as described below.
145The optional argument is a pack identification string,
146up to 16 characters long.
147The pack id must be quoted if it contains blanks.
148If the
149.Fl r
150flag is given, the disk sectors containing the label and bootstrap
151will be written directly.
152A side-effect of this is that any existing bootstrap code will be overwritten
153and the disk rendered unbootable.
154If
155.Fl r
156is not specified,
157the existing label will be updated via the in-core copy and any bootstrap
158code will be unaffected.
159If the disk does not already have a label, the
160.Fl r
161flag must be used.
162In either case, the kernel's in-core label is replaced.
163.Pp
164An existing disk label may be edited by using the
165.Fl e
166flag.
167The label is read from the in-core kernel copy,
168or directly from the disk if the
169.Fl r
170flag is also given.
171The label is formatted and then supplied to an editor for changes.
172If no editor is specified in an
173.Ev EDITOR
174environment variable,
175.Xr vi 1
176is used.
177When the editor terminates, the formatted label is reread
178and used to rewrite the disk label.
179Existing bootstrap code is unchanged regardless of whether
180.Fl r
181was specified.
182.Pp
183With the
184.Fl R
185flag,
186.Nm disklabel
187is capable of restoring a disk label that was formatted
188in a prior operation and saved in an ascii file.
189The prototype file used to create the label should be in the same format
190as that produced when reading or editing a label.
191Comments are delimited by
192.Ar \&#
193and newline.
194As with
195.Fl w ,
196any existing bootstrap code will be clobbered if
197.Fl r
198is specified and will be unaffected otherwise.
199.Pp
200The
201.Fl NW
202flags for
203.Nm disklabel
204explicitly disallow and
205allow, respectively, writing of the pack label area on the selected disk.
206.Pp
207The final three forms of
208.Nm disklabel
209are used to install boostrap code on machines where the bootstrap is part
210of the label.
211The bootstrap code is comprised of one or two boot programs depending on
212the machine.
213The
214.Fl B
215option is used to denote that bootstrap code is to be installed.
216The
217.Fl r
218flag is implied by
219.Fl B
220and never needs to be specified.
221The name of the boot program(s) to be installed can be selected in a
222variety of ways.
223First, the names can be specified explicitly via the
224.Fl b
225and
226.Fl s
227flags.
228On machines with only a single level of boot program,
229.Fl b
230is the name of that program.
231For machines with a two-level bootstrap,
232.Fl b
233indicates the primary boot program and
234.Fl s
235the secondary boot program.
236If the names are not explicitly given, standard boot programs will be used.
237The boot programs are located in
238.Pa /usr/mdec .
239The names of the programs are taken from the ``b0'' and ``b1'' parameters
240of the
241.Xr disktab 5
242entry for the disk if
243.Ar disktype
244was given and its disktab entry exists and includes those parameters.
245Otherwise, boot program names are derived from the name of the disk.
246These names are of the form
247.Pa basename Ns boot
248for the primary (or only) bootstrap, and
249.Pf boot Pa basename
250for the secondary bootstrap;
251for example,
252.Pa /usr/mdec/sdboot
253and
254.Pa /usr/mdec/bootsd
255if the disk device is
256.Em sd0 .
257.Pp
258The first of the three boot-installation forms is used to install
259bootstrap code without changing the existing label.
260It is essentially a read command with respect to the disk label
261itself and all options are related to the specification of the boot
262program as described previously.
263The final two forms are analogous to the basic write and restore versions
264except that they will install bootstrap code in addition to a new label.
265.Sh FILES
266.Bl -tag -width Pa -compact
267.It Pa /etc/disktab
268.It Pa /usr/mdec/ Ns Em xx Ns boot
269.It Pa /usr/mdec/boot Ns Em xx
270.El
271.Sh EXAMPLES
272.Dl disklabel sd0
273.Pp
274Display the in-core label for sd0 as obtained via
275.Pa /dev/rsd0c .
276.Pp
277.Dl disklabel -w -r /dev/rsd0c sd2212 foo
278.Pp
279Create a label for sd0 based on information for ``sd2212'' found in
280.Pa /etc/disktab .
281Any existing bootstrap code will be clobbered.
282.Pp
283.Dl disklabel -e -r sd0
284.Pp
285Read the on-disk label for sd0, edit it and reinstall in-core as well
286as on-disk.
287Existing bootstrap code is unaffected.
288.Pp
289.Dl disklabel -R sd0 mylabel
290.Pp
291Restore the on-disk and in-core label for sd0 from information in
292.Pa mylabel .
293Existing bootstrap code is unaffected.
294.Pp
295.Dl disklabel -B sd0
296.Pp
297Install a new bootstrap on sd0.
298The boot code comes from
299.Pa /usr/mdec/sdboot
300and possibly
301.Pa /usr/mdec/bootsd .
302On-disk and in-core labels are unchanged.
303.Pp
304.Dl disklabel -w -B /dev/rsd0c -b newboot sd2212
305.Pp
306Install a new label and bootstrap.
307The label is derived from disktab information for ``sd2212'' and
308installed both in-core and on-disk.
309The bootstrap code comes from the file
310.Pa /usr/mdec/newboot .
311.Sh SEE ALSO
312.Xr disktab 5 ,
313.Xr disklabel 5
314.Sh DIAGNOSTICS
315The kernel device drivers will not allow the size of a disk partition
316to be decreased or the offset of a partition to be changed while it is open.
317Some device drivers create a label containing only a single large partition
318if a disk is unlabeled; thus, the label must be written to the ``a''
319partition of the disk while it is open.
320This sometimes requires the desired label to be set in two steps,
321the first one creating at least one other partition,
322and the second setting the label on the new partition
323while shrinking the ``a'' partition.
324.Pp
325On some machines the bootstrap code may not fit entirely in the area
326allocated for it by some filesystems.
327As a result, it may not be possible to have filesystems on some partitions
328of a ``bootable'' disk.
329When installing bootstrap code,
330.Nm disklabel
331checks for these cases.
332If the installed boot code would overlap a partition of type FS_UNUSED
333it is marked as type FS_BOOT.
334The
335.Xr newfs 8
336utility will disallow creation of filesystems on FS_BOOT partitions.
337Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT,
338.Nm disklabel
339will not install bootstrap code that overlaps it.
340.Sh BUGS
341When a disk name is given without a full pathname,
342the constructed device name uses the ``a'' partition on the tahoe,
343the ``c'' partition on all others.
344