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.6 2006/02/10 19:01:09 swildner 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
101 installs, examines or modifies the label on a disk drive or pack. When writing
102 the label, it can be used to change the drive identification, the disk
103 partitions on the drive, or to replace a damaged label. There are several forms
104 of the command that read (display), install or edit the label on a disk. In
107 can install bootstrap code.
108 .Ss Raw or in-core label
109 The disk label resides close to or at the beginning of each disk slice.
110 For faster access, the kernel maintains a copy in core at all times. By
111 default, most forms of the
113 command access the in-core copy of the label. To access the raw (on-disk)
116 option. This option allows a label to be installed on a disk without kernel
117 support for a label, such as when labels are first installed on a system; it
118 must be used when first installing a label on a disk. The specific effect of
120 is described under each command.
125 forms require a disk device name, which should always be the raw
126 device name representing the disk or slice. For example
128 represents the entire disk regardless of any DOS partitioning,
131 represents a slice. Some devices, most notably
137 partition be specified. For example
139 You do not have to include the
141 path prefix when specifying the device.
144 utility will automatically prepend it.
145 .Ss Reading the disk label
146 To examine the label on a disk drive, use
155 represents the raw disk in question, and may be in the form
159 It will display all of the parameters associated with the drive and its
160 partition layout. Unless the
163 the kernel's in-core copy of the label is displayed;
164 if the disk has no label, or the partition types on the disk are incorrect,
165 the kernel may have constructed or modified the label.
170 reads the label from the raw disk and displays it. Both versions are usually
171 identical except in the case where a label has not yet been initialized or
173 .Ss Writing a standard label
174 To write a standard label, use the form
180 .Ar disk Ar disktype/auto
190 The required arguments to
192 are the drive to be labeled and the drive type as described in the
194 file. The drive parameters and partitions are taken from that file. If
195 different disks of the same physical type are to have different partitions, it
196 will be necessary to have separate disktab entries describing each, or to edit
197 the label after installation as described below. The optional argument is a
198 pack identification string, up to 16 characters long. The pack id must be
199 quoted if it contains blanks.
203 flag is given, no data will be written to the device, and instead the
204 disklabel that would have been written will be printed to stdout.
208 flag is given, the disk sectors containing the label and bootstrap
209 will be written directly.
210 A side-effect of this is that any existing bootstrap code will be overwritten
211 and the disk rendered unbootable. See the boot options below for a method of
212 writing the label and the bootstrap at the same time.
216 the existing label will be updated via the in-core copy and any bootstrap
217 code will be unaffected.
218 If the disk does not already have a label, the
221 In either case, the kernel's in-core label is replaced.
223 For a virgin disk that is not known to
228 In this case, the driver is requested to produce a virgin label for the
229 disk. This might or might not be successful, depending on whether the
230 driver for the disk is able to get the required data without reading
231 anything from the disk at all. It will likely succeed for all SCSI
232 disks, most IDE disks, and vnode devices. Writing a label to the
233 disk is the only supported operation, and the
235 itself must be provided as the canonical name, i.e. not as a full
238 For most harddisks, a label based on percentages for most partitions (and
239 one partition with a size of
241 will produce a reasonable configuration.
243 PC-based systems have special requirements in order for the BIOS to properly
246 disklabel. Older systems may require what is known as a
247 .Dq dangerously dedicated
248 disklabel, which creates a fake DOS partition to work around problems older
249 BIOSes have with modern disk geometries.
250 On newer systems you generally want
251 to create a normal DOS partition using
255 disklabel within that slice. This is described
256 later on in this page.
258 Installing a new disklabel does not in of itself allow your system to boot
259 a kernel using that label. You must also install boot blocks, which is
260 described later on in this manual page.
261 .Ss Editing an existing disk label
262 To edit an existing disk label, use the form
270 This command reads the label from the in-core kernel copy, or directly from the
273 flag is also specified. The label is written to a file in ASCII and then
274 supplied to an editor for changes. If no editor is specified in an
276 environment variable,
278 is used. When the editor terminates, the label file is used to rewrite the disk
279 label. Existing bootstrap code is unchanged regardless of whether
283 is specified, no data will be written to the device, and instead the
284 disklabel that would have been written will be printed to stdout. This is
285 useful to see how a partitioning scheme will work out for a specific disk.
286 .Ss Restoring a disk label from a file
287 To restore a disk label from a file, use the form
293 .Ar disk Ar protofile
296 is capable of restoring a disk label that was previously saved in a file in ASCII format.
297 The prototype file used to create the label should be in the same format as that
298 produced when reading or editing a label. Comments are delimited by
300 and newline. As when writing a new label, any existing bootstrap code will be
303 is specified and will be unaffected otherwise. See the boot options below for a
304 method of restoring the label and writing the bootstrap at the same time.
307 is used, no data will be written to the device, and instead the
308 disklabel that would have been written will be printed to stdout. This is
309 useful to see how a partitioning scheme will work out for a specific disk.
310 .Ss Enabling and disabling writing to the disk label area
311 By default, it is not possible to write to the disk label area at the beginning
312 of a disk. The disk driver arranges for
314 and similar system calls
317 on any attempt to do so. If you need
318 to write to this area (for example, to obliterate the label), use the form
324 To disallow writing to the label area after previously allowing it, use the
330 .Ss Installing bootstraps
331 The final three forms of
333 are used to install bootstrap code. If you are creating a
334 .Dq dangerously-dedicated
335 slice for compatibility with older PC systems,
336 you generally want to specify the raw disk name such as
338 If you are creating a label within an existing DOS slice,
340 the partition name such as
342 Making a slice bootable can be tricky. If you are using a normal DOS
343 slice you typically install (or leave) a standard MBR on the base disk and
346 bootblocks in the slice.
357 This form installs the bootstrap only. It does not change the disk label.
358 You should never use this command on a base disk unless you intend to create a
359 .Dq dangerously-dedicated
362 This command is typically run on a slice such as
376 This form corresponds to the
378 command described above.
379 In addition to writing a new volume label, it also installs the bootstrap.
380 If run on a base disk this command will create a
381 .Dq dangerously-dedicated
382 label. This command is normally run on a slice rather than a base disk.
385 is used, no data will be written to the device, and instead the
386 disklabel that would have been written will be printed to stdout.
396 .Ar disk Ar protofile
399 This form corresponds to the
401 command described above.
402 In addition to restoring the volume label, it also installs the bootstrap.
403 If run on a base disk this command will create a
404 .Dq dangerously-dedicated
405 label. This command is normally run on a slice rather than a base disk.
407 The bootstrap commands always access the disk directly, so it is not necessary
412 is used, no data will be written to the device, and instead the
413 disklabel that would have been written will be printed to stdout.
415 The bootstrap code is comprised of two boot programs. Specify the name of the
416 boot programs to be installed in one of these ways:
419 Specify the names explicitly with the
425 indicates the primary boot program and
427 the secondary boot program. The boot programs are located in
434 flags are not specified, but
436 was specified, the names of the programs are taken from the
442 entry for the disk if the disktab entry exists and includes those parameters.
444 Otherwise, the default boot image names are used:
448 for the standard stage1 and stage2 boot images (details may vary
449 on architectures like the Alpha, where only a single-stage boot is used).
451 .Ss Initializing/Formatting a bootable disk from scratch
452 To initialize a disk from scratch the following sequence is recommended.
453 Please note that this will wipe everything that was previously on the disk,
461 to initialize the hard disk, and create a slice table, referred to
463 .Dq "partition table"
469 to define partitions on
471 slices created in the previous step.
475 to create file systems on new partitions.
478 A typical partitioning scheme would be to have an
481 of approximately 128MB to hold the root file system, a
497 (usually around 2GB),
502 (usually all remaining space).
503 Your mileage may vary.
505 .Nm fdisk Fl BI Pa da0
516 .Bl -tag -width ".Pa /etc/disktab" -compact
520 Disk description file.
522 .Sh SAVED FILE FORMAT
528 version of the label when examining, editing, or restoring a disk
531 .Bd -literal -offset 4n
540 sectors/cylinder: 969
542 sectors/unit: 1173930
547 headswitch: 0 # milliseconds
548 track-to-track seek: 0 # milliseconds
552 # size offset fstype [fsize bsize bps/cpg]
553 a: 81920 0 4.2BSD 1024 8192 16 # (Cyl. 0 - 84*)
554 b: 160000 81920 swap # (Cyl. 84* - 218*)
555 c: 1173930 0 unused 0 0 # (Cyl. 0 - 1211*)
556 h: 962010 211920 vinum # (Cyl. 218*- 1211*)
559 Lines starting with a
562 Most of the other specifications are no longer used.
563 The ones which must still be set correctly are:
567 is an optional label, set by the
569 option when writing a label.
576 is set for removable media drives, but no current
578 driver evaluates this
581 is no longer supported;
583 specifies that the drive can perform bad sector remapping.
585 describes the total size of the disk.
586 This value must be correct.
587 .It Ar "the partition table"
590 partition table, not the
592 partition table described in
596 The partition table can have up to 8 entries.
597 It contains the following information:
598 .Bl -tag -width indent
600 The partition identifier is a single letter in the range
604 By convention, partition
606 is reserved to describe the entire disk.
608 The size of the partition in sectors,
612 (megabytes - 1024*1024),
614 (gigabytes - 1024*1024*1024),
616 (percentage of free space
618 removing any fixed-size partitions other than partition
622 (all remaining free space
624 fixed-size and percentage partitions).
629 indicates the entire disk.
630 Lowercase versions of
635 Size and type should be specifed without any spaces between them.
637 Example: 2097152, 1G, 1024M and 1048576K are all the same size
638 (assuming 512-byte sectors).
640 The offset of the start of the partition from the beginning of the
645 calculate the correct offset to use (the end of the previous partition plus
646 one, ignoring partition
651 will be interpreted as an offset of 0.
653 Describes the purpose of the partition.
654 The example shows all currently used partition types.
661 For Vinum drives, use type
663 Other common types are
667 By convention, partition
669 represents the entire slice and should be of type
673 does not enforce this convention.
677 also knows about a number of other partition types,
678 none of which are in current use.
679 (See the definitions starting with
682 .Aq Pa sys/disklabel.h
689 file systems only, the fragment size.
690 Defaults to 1024 for partitions smaller than 1GB,
691 2048 for partitions 1GB or larger.
697 file systems only, the block size.
698 Defaults to 8192 for partitions smaller than 1GB,
699 16384 for partitions 1GB or larger.
703 file systems, the number of cylinders in a cylinder group.
706 file systems, the segment shift value.
707 Defaults to 16 for partitions smaller than 1GB,
708 64 for partitions 1GB or larger.
711 The remainder of the line is a comment and shows the cylinder allocations based
712 on the obsolete (but possibly correct) geometry information about the drive.
715 indicates that the partition does not begin or end exactly on a
718 .Dl "disklabel da0s1"
720 Display the in-core label for the first slice of the
722 disk, as obtained via
725 .Dq dangerously-dedicated ,
726 the base disk name should be specified, such as
729 .Dl "disklabel da0s1 > savedlabel"
731 Save the in-core label for
735 This file can be used with the
737 option to restore the label at a later date.
739 .Dl "disklabel -w -r /dev/da0s1 da2212 foo"
743 based on information for
747 Any existing bootstrap code will be clobbered
748 and the disk rendered unbootable.
750 .Dl "disklabel -e -r da0s1"
752 Read the on-disk label for
754 edit it, and reinstall in-core as well as on-disk.
755 Existing bootstrap code is unaffected.
757 .Dl "disklabel -e -r -n da0s1"
759 Read the on-disk label for
761 edit it, and display what the new label would be (in sectors).
764 install the new label either in-core or on-disk.
766 .Dl "disklabel -r -w da0s1 auto"
768 Try to auto-detect the required information from
770 and write a new label to the disk.
774 partitioning and file system information.
776 .Dl "disklabel -R da0s1 savedlabel"
778 Restore the on-disk and in-core label for
782 Existing bootstrap code is unaffected.
784 .Dl "disklabel -R -n da0s1 label_layout"
786 Display what the label would be for
788 using the partition layout in
790 This is useful for determining how much space would be alloted for various
791 partitions with a labelling scheme using
797 .Dl disklabel -B da0s1
799 Install a new bootstrap on
801 The boot code comes from
805 On-disk and in-core labels are unchanged.
807 .Dl disklabel -w -B /dev/da0s1 -b newboot1 -s newboot2 da2212
809 Install a new label and bootstrap.
810 The label is derived from disktab information for
812 and installed both in-core and on-disk.
813 The bootstrap code comes from the files
818 .Dl dd if=/dev/zero of=/dev/da0 bs=512 count=32
820 .Dl dd if=/dev/zero of=/dev/da0s1 bs=512 count=32
821 .Dl disklabel -w -B da0s1 auto
822 .Dl disklabel -e da0s1
824 Completely wipe any prior information on the disk, creating a new bootable
825 disk with a DOS partition table containing one
828 initialize the slice, then edit it to your needs. The
830 commands are optional, but may be necessary for some BIOSes to properly
833 This is an example disklabel that uses some of the new partition size types
838 which could be used as a source file for
840 .Dl disklabel -R ad0s1c new_label_file
841 .Bd -literal -offset 4n
850 sectors/cylinder: 1008
852 sectors/unit: 40959009
857 headswitch: 0 # milliseconds
858 track-to-track seek: 0 # milliseconds
862 # size offset fstype [fsize bsize bps/cpg]
863 a: 400M 0 4.2BSD 4096 16384 75 # (Cyl. 0 - 812*)
878 The kernel device drivers will not allow the size of a disk partition
879 to be decreased or the offset of a partition to be changed while it is open.
880 Some device drivers create a label containing only a single large partition
881 if a disk is unlabeled; thus, the label must be written to the
883 partition of the disk while it is open. This sometimes requires the desired
884 label to be set in two steps, the first one creating at least one other
885 partition, and the second setting the label on the new partition while shrinking
890 On some machines the bootstrap code may not fit entirely in the area
891 allocated for it by some file systems.
892 As a result, it may not be possible to have file systems on some partitions
896 When installing bootstrap code,
898 checks for these cases.
899 If the installed boot code would overlap a partition of type FS_UNUSED
900 it is marked as type FS_BOOT.
903 utility will disallow creation of file systems on FS_BOOT partitions.
904 Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT,
906 will not install bootstrap code that overlaps it.
908 When a disk name is given without a full pathname,
909 the constructed device name uses the
913 For the i386 architecture, the primary bootstrap sector contains
919 utility takes care to not clobber it when installing a bootstrap only
921 or when editing an existing label
923 but it unconditionally writes the primary bootstrap program onto
930 table by the dummy one in the bootstrap program. This is only of
931 concern if the disk is fully dedicated, so that the
934 starts at absolute block 0 on the disk.
939 does not perform all possible error checking. Warning *is* given if partitions
940 overlap; if an absolute offset does not match the expected offset; if the
942 partition does not start at 0 or does not cover the entire slice; if a
943 partition runs past the end of the device; and a number of other errors; but
944 no warning is given if space remains unused.