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