xref: /freebsd/sbin/bsdlabel/bsdlabel.8 (revision 7f3dea244c40159a41ab22da77a434d7c5b5e85a)
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.\" $FreeBSD$
37.\"
38.Dd July 30, 1999
39.Dt DISKLABEL 8
40.Os FreeBSD
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.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.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.Fl s Ar boot2
88.Oc
89.Ar disk Ar protofile
90.Oo Ar disktype Oc
91.Sh DESCRIPTION
92.Nm Disklabel
93installs, examines or modifes the label on a disk drive or pack.  When writing
94the label, it can be used to change the drive identification, the disk
95partitions on the drive, or to replace a damaged label.  There are several forms
96of the command that read (display), install or edit the label on a disk.  In
97addition,
98.Nm
99can install bootstrap code.
100.Ss Raw or in-core label
101.Pp
102The disk label is resident close to or at the beginning of each disk partition.
103For faster access, the kernel maintains a copy in core at all times.  By
104default, most
105.Nm
106access the in-core copy of the label.  To access the raw (on-disk) copy, use the
107.Fl r
108option.  This option allows a label to be installed on a disk without kernel
109support for a label, such as when labels are first installed on a system; it
110must be used when first installing a label on a disk.  The specific effect of
111.Fl r
112is described under each command.
113.Pp
114.Ss Disk device name
115.Pp
116All
117.Nm disklabel
118forms require a disk device name, which should always be the raw
119.if t ``complete'' (or ``c'')
120.if n "complete" (or "c")
121partition, for example
122.Pa /dev/rda0c .
123.Nm
124understands the abbreviation
125.Pa da0 ,
126which it converts internally to
127.Pa /dev/rda0c .
128.Ss Reading the disk label
129.Pp
130To examine or save the label on a disk drive, use
131.Nm
132without options:
133.Pp
134.Nm disklabel
135.Op Fl r
136.Ar disk
137.Pp
138.Ar disk
139represents the raw disk in question, and may be in the form
140.Pa da0
141or
142.Pa /dev/rda0c .
143It will display all of the parameters associated with the drive and its
144partition layout.  Unless the
145.Fl r
146flag is given,
147the kernel's in-core copy of the label is displayed;
148if the disk has no label, or the partition types on the disk are incorrect,
149the kernel may have constructed or modified the label.
150If the
151.Fl r
152flag is given,
153.Nm
154reads the label from the raw disk and displays it.
155.Ss Writing a standard label
156.Pp
157To write a standard label, use the form
158.Pp
159.Nm disklabel
160.Fl w
161.Op Fl r
162.Ar disk Ar disktype
163.Oo Ar packid Oc
164.Pp
165The required arguments to
166.Nm
167are the drive to be labeled and the drive type as described in the
168.Pa disktab(5)
169file.  The drive parameters and partitions are taken from that file.  If
170different disks of the same physical type are to have different partitions, it
171will be necessary to have separate disktab entries describing each, or to edit
172the label after installation as described below.  The optional argument is a
173pack identification string, up to 16 characters long.  The pack id must be
174quoted if it contains blanks.  If the
175.Fl r
176flag is given, the disk sectors containing the label and bootstrap
177will be written directly.
178A side-effect of this is that any existing bootstrap code will be overwritten
179and the disk rendered unbootable.  See the boot options below for a method of
180writing the label and the bootstrap at the same time.
181If
182.Fl r
183is not specified,
184the existing label will be updated via the in-core copy and any bootstrap
185code will be unaffected.
186If the disk does not already have a label, the
187.Fl r
188flag must be used.
189In either case, the kernel's in-core label is replaced.
190.Pp
191For a virgin disk that is not known to
192.Xr disktab 5 ,
193.Ar disktype
194can be specified as
195.Dq auto .
196In this case, the driver is requested to produce a virgin label for the
197disk.  This might or might not be successful, depending on whether the
198driver for the disk is able to get the required data without reading
199anything from the disk at all.  It will likely succeed for all SCSI
200disks, most IDE disks, and vnode devices.  Writing a label to the
201disk is the only supported operation, and the
202.Ar disk
203itself must be provided as the canonical name, i.e. not as a full
204path name.
205.Ss Editing an existing disk label
206.Pp
207To edit an existing disk label, use the form
208.Pp
209.Nm disklabel
210.Fl e
211.Op Fl r
212.Ar disk
213.Pp
214This command reads the label from the in-core kernel copy, or directly from the
215disk if the
216.Fl r
217flag is also specified.  The label is written to a file in ASCII and then
218supplied to an editor for changes.  If no editor is specified in an
219.Ev EDITOR
220environment variable,
221.Xr vi 1
222is used.  When the editor terminates, the label file is used to rewrite the disk
223label.  Existing bootstrap code is unchanged regardless of whether
224.Fl r
225was specified.
226.Ss Restoring a disk label from a file
227.Pp
228To restore a disk label from a file, use the form
229.Pp
230.Nm disklabel
231.Fl R
232.Op Fl r
233.Ar disk Ar protofile
234.Pp
235.Nm
236is capable of restoring a disk label that was previously saved in a file ASCII.
237The prototype file used to create the label should be in the same format as that
238produced when reading or editing a label.  Comments are delimited by
239.Ar \&#
240and newline.  As when writing a new label, any existing bootstrap code will be
241clobbered if
242.Fl r
243is specified and will be unaffected otherwise.  See the boot options below for a
244method of restoring the label and writing the bootstrap at the same time.
245.Ss Enabling and disabling writing to the disk label area
246.Pp
247By default, it is not possible to write to the disk label area at the beginning
248of a disk.  The disk driver silently ignores any attempt to do so.  If you need
249to write to this area (for example, to obliterate the label), use the form
250.Pp
251.Nm disklabel
252.Op Fl W
253.Ar disk
254.Pp
255To disallow writing to the label area after previously allowing it, use the
256command
257.Pp
258.Nm disklabel
259.Op Fl N
260.Ar disk
261.Ss Installing bootstraps
262.Pp
263The final three forms of
264.Nm
265are used to install bootstrap code:
266.Pp
267.Nm disklabel
268.Fl B
269.Oo
270.Fl b Ar boot1
271.Fl s Ar boot2
272.Oc
273.Ar disk
274.Oo Ar disktype Oc
275.Pp
276This form installs the bootstrap only.  It does not change the disk label.
277.Pp
278.Nm disklabel
279.Fl w
280.Fl B
281.Oo
282.Fl b Ar boot1
283.Fl s Ar boot2
284.Oc
285.Ar disk Ar disktype
286.Oo Ar packid Oc
287.Pp
288.if t This form corresponds to the ``write label'' command described above.
289.if n This form corresponds to the "write label" command described above.
290In addition to writing a new volume label, it also installs the bootstrap.
291.Pp
292.Nm disklabel
293.Fl R
294.Fl B
295.Oo
296.Fl b Ar boot1
297.Fl s Ar boot2
298.Oc
299.Ar disk Ar protofile
300.Oo Ar disktype Oc
301.Pp
302.if t This form corresponds to the ``restore label'' command described above.
303.if n This form corresponds to the "restore label" command described above.
304In addition to restoring the volume label, it also installs the bootstrap.
305.Pp
306The bootstrap commands always access the disk directly, so it is not necessary
307to specify the
308.Fl r
309flag.
310.Pp
311The bootstrap code is comprised of two boot programs.  Specify the name of the
312boot programs to be installed in one of these ways:
313.Bl -enum
314.It
315Specify the names explicitly with the
316.Fl b
317and
318.Fl s
319flags.
320.Fl b
321indicates the primary boot program and
322.Fl s
323the secondary boot program.  The boot programs are located in
324.Pa /boot .
325.It
326If the
327.Fl b
328and
329.Fl s
330flags are not specified, but
331.Ar disktype
332was specified, the names of the programs are taken from the
333.if t ``b0'' and ``b1''
334.if n "b0" and "b1"
335parameters of the
336.Xr disktab 5
337entry for the disk if the disktab entry exists and includes those parameters.
338.It
339Otherwise, the default boot image names are used:
340.Pa /boot/boot1
341and
342.Pa /boot/boot2
343for the standard stage1 and stage2 boot images (details may vary
344on architectures like the Alpha, where only a single-stage boot is used).
345.El
346.Sh FILES
347.Bl -tag -width Pa -compact
348.It Pa /etc/disktab
349.It Pa /boot/
350.It Pa /boot/boot<n>
351.El
352.Sh SAVED FILE FORMAT
353.Nm
354uses an ASCII version of the label when examining, editing or restoring a disk
355label.  The format is:
356.Bd -literal -offset 4n
357# /dev/rda1c:
358type: SCSI
359disk: sd0s1
360label:
361flags:
362bytes/sector: 512
363sectors/track: 51
364tracks/cylinder: 19
365sectors/cylinder: 969
366cylinders: 1211
367sectors/unit: 1173930
368rpm: 3600
369interleave: 1
370trackskew: 0
371cylinderskew: 0
372headswitch: 0           # milliseconds
373track-to-track seek: 0  # milliseconds
374drivedata: 0
375
3768 partitions:
377#        size   offset    fstype   [fsize bsize bps/cpg]
378  a:    81920        0    4.2BSD     1024  8192    16   # (Cyl.    0 - 84*)
379  b:   160000    81920      swap                        # (Cyl.   84* - 218*)
380  c:  1173930        0    unused        0     0         # (Cyl.    0 - 1211*)
381  h:   962010   211920     vinum                        # (Cyl.  218*- 1211*)
382.Ed
383.Pp
384Lines starting with a # mark are comments.  Most of the other specifications are
385no longer used.  The ones which must still be set correctly are:
386.Pp
387.Bl -hang -width 20n
388.It Nm label
389is an optional label, set by the
390.Ar packid
391option when writing a label.
392.It Nm flags
393Flags may be
394.Ar removable ,
395.Ar ecc
396or
397.Ar badsect .
398.Ar removable
399is set for removable media drives, but no current FreeBSD driver evaluates this
400flag.
401.Ar ecc
402is no longer supported;
403.Ar badsect
404specifies that the drive can perform bad sector remapping.
405.It Nm sectors/unit
406describes the total size of the disk.  This value must be correct.
407.It Nm the partition table
408This is the UNIX partition table, not the Microsoft partition table described in
409.Xr fdisk 8 .
410.El
411.Pp
412The partition table can have up to 8 entries.  It contains the following
413information:
414.Bl -hang -width 10n
415.It identifier
416The partition identifier is a single letter in the range
417.Nm a
418to
419.Nm h .
420By convention, partition
421.Nm c
422is reserved to describe the entire disk.
423.It size
424is the size of the partition in sectors.
425.It offset
426is the offset of the start of the partition from the beginning of the drive.
427.It fstype
428describes the purpose of the partition.  The example shows most normal usages.
429For UFS file systems, use type 4.2BSD.  See
430.Pa /usr/include/sys/disklabel.h
431for a complete list.
432.It fsize
433For file systems only, the fragment size.
434.It bsize
435For file systems only, the block size.
436.It bps/cpg
437For UFS file systems, the number of cylinders in a cylinder group.  For LFS file
438systems, the segment shift value.
439.El
440The remainder of the line is a comment and shows the cylinder allocations based
441on the obsolete (but possibly correct) geometry information about the drive.
442The asterisk (*) indicates that the partition does not begin or end exactly on a
443cylinder boundary.
444.Sh EXAMPLES
445.Dl disklabel da0
446.Pp
447Display the in-core label for
448.Pa da0
449as obtained via
450.Pa /dev/rda0c .
451.Pp
452.Dl disklabel da0 > savedlabel
453.Pp
454Save the in-core label for
455.Pa da0
456into the file
457.Pa savedlabel .
458This file can be used with the
459.Fl R
460flag to restore the label at a later date.
461.Pp
462.Dl disklabel -w -r /dev/rda0c da2212 foo
463.Pp
464Create a label for
465.Pa da0
466based on information for
467.if t ``da2212'' found in
468.if n "da2212" found in
469.Pa /etc/disktab .
470Any existing bootstrap code will be clobbered.
471.Pp
472.Dl disklabel -e -r da0
473.Pp
474Read the on-disk label for
475.Pa da0 ,
476edit it and reinstall in-core as well as on-disk.  Existing bootstrap code is
477unaffected.
478.Pp
479.Dl disklabel -r -w da0 auto
480.Pp
481Try to auto-detect the required information from
482.Pa da0 ,
483and write a new label to the disk.  Use another disklabel -e command to edit the
484partitioning and file system information.
485.Pp
486.Dl disklabel -R da0 savedlabel
487.Pp
488Restore the on-disk and in-core label for
489.Pa da0
490from information in
491.Pa savedlabel .
492Existing bootstrap code is unaffected.
493.Pp
494.Dl disklabel -B da0
495.Pp
496Install a new bootstrap on
497.Pa da0 .
498The boot code comes from
499.Pa /boot/boot1
500and possibly
501.Pa /boot/boot2 .
502On-disk and in-core labels are unchanged.
503.Pp
504.Dl disklabel -w -B /dev/rda0c -b newboot1 -s newboot da2212
505.Pp
506Install a new label and bootstrap.
507.if t The label is derived from disktab information for ``da2212'' and
508.if n The label is derived from disktab information for "da2212" and
509installed both in-core and on-disk.
510The bootstrap code comes from the files
511.Pa /boot/newboot1
512and
513.Pa /boot/newboot2 .
514.Sh SEE ALSO
515.Xr disklabel 5 ,
516.Xr disktab 5 ,
517.Xr boot0cfg 8 ,
518.Xr fdisk 8
519.Sh DIAGNOSTICS
520The kernel device drivers will not allow the size of a disk partition
521to be decreased or the offset of a partition to be changed while it is open.
522Some device drivers create a label containing only a single large partition
523if a disk is unlabeled; thus, the label must be written to the
524.if t ``a''
525.if n "a"
526partition of the disk while it is open.  This sometimes requires the desired
527label to be set in two steps, the first one creating at least one other
528partition, and the second setting the label on the new partition while shrinking
529the
530.if t ``a''
531.if n "a"
532partition.
533.Pp
534On some machines the bootstrap code may not fit entirely in the area
535allocated for it by some filesystems.
536As a result, it may not be possible to have filesystems on some partitions
537.if t of a ``bootable'' disk.
538.if n of a "bootable" disk.
539When installing bootstrap code,
540.Nm
541checks for these cases.
542If the installed boot code would overlap a partition of type FS_UNUSED
543it is marked as type FS_BOOT.
544The
545.Xr newfs 8
546utility will disallow creation of filesystems on FS_BOOT partitions.
547Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT,
548.Nm
549will not install bootstrap code that overlaps it.
550.Sh BUGS
551When a disk name is given without a full pathname,
552.if t the constructed device name uses the ``c'' partition.
553.if n the constructed device name uses the "c" partition.
554.Pp
555For the i386 architecture, the primary bootstrap sector contains
556an embedded
557.Em fdisk
558table.
559.Nm Disklabel
560takes care to not clobber it when installing a bootstrap only
561.Pq Fl B ,
562or when editing an existing label
563.Pq Fl e ,
564but it unconditionally writes the primary bootstrap program onto
565the disk for
566.Fl w
567or
568.Fl R ,
569thus replacing the
570.Em fdisk
571table by the dummy one in the bootstrap program.  This is only of
572concern if the disk is fully dedicated, so that the BSD disklabel
573starts at absolute block 0 on the disk.
574.Pp
575.Nm
576does not perform adequate error checking.  No warning is given if partitions
577overlap, nor if space remains unused.
578