xref: /freebsd/sbin/bsdlabel/bsdlabel.8 (revision 817420dc8eac7df799c78f5309b75092b7f7cd40)
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
46.Op Fl r
47.Ar disk
48.Nm
49.Fl w
50.Op Fl r
51.Ar disk Ar disktype/auto
52.Oo Ar packid Oc
53.Nm
54.Fl e
55.Op Fl r
56.Ar disk
57.Nm
58.Fl R
59.Op Fl r
60.Ar disk Ar protofile
61.Nm
62.Op Fl NW
63.Ar disk
64.Pp
65.Nm
66.Fl B
67.Oo
68.Fl b Ar boot1
69.Fl s Ar boot2
70.Oc
71.Ar disk
72.Oo Ar disktype/auto Oc
73.Nm
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/auto
81.Oo Ar packid Oc
82.Nm
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/auto 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
118forms require a disk device name, which should always be the raw
119device name representing the disk or slice.  For example
120.Pa da0
121represents the entire disk irregardless of any DOS partitioning,
122and
123.Pa da0s1
124represents a slice.  Some devices, most notably
125.Ar ccd ,
126require that the
127.Dq whole-disk
128(or
129.Dq c )
130partition be specified.  For example
131.Pa ccd0c .
132You do not have to include the
133.Pa /dev/
134path prefix when specifying the device.
135.Nm
136will automatically prepend it.
137.Ss Reading the disk label
138.Pp
139To examine or save the label on a disk drive, use
140.Nm
141without options:
142.Pp
143.Nm
144.Op Fl r
145.Ar disk
146.Pp
147.Ar disk
148represents the raw disk in question, and may be in the form
149.Pa da0
150or
151.Pa /dev/da0c .
152It will display all of the parameters associated with the drive and its
153partition layout.  Unless the
154.Fl r
155flag is given,
156the kernel's in-core copy of the label is displayed;
157if the disk has no label, or the partition types on the disk are incorrect,
158the kernel may have constructed or modified the label.
159If the
160.Fl r
161flag is given,
162.Nm
163reads the label from the raw disk and displays it.  Both versions are usually
164identical except in the case where a label has not yet been initialized or
165is corrupt.
166.Ss Writing a standard label
167.Pp
168To write a standard label, use the form
169.Pp
170.Nm
171.Fl w
172.Op Fl r
173.Ar disk Ar disktype/auto
174.Oo Ar packid Oc
175.Pp
176.Nm
177.Fl w
178.Op Fl r
179.Ar disk
180auto
181.Pp
182The required arguments to
183.Nm
184are the drive to be labeled and the drive type as described in the
185.Pa disktab(5)
186file.  The drive parameters and partitions are taken from that file.  If
187different disks of the same physical type are to have different partitions, it
188will be necessary to have separate disktab entries describing each, or to edit
189the label after installation as described below.  The optional argument is a
190pack identification string, up to 16 characters long.  The pack id must be
191quoted if it contains blanks.  If the
192.Fl r
193flag is given, the disk sectors containing the label and bootstrap
194will be written directly.
195A side-effect of this is that any existing bootstrap code will be overwritten
196and the disk rendered unbootable.  See the boot options below for a method of
197writing the label and the bootstrap at the same time.
198If
199.Fl r
200is not specified,
201the existing label will be updated via the in-core copy and any bootstrap
202code will be unaffected.
203If the disk does not already have a label, the
204.Fl r
205flag must be used.
206In either case, the kernel's in-core label is replaced.
207.Pp
208For a virgin disk that is not known to
209.Xr disktab 5 ,
210.Ar disktype
211can be specified as
212.Dq auto .
213In this case, the driver is requested to produce a virgin label for the
214disk.  This might or might not be successful, depending on whether the
215driver for the disk is able to get the required data without reading
216anything from the disk at all.  It will likely succeed for all SCSI
217disks, most IDE disks, and vnode devices.  Writing a label to the
218disk is the only supported operation, and the
219.Ar disk
220itself must be provided as the canonical name, i.e. not as a full
221path name.
222.Pp
223PC-based systems have special requirements in order for the BIOS to properly
224recognize a
225.Fx
226disklabel.  Older systems may require what is known as a
227.Dq dangerously dedicated
228disklabel, which creates a fake DOS partition to work around problems older
229BIOSes have with modern disk geometries.  On newer systems you generally want
230to create a normal DOS slice using
231.Ar fdisk
232and then create a
233.Fx
234disklabel within that slice.  This is described
235later on in this page.
236.Pp
237Installing a new disklabel does not in of itself allow your system to boot
238a kernel using that label.  You must also install boot blocks, which is
239described later on in this manual page.
240.Ss Editing an existing disk label
241.Pp
242To edit an existing disk label, use the form
243.Pp
244.Nm
245.Fl e
246.Op Fl r
247.Ar disk
248.Pp
249This command reads the label from the in-core kernel copy, or directly from the
250disk if the
251.Fl r
252flag is also specified.  The label is written to a file in ASCII and then
253supplied to an editor for changes.  If no editor is specified in an
254.Ev EDITOR
255environment variable,
256.Xr vi 1
257is used.  When the editor terminates, the label file is used to rewrite the disk
258label.  Existing bootstrap code is unchanged regardless of whether
259.Fl r
260was specified.
261.Ss Restoring a disk label from a file
262.Pp
263To restore a disk label from a file, use the form
264.Pp
265.Nm
266.Fl R
267.Op Fl r
268.Ar disk Ar protofile
269.Pp
270.Nm
271is capable of restoring a disk label that was previously saved in a file in ASCII format.
272The prototype file used to create the label should be in the same format as that
273produced when reading or editing a label.  Comments are delimited by
274.Ar \&#
275and newline.  As when writing a new label, any existing bootstrap code will be
276clobbered if
277.Fl r
278is specified and will be unaffected otherwise.  See the boot options below for a
279method of restoring the label and writing the bootstrap at the same time.
280.Ss Enabling and disabling writing to the disk label area
281.Pp
282By default, it is not possible to write to the disk label area at the beginning
283of a disk.  The disk driver silently ignores any attempt to do so.  If you need
284to write to this area (for example, to obliterate the label), use the form
285.Pp
286.Nm
287.Op Fl W
288.Ar disk
289.Pp
290To disallow writing to the label area after previously allowing it, use the
291command
292.Pp
293.Nm
294.Op Fl N
295.Ar disk
296.Ss Installing bootstraps
297.Pp
298The final three forms of
299.Nm
300are used to install bootstrap code.  If you are creating a
301.Dq dangerously-dedicated
302partition for compatibility with older PC systems,
303you generally want to specify the raw disk name such as
304.Pa da0.
305If you are creating a label within an existing DOS slice, you should specify
306the slice name such as
307.Pa da0s1 .
308Making a partition bootable can be tricky.  If you are using a normal DOS
309slice you typically install (or leave) a standard MBR on the base disk and
310then install the
311.Fx
312bootblocks in the slice.
313.Pp
314.Nm
315.Fl B
316.Oo
317.Fl b Ar boot1
318.Fl s Ar boot2
319.Oc
320.Ar disk
321.Oo Ar disktype Oc
322.Pp
323This form installs the bootstrap only.  It does not change the disk label.
324You should never use this command on a base disk unless you intend to create a
325.Dq dangerously-dedicated
326disk, such as
327.Ar da0 .
328This command is typically run on a slice such as
329.Ar da0s1 .
330.Pp
331.Nm
332.Fl w
333.Fl B
334.Oo
335.Fl b Ar boot1
336.Fl s Ar boot2
337.Oc
338.Ar disk Ar disktype
339.Oo Ar packid Oc
340.Pp
341This form corresponds to the
342.Dq write label
343command described above.
344In addition to writing a new volume label, it also installs the bootstrap.
345If run on a base disk this command will create a
346.Dq dangerously-dedicated
347label.  This command is normally run on a slice rather then a base disk.
348.Pp
349.Nm
350.Fl R
351.Fl B
352.Oo
353.Fl b Ar boot1
354.Fl s Ar boot2
355.Oc
356.Ar disk Ar protofile
357.Oo Ar disktype Oc
358.Pp
359This form corresponds to the
360.Dq restore label
361command described above.
362In addition to restoring the volume label, it also installs the bootstrap.
363If run on a base disk this command will create a
364.Dq dangerously-dedicated
365label.  This command is normally run on a slice rather then a base disk.
366.Pp
367The bootstrap commands always access the disk directly, so it is not necessary
368to specify the
369.Fl r
370flag.
371.Pp
372The bootstrap code is comprised of two boot programs.  Specify the name of the
373boot programs to be installed in one of these ways:
374.Bl -enum
375.It
376Specify the names explicitly with the
377.Fl b
378and
379.Fl s
380flags.
381.Fl b
382indicates the primary boot program and
383.Fl s
384the secondary boot program.  The boot programs are located in
385.Pa /boot .
386.It
387If the
388.Fl b
389and
390.Fl s
391flags are not specified, but
392.Ar disktype
393was specified, the names of the programs are taken from the
394.Dq b0
395and
396.Dq b1
397parameters of the
398.Xr disktab 5
399entry for the disk if the disktab entry exists and includes those parameters.
400.It
401Otherwise, the default boot image names are used:
402.Pa /boot/boot1
403and
404.Pa /boot/boot2
405for the standard stage1 and stage2 boot images (details may vary
406on architectures like the Alpha, where only a single-stage boot is used).
407.El
408.Ss Initializing/Formatting a bootable disk from scratch
409.Pp
410To initialize a disk from scratch the following sequence is recommended.
411Please note that this will wipe everything that was previously on the disk,
412including any
413.No non- Ns Fx
414slices.
415.Bl -enum
416.It
417Use
418.Ar fdisk
419to initialize the DOS partition table, creating a real whole-disk slice to
420hold the
421.Fx
422disklabel, and installing a master boot record.
423.It
424Use
425.Ar disklabel
426to initialize a virgin
427.Fx
428disklabel and install
429.Fx
430boot blocks.
431.It
432Use
433.Ar disklabel
434to edit your newly created label, addiing appropriate partitions.
435.It
436Finally newfs the filesystem partitions you created in the label.  A typical
437disklabel partiioning scheme would be to have an
438.Dq a
439partition
440of approximately 128MB to hold the root filesystem, a
441.Dq b
442partition for
443swap, a
444.Dq d
445partition for /var (usually 128MB), an
446.Dq e
447partition
448for /var/tmp (usually 128MB), an
449.Dq f
450partition for /usr (usually around 2G),
451and finally a
452.Dq g
453partition for /home (usally all remaining space).
454Your mileage may vary.
455.El
456.Pp
457.Nm fdisk Fl BI Ar da0
458.Pp
459.Nm
460.Fl w
461.Fl r
462.Fl B
463.Ar da0s1
464auto
465.Pp
466.Pp
467.Nm
468.Fl e
469.Ar da0s1
470.Pp
471.Sh FILES
472.Bl -tag -width Pa -compact
473.It Pa /etc/disktab
474.It Pa /boot/
475.It Pa /boot/boot<n>
476.El
477.Sh SAVED FILE FORMAT
478.Nm
479uses an ASCII version of the label when examining, editing or restoring a disk
480label.  The format is:
481.Bd -literal -offset 4n
482# /dev/da1c:
483type: SCSI
484disk: da0s1
485label:
486flags:
487bytes/sector: 512
488sectors/track: 51
489tracks/cylinder: 19
490sectors/cylinder: 969
491cylinders: 1211
492sectors/unit: 1173930
493rpm: 3600
494interleave: 1
495trackskew: 0
496cylinderskew: 0
497headswitch: 0           # milliseconds
498track-to-track seek: 0  # milliseconds
499drivedata: 0
500
5018 partitions:
502#        size   offset    fstype   [fsize bsize bps/cpg]
503  a:    81920        0    4.2BSD     1024  8192    16   # (Cyl.    0 - 84*)
504  b:   160000    81920      swap                        # (Cyl.   84* - 218*)
505  c:  1173930        0    unused        0     0         # (Cyl.    0 - 1211*)
506  h:   962010   211920     vinum                        # (Cyl.  218*- 1211*)
507.Ed
508.Pp
509Lines starting with a # mark are comments.  Most of the other specifications are
510no longer used.  The ones which must still be set correctly are:
511.Pp
512.Bl -hang -width 20n
513.It Nm label
514is an optional label, set by the
515.Ar packid
516option when writing a label.
517.It Nm flags
518Flags may be
519.Ar removable ,
520.Ar ecc
521or
522.Ar badsect .
523.Ar removable
524is set for removable media drives, but no current
525.Fx
526driver evaluates this
527flag.
528.Ar ecc
529is no longer supported;
530.Ar badsect
531specifies that the drive can perform bad sector remapping.
532.It Nm sectors/unit
533describes the total size of the disk.  This value must be correct.
534.It Nm the partition table
535This is the UNIX partition table, not the Microsoft partition table described in
536.Xr fdisk 8 .
537.El
538.Pp
539The partition table can have up to 8 entries.  It contains the following
540information:
541.Bl -hang -width 10n
542.It identifier
543The partition identifier is a single letter in the range
544.Nm a
545to
546.Nm h .
547By convention, partition
548.Nm c
549is reserved to describe the entire disk.
550.It size
551is the size of the partition in sectors.
552.It offset
553is the offset of the start of the partition from the beginning of the drive.
554.It fstype
555describes the purpose of the partition.  The example shows most normal usages.
556For UFS file systems, use type 4.2BSD.  See
557.Pa /usr/include/sys/disklabel.h
558for a complete list.
559.It fsize
560For file systems only, the fragment size.
561.It bsize
562For file systems only, the block size.
563.It bps/cpg
564For UFS file systems, the number of cylinders in a cylinder group.  For LFS file
565systems, the segment shift value.
566.El
567The remainder of the line is a comment and shows the cylinder allocations based
568on the obsolete (but possibly correct) geometry information about the drive.
569The asterisk (*) indicates that the partition does not begin or end exactly on a
570cylinder boundary.
571.Sh EXAMPLES
572.Dl disklabel da0
573.Pp
574Display the in-core label for
575.Pa da0s1
576as obtained via
577.Pa /dev/da0s1 .
578When reading a label,
579.Fx
580will allow you to specify the base disk name
581even if the label resides on a slice.  However, to be proper you should
582specify the base disk name only if you are using a
583.Dq dangerously-dedicated
584label.  Normally you specify the slice.
585.Pp
586.Dl disklabel da0s1 > savedlabel
587.Pp
588Save the in-core label for
589.Pa da0s1
590into the file
591.Pa savedlabel .
592This file can be used with the
593.Fl R
594flag to restore the label at a later date.
595.Pp
596.Dl disklabel -w -r /dev/da0s1 da2212 foo
597.Pp
598Create a label for
599.Pa da0s1
600based on information for
601.Dq da2212
602found in
603.Pa /etc/disktab .
604Any existing bootstrap code will be clobbered.
605.Pp
606.Dl disklabel -e -r da0s1
607.Pp
608Read the on-disk label for
609.Pa da0s1 ,
610edit it and reinstall in-core as well as on-disk.  Existing bootstrap code is
611unaffected.
612.Pp
613.Dl disklabel -r -w da0s1 auto
614.Pp
615Try to auto-detect the required information from
616.Pa da0s1 ,
617and write a new label to the disk.  Use another disklabel -e command to edit the
618partitioning and file system information.
619.Pp
620.Dl disklabel -R da0s1 savedlabel
621.Pp
622Restore the on-disk and in-core label for
623.Pa da0s1
624from information in
625.Pa savedlabel .
626Existing bootstrap code is unaffected.
627.Pp
628.Dl disklabel -B da0s1
629.Pp
630Install a new bootstrap on
631.Pa da0s1 .
632The boot code comes from
633.Pa /boot/boot1
634and possibly
635.Pa /boot/boot2 .
636On-disk and in-core labels are unchanged.
637.Pp
638.Dl disklabel -w -B /dev/da0s1 -b newboot1 -s newboot da2212
639.Pp
640Install a new label and bootstrap.
641The label is derived from disktab information for
642.Dq da2212
643and installed both in-core and on-disk.
644The bootstrap code comes from the files
645.Pa /boot/newboot1
646and
647.Pa /boot/newboot2 .
648.Pp
649.Dl dd if=/dev/zero of=/dev/da0 bs=512 count=32
650.Dl fdisk -BI da0
651.Dl dd if=/dev/zero of=/dev/da0s1 bs=512 count=32
652.Dl disklabel -w -r -B da0s1 auto
653.Dl disklabel -e da0s1
654.Pp
655Completely wipe any prior information on the disk, creating a new bootable
656disk with a DOS partition table containing one
657.Dq whole-disk
658slice.  Then
659initialize the slice, then edit it to your needs.  The
660.Pa dd
661commands are optional, but may be necessary for some BIOSes to properly
662recognize the disk.
663.Sh SEE ALSO
664.Xr disklabel 5 ,
665.Xr disktab 5 ,
666.Xr boot0cfg 8 ,
667.Xr fdisk 8
668.Sh DIAGNOSTICS
669The kernel device drivers will not allow the size of a disk partition
670to be decreased or the offset of a partition to be changed while it is open.
671Some device drivers create a label containing only a single large partition
672if a disk is unlabeled; thus, the label must be written to the
673.Dq a
674partition of the disk while it is open.  This sometimes requires the desired
675label to be set in two steps, the first one creating at least one other
676partition, and the second setting the label on the new partition while shrinking
677the
678.Dq a
679partition.
680.Pp
681On some machines the bootstrap code may not fit entirely in the area
682allocated for it by some filesystems.
683As a result, it may not be possible to have filesystems on some partitions
684of a
685.Dq bootable
686disk.
687When installing bootstrap code,
688.Nm
689checks for these cases.
690If the installed boot code would overlap a partition of type FS_UNUSED
691it is marked as type FS_BOOT.
692The
693.Xr newfs 8
694utility will disallow creation of filesystems on FS_BOOT partitions.
695Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT,
696.Nm
697will not install bootstrap code that overlaps it.
698.Sh BUGS
699When a disk name is given without a full pathname,
700the constructed device name uses the
701.Dq c
702partition.
703.Pp
704For the i386 architecture, the primary bootstrap sector contains
705an embedded
706.Em fdisk
707table.
708.Nm Disklabel
709takes care to not clobber it when installing a bootstrap only
710.Pq Fl B ,
711or when editing an existing label
712.Pq Fl e ,
713but it unconditionally writes the primary bootstrap program onto
714the disk for
715.Fl w
716or
717.Fl R ,
718thus replacing the
719.Em fdisk
720table by the dummy one in the bootstrap program.  This is only of
721concern if the disk is fully dedicated, so that the BSD disklabel
722starts at absolute block 0 on the disk.
723.Pp
724.Nm
725does not perform adequate error checking.  No warning is given if partitions
726overlap, nor if space remains unused.
727