xref: /freebsd/sbin/bsdlabel/bsdlabel.8 (revision e627b39baccd1ec9129690167cf5e6d860509655)
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
164For a virgin disk that is not known to
165.Xr disktab 5 ,
166.Ar disktype
167can be specified as
168.Dq auto .
169In this case, the driver is requested to produce a virgin label for the
170disk.  This might or might not be successful, depending on whether the
171driver for the disk is able to get the required data without reading
172anything from the disk at all.  It will likely succeed for all SCSI
173disks, most IDE disks, and vnode devices.  Writing a label to the
174disk is the only supported operation, and the
175.Ar disk
176itself must be provided as the canonical name, i.e. not as a full
177path name.
178.Pp
179An existing disk label may be edited by using the
180.Fl e
181flag.
182The label is read from the in-core kernel copy,
183or directly from the disk if the
184.Fl r
185flag is also given.
186The label is formatted and then supplied to an editor for changes.
187If no editor is specified in an
188.Ev EDITOR
189environment variable,
190.Xr vi 1
191is used.
192When the editor terminates, the formatted label is reread
193and used to rewrite the disk label.
194Existing bootstrap code is unchanged regardless of whether
195.Fl r
196was specified.
197.Pp
198With the
199.Fl R
200flag,
201.Nm disklabel
202is capable of restoring a disk label that was formatted
203in a prior operation and saved in an ascii file.
204The prototype file used to create the label should be in the same format
205as that produced when reading or editing a label.
206Comments are delimited by
207.Ar \&#
208and newline.
209As with
210.Fl w ,
211any existing bootstrap code will be clobbered if
212.Fl r
213is specified and will be unaffected otherwise.
214.Pp
215The
216.Fl NW
217flags for
218.Nm disklabel
219explicitly disallow and
220allow, respectively, writing of the pack label area on the selected disk.
221.Pp
222The final three forms of
223.Nm disklabel
224are used to install boostrap code on machines where the bootstrap is part
225of the label.
226The bootstrap code is comprised of one or two boot programs depending on
227the machine.
228The
229.Fl B
230option is used to denote that bootstrap code is to be installed.
231The
232.Fl r
233flag is implied by
234.Fl B
235and never needs to be specified.
236The name of the boot program(s) to be installed can be selected in a
237variety of ways.
238First, the names can be specified explicitly via the
239.Fl b
240and
241.Fl s
242flags.
243On machines with only a single level of boot program,
244.Fl b
245is the name of that program.
246For machines with a two-level bootstrap,
247.Fl b
248indicates the primary boot program and
249.Fl s
250the secondary boot program.
251If the names are not explicitly given, standard boot programs will be used.
252The boot programs are located in
253.Pa /usr/mdec .
254The names of the programs are taken from the ``b0'' and ``b1'' parameters
255of the
256.Xr disktab 5
257entry for the disk if
258.Ar disktype
259was given and its disktab entry exists and includes those parameters.
260Otherwise, boot program names are derived from the name of the disk.
261These names are of the form
262.Pa basename Ns boot
263for the primary (or only) bootstrap, and
264.Pf boot Pa basename
265for the secondary bootstrap;
266for example,
267.Pa /usr/mdec/sdboot
268and
269.Pa /usr/mdec/bootsd
270if the disk device is
271.Em sd0 .
272.Pp
273The first of the three boot-installation forms is used to install
274bootstrap code without changing the existing label.
275It is essentially a read command with respect to the disk label
276itself and all options are related to the specification of the boot
277program as described previously.
278The final two forms are analogous to the basic write and restore versions
279except that they will install bootstrap code in addition to a new label.
280.Sh FILES
281.Bl -tag -width Pa -compact
282.It Pa /etc/disktab
283.It Pa /usr/mdec/ Ns Em xx Ns boot
284.It Pa /usr/mdec/boot Ns Em xx
285.El
286.Sh EXAMPLES
287.Dl disklabel sd0
288.Pp
289Display the in-core label for sd0 as obtained via
290.Pa /dev/rsd0c .
291.Pp
292.Dl disklabel -w -r /dev/rsd0c sd2212 foo
293.Pp
294Create a label for sd0 based on information for ``sd2212'' found in
295.Pa /etc/disktab .
296Any existing bootstrap code will be clobbered.
297.Pp
298.Dl disklabel -e -r sd0
299.Pp
300Read the on-disk label for sd0, edit it and reinstall in-core as well
301as on-disk.
302Existing bootstrap code is unaffected.
303.Pp
304.Dl disklabel -r -w sd0 auto
305.Pp
306Try to auto-detect the required information from sd0, and write a new
307label to the disk.  Use another disklabel -e command to edit the
308partitioning and file system information.
309.Pp
310.Dl disklabel -R sd0 mylabel
311.Pp
312Restore the on-disk and in-core label for sd0 from information in
313.Pa mylabel .
314Existing bootstrap code is unaffected.
315.Pp
316.Dl disklabel -B sd0
317.Pp
318Install a new bootstrap on sd0.
319The boot code comes from
320.Pa /usr/mdec/sdboot
321and possibly
322.Pa /usr/mdec/bootsd .
323On-disk and in-core labels are unchanged.
324.Pp
325.Dl disklabel -w -B /dev/rsd0c -b newboot sd2212
326.Pp
327Install a new label and bootstrap.
328The label is derived from disktab information for ``sd2212'' and
329installed both in-core and on-disk.
330The bootstrap code comes from the file
331.Pa /usr/mdec/newboot .
332.Sh SEE ALSO
333.Xr disktab 5 ,
334.Xr disklabel 5
335.Sh DIAGNOSTICS
336The kernel device drivers will not allow the size of a disk partition
337to be decreased or the offset of a partition to be changed while it is open.
338Some device drivers create a label containing only a single large partition
339if a disk is unlabeled; thus, the label must be written to the ``a''
340partition of the disk while it is open.
341This sometimes requires the desired label to be set in two steps,
342the first one creating at least one other partition,
343and the second setting the label on the new partition
344while shrinking the ``a'' partition.
345.Pp
346On some machines the bootstrap code may not fit entirely in the area
347allocated for it by some filesystems.
348As a result, it may not be possible to have filesystems on some partitions
349of a ``bootable'' disk.
350When installing bootstrap code,
351.Nm disklabel
352checks for these cases.
353If the installed boot code would overlap a partition of type FS_UNUSED
354it is marked as type FS_BOOT.
355The
356.Xr newfs 8
357utility will disallow creation of filesystems on FS_BOOT partitions.
358Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT,
359.Nm disklabel
360will not install bootstrap code that overlaps it.
361.Sh BUGS
362When a disk name is given without a full pathname,
363the constructed device name uses the ``a'' partition on the tahoe,
364the ``c'' partition on all others.
365.Pp
366For the i386 architecture, the primary bootstrap sector contains
367an embedded
368.Em fdisk
369table.
370.Nm Disklabel
371takes care to not clobber it when installing a bootstrap only
372.Pq Fl B ,
373or when editing an existing label
374.Pq Fl e ,
375but it unconditionally writes the primary bootstrap program onto
376the disk for
377.Fl w
378or
379.Fl R ,
380thus replacing the
381.Em fdisk
382table by the dummy one in the bootstrap program.  This is only of
383concern if the disk is fully dedicated, so that the BSD disklabel
384starts at absolute block 0 on the disk.
385