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