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