cb07dde752bdabe2ece9a3039cc04c715c41a6d0
[dragonfly.git] / sbin / disklabel / disklabel.8
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: src/sbin/disklabel/disklabel.8,v 1.15.2.22 2003/04/17 17:56:34 trhodes Exp $
37 .\" $DragonFly: src/sbin/disklabel/disklabel.8,v 1.2 2003/06/17 04:27:32 dillon Exp $
38 .\"
39 .Dd July 30, 1999
40 .Dt DISKLABEL 8
41 .Os
42 .Sh NAME
43 .Nm disklabel
44 .Nd read and write disk pack label
45 .Sh SYNOPSIS
46 .Nm
47 .Op Fl r
48 .Ar disk
49 .Nm
50 .Fl w
51 .Op Fl r
52 .Op Fl n
53 .Ar disk Ar disktype/auto
54 .Oo Ar packid Oc
55 .Nm
56 .Fl e
57 .Op Fl r
58 .Op Fl n
59 .Ar disk
60 .Nm
61 .Fl R
62 .Op Fl r
63 .Op Fl n
64 .Ar disk Ar protofile
65 .Nm
66 .Op Fl NW
67 .Ar disk
68 .Pp
69 .Nm
70 .Fl B
71 .Oo
72 .Fl b Ar boot1
73 .Fl s Ar boot2
74 .Oc
75 .Ar disk
76 .Oo Ar disktype/auto Oc
77 .Nm
78 .Fl w
79 .Fl B
80 .Op Fl n
81 .Oo
82 .Fl b Ar boot1
83 .Fl s Ar boot2
84 .Oc
85 .Ar disk Ar disktype/auto
86 .Oo Ar packid Oc
87 .Nm
88 .Fl R
89 .Fl B
90 .Op Fl n
91 .Oo
92 .Fl b Ar boot1
93 .Fl s Ar boot2
94 .Oc
95 .Ar disk Ar protofile
96 .Oo Ar disktype/auto Oc
97 .Sh DESCRIPTION
98 The
99 .Nm
100 utility
101 installs, examines or modifies the label on a disk drive or pack.  When writing
102 the label, it can be used to change the drive identification, the disk
103 partitions on the drive, or to replace a damaged label.  There are several forms
104 of the command that read (display), install or edit the label on a disk.  In
105 addition,
106 .Nm
107 can install bootstrap code.
108 .Ss Raw or in-core label
109 .Pp
110 The disk label resides close to or at the beginning of each disk slice.
111 For faster access, the kernel maintains a copy in core at all times.  By
112 default, most
113 .Nm
114 access the in-core copy of the label.  To access the raw (on-disk) copy, use the
115 .Fl r
116 option.  This option allows a label to be installed on a disk without kernel
117 support for a label, such as when labels are first installed on a system; it
118 must be used when first installing a label on a disk.  The specific effect of
119 .Fl r
120 is described under each command.
121 .Pp
122 .Ss Disk device name
123 .Pp
124 All
125 .Nm
126 forms require a disk device name, which should always be the raw
127 device name representing the disk or slice.  For example
128 .Pa da0
129 represents the entire disk regardless of any DOS partitioning,
130 and
131 .Pa da0s1
132 represents a slice.  Some devices, most notably
133 .Ar ccd ,
134 require that the
135 .Dq whole-disk
136 (or
137 .Dq c )
138 partition be specified.  For example
139 .Pa ccd0c .
140 You do not have to include the
141 .Pa /dev/
142 path prefix when specifying the device.
143 The
144 .Nm
145 utility will automatically prepend it.
146 .Ss Reading the disk label
147 .Pp
148 To examine the label on a disk drive, use
149 .Nm
150 without options:
151 .Pp
152 .Nm
153 .Op Fl r
154 .Ar disk
155 .Pp
156 .Ar disk
157 represents the raw disk in question, and may be in the form
158 .Pa da0
159 or
160 .Pa /dev/da0c .
161 It will display all of the parameters associated with the drive and its
162 partition layout.  Unless the
163 .Fl r
164 flag is given,
165 the kernel's in-core copy of the label is displayed;
166 if the disk has no label, or the partition types on the disk are incorrect,
167 the kernel may have constructed or modified the label.
168 If the
169 .Fl r
170 flag is given,
171 .Nm
172 reads the label from the raw disk and displays it.  Both versions are usually
173 identical except in the case where a label has not yet been initialized or
174 is corrupt.
175 .Ss Writing a standard label
176 .Pp
177 To write a standard label, use the form
178 .Pp
179 .Nm
180 .Fl w
181 .Op Fl r
182 .Op Fl n
183 .Ar disk Ar disktype/auto
184 .Oo Ar packid Oc
185 .Pp
186 .Nm
187 .Fl w
188 .Op Fl r
189 .Op Fl n
190 .Ar disk
191 auto
192 .Pp
193 The required arguments to
194 .Nm
195 are the drive to be labeled and the drive type as described in the
196 .Xr disktab 5
197 file.  The drive parameters and partitions are taken from that file.  If
198 different disks of the same physical type are to have different partitions, it
199 will be necessary to have separate disktab entries describing each, or to edit
200 the label after installation as described below.  The optional argument is a
201 pack identification string, up to 16 characters long.  The pack id must be
202 quoted if it contains blanks.
203 .Pp
204 If the
205 .Fl n
206 flag is given, no data will be written to the device, and instead the
207 disklabel that would have been written will be printed to stdout.
208 .Pp
209 If the
210 .Fl r
211 flag is given, the disk sectors containing the label and bootstrap
212 will be written directly.
213 A side-effect of this is that any existing bootstrap code will be overwritten
214 and the disk rendered unbootable.  See the boot options below for a method of
215 writing the label and the bootstrap at the same time.
216 If
217 .Fl r
218 is not specified,
219 the existing label will be updated via the in-core copy and any bootstrap
220 code will be unaffected.
221 If the disk does not already have a label, the
222 .Fl r
223 flag must be used.
224 In either case, the kernel's in-core label is replaced.
225 .Pp
226 For a virgin disk that is not known to
227 .Xr disktab 5 ,
228 .Ar disktype
229 can be specified as
230 .Dq auto .
231 In this case, the driver is requested to produce a virgin label for the
232 disk.  This might or might not be successful, depending on whether the
233 driver for the disk is able to get the required data without reading
234 anything from the disk at all.  It will likely succeed for all SCSI
235 disks, most IDE disks, and vnode devices.  Writing a label to the
236 disk is the only supported operation, and the
237 .Ar disk
238 itself must be provided as the canonical name, i.e. not as a full
239 path name.
240 .Pp
241 For most harddisks, a label based on percentages for most partitions (and
242 one partition with a size of
243 .Ql * )
244 will produce a reasonable configuration.
245 .Pp
246 PC-based systems have special requirements in order for the BIOS to properly
247 recognize a
248 .Fx
249 disklabel.  Older systems may require what is known as a
250 .Dq dangerously dedicated
251 disklabel, which creates a fake DOS partition to work around problems older
252 BIOSes have with modern disk geometries.
253 On newer systems you generally want
254 to create a normal DOS partition using
255 .Ar fdisk
256 and then create a
257 .Fx
258 disklabel within that slice.  This is described
259 later on in this page.
260 .Pp
261 Installing a new disklabel does not in of itself allow your system to boot
262 a kernel using that label.  You must also install boot blocks, which is
263 described later on in this manual page.
264 .Ss Editing an existing disk label
265 .Pp
266 To edit an existing disk label, use the form
267 .Pp
268 .Nm
269 .Fl e
270 .Op Fl r
271 .Op Fl n
272 .Ar disk
273 .Pp
274 This command reads the label from the in-core kernel copy, or directly from the
275 disk if the
276 .Fl r
277 flag is also specified.  The label is written to a file in ASCII and then
278 supplied to an editor for changes.  If no editor is specified in an
279 .Ev EDITOR
280 environment variable,
281 .Xr vi 1
282 is used.  When the editor terminates, the label file is used to rewrite the disk
283 label.  Existing bootstrap code is unchanged regardless of whether
284 .Fl r
285 was specified.  If
286 .Fl n
287 is specified, no data will be written to the device, and instead the
288 disklabel that would have been written will be printed to stdout.  This is
289 useful to see how a partitioning scheme will work out for a specific disk.
290 .Ss Restoring a disk label from a file
291 .Pp
292 To restore a disk label from a file, use the form
293 .Pp
294 .Nm
295 .Fl R
296 .Op Fl r
297 .Op Fl n
298 .Ar disk Ar protofile
299 .Pp
300 .Nm
301 is capable of restoring a disk label that was previously saved in a file in ASCII format.
302 The prototype file used to create the label should be in the same format as that
303 produced when reading or editing a label.  Comments are delimited by
304 .Ar \&#
305 and newline.  As when writing a new label, any existing bootstrap code will be
306 clobbered if
307 .Fl r
308 is specified and will be unaffected otherwise.  See the boot options below for a
309 method of restoring the label and writing the bootstrap at the same time.
310 If
311 .Fl n
312 is used, no data will be written to the device, and instead the
313 disklabel that would have been written will be printed to stdout.  This is
314 useful to see how a partitioning scheme will work out for a specific disk.
315 .Ss Enabling and disabling writing to the disk label area
316 .Pp
317 By default, it is not possible to write to the disk label area at the beginning
318 of a disk.  The disk driver arranges for
319 .Xr write 2
320 and similar system calls
321 to return
322 .Er EROFS
323 on any attempt to do so.  If you need
324 to write to this area (for example, to obliterate the label), use the form
325 .Pp
326 .Nm
327 .Fl W
328 .Ar disk
329 .Pp
330 To disallow writing to the label area after previously allowing it, use the
331 command
332 .Pp
333 .Nm
334 .Fl N
335 .Ar disk
336 .Ss Installing bootstraps
337 .Pp
338 The final three forms of
339 .Nm
340 are used to install bootstrap code.  If you are creating a
341 .Dq dangerously-dedicated
342 slice for compatibility with older PC systems,
343 you generally want to specify the raw disk name such as
344 .Pa da0 .
345 If you are creating a label within an existing DOS slice,
346 you should specify
347 the partition name such as
348 .Pa da0s1a .
349 Making a slice bootable can be tricky.  If you are using a normal DOS
350 slice you typically install (or leave) a standard MBR on the base disk and
351 then install the
352 .Fx
353 bootblocks in the slice.
354 .Pp
355 .Nm
356 .Fl B
357 .Oo
358 .Fl b Ar boot1
359 .Fl s Ar boot2
360 .Oc
361 .Ar disk
362 .Oo Ar disktype Oc
363 .Pp
364 This form installs the bootstrap only.  It does not change the disk label.
365 You should never use this command on a base disk unless you intend to create a
366 .Dq dangerously-dedicated
367 disk, such as
368 .Ar da0 .
369 This command is typically run on a slice such as
370 .Ar da0s1 .
371 .Pp
372 .Nm
373 .Fl w
374 .Fl B
375 .Op Fl n
376 .Oo
377 .Fl b Ar boot1
378 .Fl s Ar boot2
379 .Oc
380 .Ar disk Ar disktype
381 .Oo Ar packid Oc
382 .Pp
383 This form corresponds to the
384 .Dq write label
385 command described above.
386 In addition to writing a new volume label, it also installs the bootstrap.
387 If run on a base disk this command will create a
388 .Dq dangerously-dedicated
389 label.  This command is normally run on a slice rather than a base disk.
390 If
391 .Fl n
392 is used, no data will be written to the device, and instead the
393 disklabel that would have been written will be printed to stdout.
394 .Pp
395 .Nm
396 .Fl R
397 .Fl B
398 .Op Fl n
399 .Oo
400 .Fl b Ar boot1
401 .Fl s Ar boot2
402 .Oc
403 .Ar disk Ar protofile
404 .Oo Ar disktype Oc
405 .Pp
406 This form corresponds to the
407 .Dq restore label
408 command described above.
409 In addition to restoring the volume label, it also installs the bootstrap.
410 If run on a base disk this command will create a
411 .Dq dangerously-dedicated
412 label.  This command is normally run on a slice rather than a base disk.
413 .Pp
414 The bootstrap commands always access the disk directly, so it is not necessary
415 to specify the
416 .Fl r
417 flag.  If
418 .Fl n
419 is used, no data will be written to the device, and instead the
420 disklabel that would have been written will be printed to stdout.
421 .Pp
422 The bootstrap code is comprised of two boot programs.  Specify the name of the
423 boot programs to be installed in one of these ways:
424 .Bl -enum
425 .It
426 Specify the names explicitly with the
427 .Fl b
428 and
429 .Fl s
430 flags.
431 .Fl b
432 indicates the primary boot program and
433 .Fl s
434 the secondary boot program.  The boot programs are located in
435 .Pa /boot .
436 .It
437 If the
438 .Fl b
439 and
440 .Fl s
441 flags are not specified, but
442 .Ar disktype
443 was specified, the names of the programs are taken from the
444 .Dq b0
445 and
446 .Dq b1
447 parameters of the
448 .Xr disktab 5
449 entry for the disk if the disktab entry exists and includes those parameters.
450 .It
451 Otherwise, the default boot image names are used:
452 .Pa /boot/boot1
453 and
454 .Pa /boot/boot2
455 for the standard stage1 and stage2 boot images (details may vary
456 on architectures like the Alpha, where only a single-stage boot is used).
457 .El
458 .Ss Initializing/Formatting a bootable disk from scratch
459 .Pp
460 To initialize a disk from scratch the following sequence is recommended.
461 Please note that this will wipe everything that was previously on the disk,
462 including any
463 .No non- Ns Fx
464 slices.
465 .Bl -enum
466 .It
467 Use
468 .Xr fdisk 8
469 to initialize the hard disk, and create a slice table, referred to
470 as the
471 .Dq "partition table"
472 in
473 .Tn DOS .
474 .It
475 Use
476 .Nm
477 to define partitions on
478 .Fx
479 slices created in the previous step.
480 .It
481 Finally use
482 .Xr newfs 8
483 to create file systems on new partitions.
484 .El
485 .Pp
486 A typical partitioning scheme would be to have an
487 .Ql a
488 partition
489 of approximately 128MB to hold the root file system, a
490 .Ql b
491 partition for
492 swap, a
493 .Ql d
494 partition for
495 .Pa /var
496 (usually 128MB), an
497 .Ql e
498 partition
499 for
500 .Pa /var/tmp
501 (usually 128MB), an
502 .Ql f
503 partition for
504 .Pa /usr
505 (usually around 2GB),
506 and finally a
507 .Ql g
508 partition for
509 .Pa /home
510 (usually all remaining space).
511 Your mileage may vary.
512 .Pp
513 .Nm fdisk Fl BI Pa da0
514 .Pp
515 .Nm
516 .Fl w B
517 .Pa da0s1
518 .Cm auto
519 .Pp
520 .Nm
521 .Fl e
522 .Pa da0s1
523 .Sh FILES
524 .Bl -tag -width ".Pa /etc/disktab" -compact
525 .It Pa /boot/boot
526 Default boot image.
527 .It Pa /etc/disktab
528 Disk description file.
529 .El
530 .Sh SAVED FILE FORMAT
531 The
532 .Nm
533 utility
534 uses an
535 .Tn ASCII
536 version of the label when examining, editing, or restoring a disk
537 label.
538 The format is:
539 .Bd -literal -offset 4n
540 # /dev/da1c:
541 type: SCSI
542 disk: da0s1
543 label:
544 flags:
545 bytes/sector: 512
546 sectors/track: 51
547 tracks/cylinder: 19
548 sectors/cylinder: 969
549 cylinders: 1211
550 sectors/unit: 1173930
551 rpm: 3600
552 interleave: 1
553 trackskew: 0
554 cylinderskew: 0
555 headswitch: 0           # milliseconds
556 track-to-track seek: 0  # milliseconds
557 drivedata: 0
558
559 8 partitions:
560 #        size   offset    fstype   [fsize bsize bps/cpg]
561   a:    81920        0    4.2BSD     1024  8192    16   # (Cyl.    0 - 84*)
562   b:   160000    81920      swap                        # (Cyl.   84* - 218*)
563   c:  1173930        0    unused        0     0         # (Cyl.    0 - 1211*)
564   h:   962010   211920     vinum                        # (Cyl.  218*- 1211*)
565 .Ed
566 .Pp
567 Lines starting with a
568 .Ql #
569 mark are comments.
570 Most of the other specifications are no longer used.
571 The ones which must still be set correctly are:
572 .Pp
573 .Bl -inset
574 .It Ar label
575 is an optional label, set by the
576 .Ar packid
577 option when writing a label.
578 .It Ar flags
579 may be
580 .Cm removable , ecc
581 or
582 .Cm badsect .
583 .Cm removable
584 is set for removable media drives, but no current
585 .Fx
586 driver evaluates this
587 flag.
588 .Cm ecc
589 is no longer supported;
590 .Cm badsect
591 specifies that the drive can perform bad sector remapping.
592 .It Ar sectors/unit
593 describes the total size of the disk.
594 This value must be correct.
595 .It Ar "the partition table"
596 is the
597 .Ux
598 partition table, not the
599 .Tn DOS
600 partition table described in
601 .Xr fdisk 8 .
602 .El
603 .Pp
604 The partition table can have up to 8 entries.
605 It contains the following information:
606 .Bl -tag -width indent
607 .It Ar #
608 The partition identifier is a single letter in the range
609 .Ql a
610 to
611 .Ql h .
612 By convention, partition
613 .Ql c
614 is reserved to describe the entire disk.
615 .It Ar size
616 The size of the partition in sectors,
617 .Cm K
618 (kilobytes - 1024),
619 .Cm M
620 (megabytes - 1024*1024),
621 .Cm G
622 (gigabytes - 1024*1024*1024),
623 .Cm %
624 (percentage of free space
625 .Em after
626 removing any fixed-size partitions other than partition
627 .Ql c ) ,
628 or
629 .Cm *
630 (all remaining free space
631 .Em after
632 fixed-size and percentage partitions).
633 For partition
634 .Ql c ,
635 a size of
636 .Cm *
637 indicates the entire disk.
638 Lowercase versions of
639 .Cm K , M ,
640 and
641 .Cm G
642 are allowed.
643 Size and type should be specifed without any spaces between them.
644 .Pp
645 Example: 2097152, 1G, 1024M and 1048576K are all the same size
646 (assuming 512-byte sectors).
647 .It Ar offset
648 The offset of the start of the partition from the beginning of the
649 drive in sectors, or
650 .Cm *
651 to have
652 .Nm
653 calculate the correct offset to use (the end of the previous partition plus
654 one, ignoring partition
655 .Ql c .
656 For partition
657 .Ql c ,
658 .Cm *
659 will be interpreted as an offset of 0.
660 .It Ar fstype
661 Describes the purpose of the partition.
662 The example shows all currently used partition types.
663 For
664 .Tn UFS
665 file systems and
666 .Xr ccd 4
667 partitions, use type
668 .Cm 4.2BSD .
669 For Vinum drives, use type
670 .Cm vinum .
671 Other common types are
672 .Cm swap
673 and
674 .Cm unused .
675 By convention, partition
676 .Ql c
677 represents the entire slice and should be of type
678 .Cm unused ,
679 though
680 .Nm
681 does not enforce this convention.
682 The
683 .Nm
684 utility
685 also knows about a number of other partition types,
686 none of which are in current use.
687 (See the definitions starting with
688 .Dv FS_UNUSED
689 in
690 .Aq Pa sys/disklabel.h
691 for more details).
692 .It Ar fsize
693 For
694 .Cm 4.2BSD
695 and
696 .Tn LFS
697 file systems only, the fragment size.
698 Defaults to 1024 for partitions smaller than 1GB,
699 4096 for partitions 1GB or larger.
700 .It Ar bsize
701 For
702 .Cm 4.2BSD
703 and
704 .Tn LFS
705 file systems only, the block size.
706 Defaults to 8192 for partitions smaller than 1GB,
707 16384 for partitions 1GB or larger.
708 .It Ar bps/cpg
709 For
710 .Cm 4.2BSD
711 file systems, the number of cylinders in a cylinder group.
712 For
713 .Tn LFS
714 file systems, the segment shift value.
715 Defaults to 16 for partitions smaller than 1GB,
716 64 for partitions 1GB or larger.
717 .El
718 .Pp
719 The remainder of the line is a comment and shows the cylinder allocations based
720 on the obsolete (but possibly correct) geometry information about the drive.
721 The asterisk
722 .Pq Ql *
723 indicates that the partition does not begin or end exactly on a
724 cylinder boundary.
725 .Sh EXAMPLES
726 .Dl "disklabel da0s1"
727 .Pp
728 Display the in-core label for the first slice of the
729 .Pa da0
730 disk, as obtained via
731 .Pa /dev/da0s1 .
732 (If the disk is
733 .Dq dangerously-dedicated ,
734 the base disk name should be specified, such as
735 .Pa da0 . )
736 .Pp
737 .Dl "disklabel da0s1 > savedlabel"
738 .Pp
739 Save the in-core label for
740 .Pa da0s1
741 into the file
742 .Pa savedlabel .
743 This file can be used with the
744 .Fl R
745 option to restore the label at a later date.
746 .Pp
747 .Dl "disklabel -w -r /dev/da0s1 da2212 foo"
748 .Pp
749 Create a label for
750 .Pa da0s1
751 based on information for
752 .Dq da2212
753 found in
754 .Pa /etc/disktab .
755 Any existing bootstrap code will be clobbered
756 and the disk rendered unbootable.
757 .Pp
758 .Dl "disklabel -e -r da0s1"
759 .Pp
760 Read the on-disk label for
761 .Pa da0s1 ,
762 edit it, and reinstall in-core as well as on-disk.
763 Existing bootstrap code is unaffected.
764 .Pp
765 .Dl "disklabel -e -r -n da0s1"
766 .Pp
767 Read the on-disk label for
768 .Pa da0s1 ,
769 edit it, and display what the new label would be (in sectors).
770 It does
771 .Em not
772 install the new label either in-core or on-disk.
773 .Pp
774 .Dl "disklabel -r -w da0s1 auto"
775 .Pp
776 Try to auto-detect the required information from
777 .Pa da0s1 ,
778 and write a new label to the disk.
779 Use another
780 .Nm Fl e
781 command to edit the
782 partitioning and file system information.
783 .Pp
784 .Dl "disklabel -R da0s1 savedlabel"
785 .Pp
786 Restore the on-disk and in-core label for
787 .Pa da0s1
788 from information in
789 .Pa savedlabel .
790 Existing bootstrap code is unaffected.
791 .Pp
792 .Dl "disklabel -R -n da0s1 label_layout"
793 .Pp
794 Display what the label would be for
795 .Pa da0s1
796 using the partition layout in
797 .Pa label_layout .
798 This is useful for determining how much space would be alloted for various
799 partitions with a labelling scheme using
800 .Cm % Ns -based
801 or
802 .Cm *
803 partition sizes.
804 .Pp
805 .Dl disklabel -B da0s1
806 .Pp
807 Install a new bootstrap on
808 .Pa da0s1 .
809 The boot code comes from
810 .Pa /boot/boot1
811 and possibly
812 .Pa /boot/boot2 .
813 On-disk and in-core labels are unchanged.
814 .Pp
815 .Dl disklabel -w -B /dev/da0s1 -b newboot1 -s newboot2 da2212
816 .Pp
817 Install a new label and bootstrap.
818 The label is derived from disktab information for
819 .Dq da2212
820 and installed both in-core and on-disk.
821 The bootstrap code comes from the files
822 .Pa /boot/newboot1
823 and
824 .Pa /boot/newboot2 .
825 .Pp
826 .Dl dd if=/dev/zero of=/dev/da0 bs=512 count=32
827 .Dl fdisk -BI da0
828 .Dl dd if=/dev/zero of=/dev/da0s1 bs=512 count=32
829 .Dl disklabel -w -B da0s1 auto
830 .Dl disklabel -e da0s1
831 .Pp
832 Completely wipe any prior information on the disk, creating a new bootable
833 disk with a DOS partition table containing one
834 .Dq whole-disk
835 slice.  Then
836 initialize the slice, then edit it to your needs.  The
837 .Pa dd
838 commands are optional, but may be necessary for some BIOSes to properly
839 recognize the disk.
840 .Pp
841 This is an example disklabel that uses some of the new partition size types
842 such as
843 .Cm % , M , G ,
844 and
845 .Cm * ,
846 which could be used as a source file for
847 .Pp
848 .Dl disklabel -R ad0s1c new_label_file
849 .Bd -literal -offset 4n
850 # /dev/ad0s1c:
851 type: ESDI
852 disk: ad0s1
853 label:
854 flags:
855 bytes/sector: 512
856 sectors/track: 63
857 tracks/cylinder: 16
858 sectors/cylinder: 1008
859 cylinders: 40633
860 sectors/unit: 40959009
861 rpm: 3600
862 interleave: 1
863 trackskew: 0
864 cylinderskew: 0
865 headswitch: 0           # milliseconds
866 track-to-track seek: 0  # milliseconds
867 drivedata: 0
868
869 8 partitions:
870 #        size   offset    fstype   [fsize bsize bps/cpg]
871   a:   400M        0    4.2BSD     4096 16384    75     # (Cyl.    0 - 812*)
872   b:     1G        *      swap
873   c:      *        *    unused
874   e: 204800        *    4.2BSD
875   f:     5g        *    4.2BSD
876   g:      *        *    4.2BSD
877 .Ed
878 .Sh SEE ALSO
879 .Xr ccd 4 ,
880 .Xr disklabel 5 ,
881 .Xr disktab 5 ,
882 .Xr boot0cfg 8 ,
883 .Xr fdisk 8 ,
884 .Xr vinum 8
885 .Sh DIAGNOSTICS
886 The kernel device drivers will not allow the size of a disk partition
887 to be decreased or the offset of a partition to be changed while it is open.
888 Some device drivers create a label containing only a single large partition
889 if a disk is unlabeled; thus, the label must be written to the
890 .Dq a
891 partition of the disk while it is open.  This sometimes requires the desired
892 label to be set in two steps, the first one creating at least one other
893 partition, and the second setting the label on the new partition while shrinking
894 the
895 .Dq a
896 partition.
897 .Pp
898 On some machines the bootstrap code may not fit entirely in the area
899 allocated for it by some file systems.
900 As a result, it may not be possible to have file systems on some partitions
901 of a
902 .Dq bootable
903 disk.
904 When installing bootstrap code,
905 .Nm
906 checks for these cases.
907 If the installed boot code would overlap a partition of type FS_UNUSED
908 it is marked as type FS_BOOT.
909 The
910 .Xr newfs 8
911 utility will disallow creation of file systems on FS_BOOT partitions.
912 Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT,
913 .Nm
914 will not install bootstrap code that overlaps it.
915 .Sh BUGS
916 When a disk name is given without a full pathname,
917 the constructed device name uses the
918 .Dq c
919 partition.
920 .Pp
921 For the i386 architecture, the primary bootstrap sector contains
922 an embedded
923 .Em fdisk
924 table.
925 The
926 .Nm
927 utility takes care to not clobber it when installing a bootstrap only
928 .Pq Fl B ,
929 or when editing an existing label
930 .Pq Fl e ,
931 but it unconditionally writes the primary bootstrap program onto
932 the disk for
933 .Fl w
934 or
935 .Fl R ,
936 thus replacing the
937 .Em fdisk
938 table by the dummy one in the bootstrap program.  This is only of
939 concern if the disk is fully dedicated, so that the
940 .Bx
941 disklabel
942 starts at absolute block 0 on the disk.
943 .Pp
944 The
945 .Nm
946 utility
947 does not perform all possible error checking.  Warning *is* given if partitions
948 overlap; if an absolute offset does not match the expected offset; if the
949 .Dq c
950 partition does not start at 0 or does not cover the entire slice; if a
951 partition runs past the end of the device; and a number of other errors; but
952 no warning is given if space remains unused.