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