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