xref: /freebsd/sbin/bsdlabel/bsdlabel.8 (revision 2ad872c5794e4c26fdf6ed219ad3f09ca0d5304a)
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 acknowledgment:
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.\"	$Id: disklabel.8,v 1.9 1998/11/28 09:43:31 rnordier Exp $
37.\"
38.Dd April 19, 1994
39.Dt DISKLABEL 8
40.Os BSD 4.2
41.Sh NAME
42.Nm disklabel
43.Nd read and write disk pack label
44.Sh SYNOPSIS
45.Nm disklabel
46.Op Fl r
47.Ar disk
48.Nm disklabel
49.Fl w
50.Op Fl r
51.Ar disk Ar disktype
52.Oo Ar packid Oc
53.Nm disklabel
54.Fl e
55.Op Fl r
56.Ar disk
57.Nm disklabel
58.Fl R
59.Op Fl r
60.Ar disk Ar protofile
61.Nm disklabel
62.Op Fl NW
63.Ar disk
64.sp
65.Nm disklabel
66.Fl B
67.Oo
68.Fl b Ar boot1
69.Op Fl s Ar boot2
70.Oc
71.Ar disk
72.Oo Ar disktype Oc
73.Nm disklabel
74.Fl w
75.Fl B
76.Oo
77.Fl b Ar boot1
78.Op Fl s Ar boot2
79.Oc
80.Ar disk Ar disktype
81.Oo Ar packid Oc
82.Nm disklabel
83.Fl R
84.Fl B
85.Oo
86.Fl b Ar boot1
87.Op Fl s Ar boot2
88.Oc
89.Ar disk Ar protofile
90.Oo Ar disktype Oc
91.Sh DESCRIPTION
92.Nm Disklabel
93can be used to install, examine or modify the label on a disk drive or pack.
94When writing the label, it can be used
95to change the drive identification,
96the disk partitions on the drive,
97or to replace a damaged label.
98On some systems,
99.Nm
100can be used to install bootstrap code as well.
101There are several forms of the command that read (display), install or edit
102the label on a disk.
103Each form has an additional option,
104.Fl r ,
105which causes the label to be read from or written to the disk directly,
106rather than going through the system's in-core copy of the label.
107This option may allow a label to be installed on a disk
108without kernel support for a label, such as when labels are first installed
109on a system; it must be used when first installing a label on a disk.
110The specific effect of
111.Fl r
112is described under each command.
113The read and install forms also support the
114.Fl B
115option to install bootstrap code.
116These variants are described later.
117.Pp
118The first form of the command (read) is used to examine the label on the named
119disk drive (e.g. da0 or /dev/rda0c).
120It will display all of the parameters associated with the drive
121and its partition layout.
122Unless the
123.Fl r
124flag is given,
125the kernel's in-core copy of the label is displayed;
126if the disk has no label, or the partition types on the disk are incorrect,
127the kernel may have constructed or modified the label.
128If the
129.Fl r
130flag is given, the label from the raw disk will be displayed rather
131than the in-core label.
132.Pp
133The second form of the command, with the
134.Fl w
135flag, is used to write a standard label on the designated drive.
136The required arguments to
137.Nm
138are the drive to be labeled (e.g. da0), and
139the drive type as described in the
140.Xr disktab 5
141file.
142The drive parameters and partitions are taken from that file.
143If different disks of the same physical type are to have different
144partitions, it will be necessary to have separate disktab entries
145describing each, or to edit the label after installation as described below.
146The optional argument is a pack identification string,
147up to 16 characters long.
148The pack id must be quoted if it contains blanks.
149If the
150.Fl r
151flag is given, the disk sectors containing the label and bootstrap
152will be written directly.
153A side-effect of this is that any existing bootstrap code will be overwritten
154and the disk rendered unbootable.
155If
156.Fl r
157is not specified,
158the existing label will be updated via the in-core copy and any bootstrap
159code will be unaffected.
160If the disk does not already have a label, the
161.Fl r
162flag must be used.
163In either case, the kernel's in-core label is replaced.
164.Pp
165For a virgin disk that is not known to
166.Xr disktab 5 ,
167.Ar disktype
168can be specified as
169.Dq auto .
170In this case, the driver is requested to produce a virgin label for the
171disk.  This might or might not be successful, depending on whether the
172driver for the disk is able to get the required data without reading
173anything from the disk at all.  It will likely succeed for all SCSI
174disks, most IDE disks, and vnode devices.  Writing a label to the
175disk is the only supported operation, and the
176.Ar disk
177itself must be provided as the canonical name, i.e. not as a full
178path name.
179.Pp
180An existing disk label may be edited by using the
181.Fl e
182flag.
183The label is read from the in-core kernel copy,
184or directly from the disk if the
185.Fl r
186flag is also given.
187The label is formatted and then supplied to an editor for changes.
188If no editor is specified in an
189.Ev EDITOR
190environment variable,
191.Xr vi 1
192is used.
193When the editor terminates, the formatted label is reread
194and used to rewrite the disk label.
195Existing bootstrap code is unchanged regardless of whether
196.Fl r
197was specified.
198.Pp
199With the
200.Fl R
201flag,
202.Nm
203is capable of restoring a disk label that was formatted
204in a prior operation and saved in an ascii file.
205The prototype file used to create the label should be in the same format
206as that produced when reading or editing a label.
207Comments are delimited by
208.Ar \&#
209and newline.
210As with
211.Fl w ,
212any existing bootstrap code will be clobbered if
213.Fl r
214is specified and will be unaffected otherwise.
215.Pp
216The
217.Fl NW
218flags for
219.Nm
220explicitly disallow and
221allow, respectively, writing of the pack label area on the selected disk.
222.Pp
223The final three forms of
224.Nm
225are used to install bootstrap code on machines where the bootstrap is part
226of the label.
227The bootstrap code is comprised of one or two boot programs depending on
228the machine.
229The
230.Fl B
231option is used to denote that bootstrap code is to be installed.
232The
233.Fl r
234flag is implied by
235.Fl B
236and never needs to be specified.
237The name of the boot program(s) to be installed can be selected in a
238variety of ways.
239First, the names can be specified explicitly via the
240.Fl b
241and
242.Fl s
243flags.
244On machines with only a single level of boot program,
245.Fl b
246is the name of that program.
247For machines with a two-level bootstrap,
248.Fl b
249indicates the primary boot program and
250.Fl s
251the secondary boot program.
252If the names are not explicitly given, standard boot programs will be used.
253The boot programs are located in
254.Pa /boot .
255The names of the programs are taken from the ``b0'' and ``b1'' parameters
256of the
257.Xr disktab 5
258entry for the disk if
259.Ar disktype
260was given and its disktab entry exists and includes those parameters.
261Otherwise, the default boot image names are used, these being:
262.Pa /boot/boot1
263and
264.Pa /boot/boot2
265for the standard stage1 and stage2 boot images (details may vary
266on architectures like the Alpha, where only a single-stage boot is used).
267.Pp
268The first of the three boot-installation forms is used to install
269bootstrap code without changing the existing label.
270It is essentially a read command with respect to the disk label
271itself and all options are related to the specification of the boot
272program as described previously.
273The final two forms are analogous to the basic write and restore versions
274except that they will install bootstrap code in addition to a new label.
275.Sh FILES
276.Bl -tag -width Pa -compact
277.It Pa /etc/disktab
278.It Pa /boot/
279.It Pa /boot/boot<n>
280.El
281.Sh EXAMPLES
282.Dl disklabel da0
283.Pp
284Display the in-core label for da0 as obtained via
285.Pa /dev/rda0c .
286.Pp
287.Dl disklabel -w -r /dev/rda0c da2212 foo
288.Pp
289Create a label for da0 based on information for ``da2212'' found in
290.Pa /etc/disktab .
291Any existing bootstrap code will be clobbered.
292.Pp
293.Dl disklabel -e -r da0
294.Pp
295Read the on-disk label for da0, edit it and reinstall in-core as well
296as on-disk.
297Existing bootstrap code is unaffected.
298.Pp
299.Dl disklabel -r -w da0 auto
300.Pp
301Try to auto-detect the required information from da0, and write a new
302label to the disk.  Use another disklabel -e command to edit the
303partitioning and file system information.
304.Pp
305.Dl disklabel -R da0 mylabel
306.Pp
307Restore the on-disk and in-core label for da0 from information in
308.Pa mylabel .
309Existing bootstrap code is unaffected.
310.Pp
311.Dl disklabel -B da0
312.Pp
313Install a new bootstrap on da0.
314The boot code comes from
315.Pa /boot/boot1
316and possibly
317.Pa /boot/boot2 .
318On-disk and in-core labels are unchanged.
319.Pp
320.Dl disklabel -w -B /dev/rda0c -b newboot da2212
321.Pp
322Install a new label and bootstrap.
323The label is derived from disktab information for ``da2212'' and
324installed both in-core and on-disk.
325The bootstrap code comes from the file
326.Pa /boot/newboot .
327.Sh SEE ALSO
328.Xr disklabel 5 ,
329.Xr disktab 5
330.Sh DIAGNOSTICS
331The kernel device drivers will not allow the size of a disk partition
332to be decreased or the offset of a partition to be changed while it is open.
333Some device drivers create a label containing only a single large partition
334if a disk is unlabeled; thus, the label must be written to the ``a''
335partition of the disk while it is open.
336This sometimes requires the desired label to be set in two steps,
337the first one creating at least one other partition,
338and the second setting the label on the new partition
339while shrinking the ``a'' partition.
340.Pp
341On some machines the bootstrap code may not fit entirely in the area
342allocated for it by some filesystems.
343As a result, it may not be possible to have filesystems on some partitions
344of a ``bootable'' disk.
345When installing bootstrap code,
346.Nm
347checks for these cases.
348If the installed boot code would overlap a partition of type FS_UNUSED
349it is marked as type FS_BOOT.
350The
351.Xr newfs 8
352utility will disallow creation of filesystems on FS_BOOT partitions.
353Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT,
354.Nm
355will not install bootstrap code that overlaps it.
356.Sh BUGS
357When a disk name is given without a full pathname,
358the constructed device name uses the ``a'' partition on the Tahoe,
359the ``c'' partition on all others.
360.Pp
361For the i386 architecture, the primary bootstrap sector contains
362an embedded
363.Em fdisk
364table.
365.Nm Disklabel
366takes care to not clobber it when installing a bootstrap only
367.Pq Fl B ,
368or when editing an existing label
369.Pq Fl e ,
370but it unconditionally writes the primary bootstrap program onto
371the disk for
372.Fl w
373or
374.Fl R ,
375thus replacing the
376.Em fdisk
377table by the dummy one in the bootstrap program.  This is only of
378concern if the disk is fully dedicated, so that the BSD disklabel
379starts at absolute block 0 on the disk.
380