1 .\" Copyright (c) 1987, 1988, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Symmetric Computer Systems.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
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.
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
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.19 2008/04/23 21:59:22 thomas Exp $
44 .Nd read and write disk pack label
53 .Ar disk Ar disktype/auto
76 .Oo Ar disktype/auto Oc
85 .Ar disk Ar disktype/auto
96 .Oo Ar disktype/auto Oc
98 .Fl f Ar slice_start_lba
104 installs, examines or modifies the label on a disk drive or pack.
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.
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.
118 default, most forms of the
120 command access the in-core copy of the label.
121 To access the raw (on-disk)
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
130 is described under each command.
134 forms require a disk device name, which should always be the raw
135 device name representing the disk or slice.
138 represents the entire disk regardless of any DOS partitioning,
139 this is called the compatibility slice,
142 represents a BSD slice.
143 You do not have to include the
145 path prefix when specifying the device.
148 utility will automatically prepend it.
149 .Ss Reading the disk label
150 To examine the label on a disk drive, use
159 represents the raw disk in question, and may be in the form
163 It will display all of the parameters associated with the drive and its
168 the kernel's in-core copy of the label is displayed;
169 if the disk has no label, or the partition types on the disk are incorrect,
170 the kernel may have constructed or modified the label.
175 reads the label from the raw disk and displays it.
176 Both versions are usually
177 identical except in the case where a label has not yet been initialized or
179 .Ss Writing a standard label
180 To write a standard label, use the form
186 .Ar disk Ar disktype/auto
196 The required arguments to
198 are the drive to be labeled and the drive type as described in the
201 The drive parameters and partitions are taken from that file.
203 different disks of the same physical type are to have different partitions, it
204 will be necessary to have separate disktab entries describing each, or to edit
205 the label after installation as described below.
206 The optional argument is a
207 pack identification string, up to 16 characters long.
209 quoted if it contains blanks.
213 flag is given, no data will be written to the device, and instead the
214 disklabel that would have been written will be printed to stdout.
218 flag is given, the disk sectors containing the label and bootstrap
219 will be written directly.
220 A side-effect of this is that any existing bootstrap code will be overwritten
221 and the disk rendered unbootable.
222 See the boot options below for a method of
223 writing the label and the bootstrap at the same time.
227 the existing label will be updated via the in-core copy and any bootstrap
228 code will be unaffected.
229 If the disk does not already have a label, the
232 In either case, the kernel's in-core label is replaced.
234 For a virgin disk that is not known to
239 In this case, the driver is requested to produce a virgin label for the
241 This might or might not be successful, depending on whether the
242 driver for the disk is able to get the required data without reading
243 anything from the disk at all.
244 It will likely succeed for all SCSI
245 disks, most IDE disks, and vnode devices.
246 Writing a label to the
247 disk is the only supported operation, and the
249 itself must be provided as the canonical name, i.e.\& not as a full
252 For most harddisks, a label based on percentages for most partitions (and
253 one partition with a size of
255 will produce a reasonable configuration.
257 PC-based systems have special requirements in order for the BIOS to properly
261 Older systems may require what is known as a
262 .Dq dangerously dedicated
263 disklabel, which creates a fake DOS partition to work around problems older
264 BIOSes have with modern disk geometries.
265 On newer systems you generally want
266 to create a normal DOS partition using
270 disklabel within that slice.
272 later on in this page.
274 Installing a new disklabel does not in of itself allow your system to boot
275 a kernel using that label.
276 You must also install boot blocks, which is
277 described later on in this manual page.
278 .Ss Editing an existing disk label
279 To edit an existing disk label, use the form
287 This command reads the label from the in-core kernel copy, or directly from the
290 flag is also specified.
291 The label is written to a file in ASCII and then
292 supplied to an editor for changes.
293 If no editor is specified in an
295 environment variable,
298 When the editor terminates, the label file is used to rewrite the disk
300 Existing bootstrap code is unchanged regardless of whether
305 is specified, no data will be written to the device, and instead the
306 disklabel that would have been written will be printed to stdout.
308 useful to see how a partitioning scheme will work out for a specific disk.
309 .Ss Restoring a disk label from a file
310 To restore a disk label from a file, use the form
316 .Ar disk Ar protofile
319 is capable of restoring a disk label that was previously saved in a file
321 The prototype file used to create the label should be in the same format
322 as that produced when reading or editing a label.
323 Comments are delimited by
326 As when writing a new label, any existing bootstrap code will be
329 is specified and will be unaffected otherwise.
330 See the boot options below for a
331 method of restoring the label and writing the bootstrap at the same time.
334 is used, no data will be written to the device, and instead the
335 disklabel that would have been written will be printed to stdout.
337 useful to see how a partitioning scheme will work out for a specific disk.
338 .Ss Enabling and disabling writing to the disk label area
339 By default, it is not possible to write to the disk label area at the beginning
341 The disk driver arranges for
343 and similar system calls
346 on any attempt to do so.
348 to write to this area (for example, to obliterate the label), use the form
354 To disallow writing to the label area after previously allowing it, use the
360 .Ss Installing bootstraps
361 The final three forms of
363 are used to install bootstrap code.
364 If you are creating a
365 .Dq dangerously-dedicated
366 slice for compatibility with older PC systems,
367 you generally want to specify the compatibility slice, such as
369 If you are creating a label within an existing DOS slice,
371 the slice name such as
373 Making a slice bootable can be tricky.
374 If you are using a normal DOS
375 slice you typically install (or leave) a standard MBR on the base disk and
378 bootblocks in the slice.
389 This form installs the bootstrap only.
390 It does not change the disk label.
391 You should never use this command on the compatibility slice unless you
393 .Dq dangerously-dedicated
396 This command is typically run on a BSD slice such as
410 This form corresponds to the
412 command described above.
413 In addition to writing a new volume label, it also installs the bootstrap.
414 If run on the compatibility slice this command will create a
415 .Dq dangerously-dedicated
417 This command is normally run on a BSD slice rather than the compatibility
421 is used, no data will be written to the device, and instead the
422 disklabel that would have been written will be printed to stdout.
432 .Ar disk Ar protofile
435 This form corresponds to the
437 command described above.
438 In addition to restoring the volume label, it also installs the bootstrap.
439 If run on the compatibility slice this command will create a
440 .Dq dangerously-dedicated
442 This command is normally run on a BSD slice rather than the compatibility
445 The bootstrap commands always access the disk directly, so it is not necessary
451 is used, no data will be written to the device, and instead the
452 disklabel that would have been written will be printed to stdout.
454 The bootstrap code is comprised of two boot programs.
455 Specify the name of the
456 boot programs to be installed in one of these ways:
459 Specify the names explicitly with the
465 indicates the primary boot program and
467 the secondary boot program.
468 The boot programs are located in
475 flags are not specified, but
477 was specified, the names of the programs are taken from the
483 entry for the disk if the disktab entry exists and includes those parameters.
485 Otherwise, the default boot image names are used:
489 for the standard stage1 and stage2 boot images.
491 .Ss Initializing/Formatting a bootable disk from scratch
492 To initialize a disk from scratch the following sequence is recommended.
493 Please note that this will wipe everything that was previously on the disk,
501 to initialize the hard disk, and create a slice table, referred to
503 .Dq "partition table"
509 to define partitions on
511 slices created in the previous step.
515 to create file systems on new partitions.
518 A typical partitioning scheme would be to have an
521 of approximately 128MB to hold the root file system, a
537 (usually around 2GB),
542 (usually all remaining space).
543 Your mileage may vary.
545 .Nm fdisk Fl BI Pa da0
556 .Bl -tag -width ".Pa /etc/disktab" -compact
558 Default stage1 boot image.
560 Default stage2 boot image.
562 Disk description file.
564 .Sh SAVED FILE FORMAT
570 version of the label when examining, editing, or restoring a disk
573 .Bd -literal -offset 4n
582 sectors/cylinder: 969
584 sectors/unit: 1173930
589 headswitch: 0 # milliseconds
590 track-to-track seek: 0 # milliseconds
595 a: 81920 0 4.2BSD # 40.000MB
596 b: 160000 81920 swap # 78.125MB
597 c: 1173930 0 unused # 573.208MB
598 f: 320000 241920 HAMMER # 156.250MB
599 g: 300000 561920 ccd # 146.484MB
600 h: 312010 861920 vinum # 152.349MB
603 Lines starting with a
606 Most of the other specifications are no longer used.
607 The ones which must still be set correctly are:
611 is an optional label, set by the
613 option when writing a label.
620 is set for removable media drives, but no current
622 driver evaluates this
625 is no longer supported;
627 specifies that the drive can perform bad sector remapping.
629 describes the total size of the disk.
630 This value must be correct.
631 .It Ar "the partition table"
634 partition table, not the
636 partition table described in
640 The partition table can have up to 16 entries.
641 It contains the following information:
642 .Bl -tag -width indent
644 The partition identifier is a single letter in the range
648 By convention, partition
650 is reserved to describe the entire disk.
652 The size of the partition in sectors,
656 (megabytes - 1024*1024),
658 (gigabytes - 1024*1024*1024),
660 (percentage of free space
662 removing any fixed-size partitions other than partition
666 (all remaining free space
668 fixed-size and percentage partitions).
673 indicates the entire disk.
674 Lowercase versions of
679 Size and type should be specified without any spaces between them.
681 Example: 2097152, 1G, 1024M and 1048576K are all the same size
682 (assuming 512-byte sectors).
684 The offset of the start of the partition from the beginning of the
689 calculate the correct offset to use (the end of the previous partition plus
690 one, ignoring partition
695 will be interpreted as an offset of 0.
697 Describes the purpose of the partition.
698 The example shows all currently used partition types.
701 file systems, use type
705 file systems, use type
711 For Vinum drives, use type
713 Other common types are
717 By convention, partition
719 represents the entire slice and should be of type
723 does not enforce this convention.
727 also knows about a number of other partition types,
728 none of which are in current use.
736 The remainder of the line is a comment and shows the size of the partition
740 no longer snoop-adjusts the on-disklabel when reading or writing
743 is now responsible for adjusting the label when operating in raw mode.
744 Traditional (32 bit BSD) disklabels store offsets as absolute block numbers
745 rather than slice-relative block numbers.
748 is unable to issue the
750 ioctl to get slice information it will
751 refuse to read or write the label in raw mode.
754 option may be used to force the operation by supplying a manual offset.
756 .Dl "disklabel da0s1"
758 Display the in-core label for the first slice of the
760 disk, as obtained via
763 .Dq dangerously-dedicated ,
764 the compatibility slice name should be specified, such as
767 .Dl "disklabel da0s1 > savedlabel"
769 Save the in-core label for
773 This file can be used with the
775 option to restore the label at a later date.
777 .Dl "disklabel -w -r /dev/da0s1 da2212 foo"
781 based on information for
785 Any existing bootstrap code will be clobbered
786 and the disk rendered unbootable.
788 .Dl "disklabel -e -r da0s1"
790 Read the on-disk label for
792 edit it, and reinstall in-core as well as on-disk.
793 Existing bootstrap code is unaffected.
795 .Dl "disklabel -e -r -n da0s1"
797 Read the on-disk label for
799 edit it, and display what the new label would be (in sectors).
802 install the new label either in-core or on-disk.
804 .Dl "disklabel -r -w da0s1 auto"
806 Try to auto-detect the required information from
808 and write a new label to the disk.
812 partitioning and file system information.
814 .Dl "disklabel -R da0s1 savedlabel"
816 Restore the on-disk and in-core label for
820 Existing bootstrap code is unaffected.
822 .Dl "disklabel -R -n da0s1 label_layout"
824 Display what the label would be for
826 using the partition layout in
828 This is useful for determining how much space would be allotted for various
829 partitions with a labelling scheme using
835 .Dl disklabel -B da0s1
837 Install a new bootstrap on
839 The boot code comes from
843 On-disk and in-core labels are unchanged.
845 .Dl disklabel -w -B /dev/da0s1 -b newboot1 -s newboot2 da2212
847 Install a new label and bootstrap.
848 The label is derived from disktab information for
850 and installed both in-core and on-disk.
851 The bootstrap code comes from the files
856 .Dl dd if=/dev/zero of=/dev/da0 bs=512 count=32
858 .Dl dd if=/dev/zero of=/dev/da0s1 bs=512 count=32
859 .Dl disklabel -w -B da0s1 auto
860 .Dl disklabel -e da0s1
862 Completely wipe any prior information on the disk, creating a new bootable
863 disk with a DOS partition table containing one
867 initialize the slice, then edit it to your needs.
870 commands are optional, but may be necessary for some BIOSes to properly
873 This is an example disklabel that uses some of the new partition size types
878 which could be used as a source file for
880 .Dl disklabel -R ad0s1 new_label_file
881 .Bd -literal -offset 4n
890 sectors/cylinder: 1008
892 sectors/unit: 40959009
897 headswitch: 0 # milliseconds
898 track-to-track seek: 0 # milliseconds
911 The kernel device drivers will not allow the size of a disk partition
912 to be decreased or the offset of a partition to be changed while it is open.
913 Some device drivers create a label containing only a single large partition
914 if a disk is unlabeled; thus, the label must be written to the
916 partition of the disk while it is open.
917 This sometimes requires the desired
918 label to be set in two steps, the first one creating at least one other
919 partition, and the second setting the label on the new partition while
924 On some machines the bootstrap code may not fit entirely in the area
925 allocated for it by some file systems.
926 As a result, it may not be possible to have file systems on some partitions
930 When installing bootstrap code,
932 checks for these cases.
933 If the installed boot code would overlap a partition of type
939 utility will disallow creation of file systems on
942 Conversely, if a partition has a type other than
947 will not install bootstrap code that overlaps it.
958 When a disk name is given without a full pathname,
959 the constructed device name uses the
963 For the i386 architecture, the primary bootstrap sector contains
969 utility takes care to not clobber it when installing a bootstrap only
971 or when editing an existing label
973 but it unconditionally writes the primary bootstrap program onto
980 table by the dummy one in the bootstrap program.
982 concern if the disk is fully dedicated, so that the
985 starts at absolute block 0 on the disk.
990 does not perform all possible error checking.
991 Warning *is* given if partitions
992 overlap; if an absolute offset does not match the expected offset; if the
994 partition does not start at 0 or does not cover the entire slice; if a
995 partition runs past the end of the device; and a number of other errors; but
996 no warning is given if space remains unused.