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
43 .Nd read and write disk pack label
52 .Ar disk Ar disktype/auto
75 .Oo Ar disktype/auto Oc
84 .Ar disk Ar disktype/auto
95 .Oo Ar disktype/auto Oc
98 installs, examines or modifies the label on a disk drive or pack. When writing
99 the label, it can be used to change the drive identification, the disk
100 partitions on the drive, or to replace a damaged label. There are several forms
101 of the command that read (display), install or edit the label on a disk. In
104 can install bootstrap code.
105 .Ss Raw or in-core label
107 The disk label is resident close to or at the beginning of each disk partition.
108 For faster access, the kernel maintains a copy in core at all times. By
111 access the in-core copy of the label. To access the raw (on-disk) copy, use the
113 option. This option allows a label to be installed on a disk without kernel
114 support for a label, such as when labels are first installed on a system; it
115 must be used when first installing a label on a disk. The specific effect of
117 is described under each command.
123 forms require a disk device name, which should always be the raw
124 device name representing the disk or slice. For example
126 represents the entire disk irregardless of any DOS partitioning,
129 represents a slice. Some devices, most notably
135 partition be specified. For example
137 You do not have to include the
139 path prefix when specifying the device.
141 will automatically prepend it.
142 .Ss Reading the disk label
144 To examine the label on a disk drive, use
153 represents the raw disk in question, and may be in the form
157 It will display all of the parameters associated with the drive and its
158 partition layout. Unless the
161 the kernel's in-core copy of the label is displayed;
162 if the disk has no label, or the partition types on the disk are incorrect,
163 the kernel may have constructed or modified the label.
168 reads the label from the raw disk and displays it. Both versions are usually
169 identical except in the case where a label has not yet been initialized or
171 .Ss Writing a standard label
173 To write a standard label, use the form
179 .Ar disk Ar disktype/auto
189 The required arguments to
191 are the drive to be labeled and the drive type as described in the
193 file. The drive parameters and partitions are taken from that file. If
194 different disks of the same physical type are to have different partitions, it
195 will be necessary to have separate disktab entries describing each, or to edit
196 the label after installation as described below. The optional argument is a
197 pack identification string, up to 16 characters long. The pack id must be
198 quoted if it contains blanks.
202 flag is given, no data will be written to the device, and instead the
203 disklabel that would have been written will be printed to stdout.
207 flag is given, the disk sectors containing the label and bootstrap
208 will be written directly.
209 A side-effect of this is that any existing bootstrap code will be overwritten
210 and the disk rendered unbootable. See the boot options below for a method of
211 writing the label and the bootstrap at the same time.
215 the existing label will be updated via the in-core copy and any bootstrap
216 code will be unaffected.
217 If the disk does not already have a label, the
220 In either case, the kernel's in-core label is replaced.
222 For a virgin disk that is not known to
227 In this case, the driver is requested to produce a virgin label for the
228 disk. This might or might not be successful, depending on whether the
229 driver for the disk is able to get the required data without reading
230 anything from the disk at all. It will likely succeed for all SCSI
231 disks, most IDE disks, and vnode devices. Writing a label to the
232 disk is the only supported operation, and the
234 itself must be provided as the canonical name, i.e. not as a full
237 For most harddisks, a label based on percentages for most partitions (and
238 one partition with a size of
240 will produce a reasonable configuration.
242 PC-based systems have special requirements in order for the BIOS to properly
245 disklabel. Older systems may require what is known as a
246 .Dq dangerously dedicated
247 disklabel, which creates a fake DOS partition to work around problems older
248 BIOSes have with modern disk geometries. On newer systems you generally want
249 to create a normal DOS slice using
253 disklabel within that slice. This is described
254 later on in this page.
256 Installing a new disklabel does not in of itself allow your system to boot
257 a kernel using that label. You must also install boot blocks, which is
258 described later on in this manual page.
259 .Ss Editing an existing disk label
261 To edit an existing disk label, use the form
269 This command reads the label from the in-core kernel copy, or directly from the
272 flag is also specified. The label is written to a file in ASCII and then
273 supplied to an editor for changes. If no editor is specified in an
275 environment variable,
277 is used. When the editor terminates, the label file is used to rewrite the disk
278 label. Existing bootstrap code is unchanged regardless of whether
282 is specified, no data will be written to the device, and instead the
283 disklabel that would have been written will be printed to stdout. This is
284 useful to see how a partitioning scheme will work out for a specific disk.
285 .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
312 By default, it is not possible to write to the disk label area at the beginning
313 of a disk. The disk driver silently ignores any attempt to do so. If you need
314 to write to this area (for example, to obliterate the label), use the form
320 To disallow writing to the label area after previously allowing it, use the
326 .Ss Installing bootstraps
328 The final three forms of
330 are used to install bootstrap code. If you are creating a
331 .Dq dangerously-dedicated
332 partition for compatibility with older PC systems,
333 you generally want to specify the raw disk name such as
335 If you are creating a label within an existing DOS slice, you should specify
336 the slice name such as
338 Making a partition bootable can be tricky. If you are using a normal DOS
339 slice you typically install (or leave) a standard MBR on the base disk and
342 bootblocks in the slice.
353 This form installs the bootstrap only. It does not change the disk label.
354 You should never use this command on a base disk unless you intend to create a
355 .Dq dangerously-dedicated
358 This command is typically run on a slice such as
372 This form corresponds to the
374 command described above.
375 In addition to writing a new volume label, it also installs the bootstrap.
376 If run on a base disk this command will create a
377 .Dq dangerously-dedicated
378 label. This command is normally run on a slice rather than a base disk.
381 is used, no data will be written to the device, and instead the
382 disklabel that would have been written will be printed to stdout.
392 .Ar disk Ar protofile
395 This form corresponds to the
397 command described above.
398 In addition to restoring the volume label, it also installs the bootstrap.
399 If run on a base disk this command will create a
400 .Dq dangerously-dedicated
401 label. This command is normally run on a slice rather than a base disk.
403 The bootstrap commands always access the disk directly, so it is not necessary
408 is used, no data will be written to the device, and instead the
409 disklabel that would have been written will be printed to stdout.
411 The bootstrap code is comprised of two boot programs. Specify the name of the
412 boot programs to be installed in one of these ways:
415 Specify the names explicitly with the
421 indicates the primary boot program and
423 the secondary boot program. The boot programs are located in
430 flags are not specified, but
432 was specified, the names of the programs are taken from the
438 entry for the disk if the disktab entry exists and includes those parameters.
440 Otherwise, the default boot image names are used:
444 for the standard stage1 and stage2 boot images (details may vary
445 on architectures like the Alpha, where only a single-stage boot is used).
447 .Ss Initializing/Formatting a bootable disk from scratch
449 To initialize a disk from scratch the following sequence is recommended.
450 Please note that this will wipe everything that was previously on the disk,
458 to initialize the DOS partition table, creating a real whole-disk slice to
461 disklabel, and installing a master boot record.
465 to initialize a virgin
467 disklabel and install
473 to edit your newly created label, adding appropriate partitions.
475 Finally newfs the filesystem partitions you created in the label. A typical
476 disklabel partitioning scheme would be to have an
479 of approximately 128MB to hold the root filesystem, a
484 partition for /var (usually 128MB), an
487 for /var/tmp (usually 128MB), an
489 partition for /usr (usually around 2G),
492 partition for /home (usually all remaining space).
493 Your mileage may vary.
496 .Nm fdisk Fl BI Ar da0
509 .Bl -tag -width Pa -compact
514 .Sh SAVED FILE FORMAT
516 uses an ASCII version of the label when examining, editing or restoring a disk
517 label. The format is:
518 .Bd -literal -offset 4n
527 sectors/cylinder: 969
529 sectors/unit: 1173930
534 headswitch: 0 # milliseconds
535 track-to-track seek: 0 # milliseconds
539 # size offset fstype [fsize bsize bps/cpg]
540 a: 81920 0 4.2BSD 1024 8192 16 # (Cyl. 0 - 84*)
541 b: 160000 81920 swap # (Cyl. 84* - 218*)
542 c: 1173930 0 unused 0 0 # (Cyl. 0 - 1211*)
543 h: 962010 211920 vinum # (Cyl. 218*- 1211*)
546 Lines starting with a # mark are comments. Most of the other specifications are
547 no longer used. The ones which must still be set correctly are:
551 is an optional label, set by the
553 option when writing a label.
561 is set for removable media drives, but no current
563 driver evaluates this
566 is no longer supported;
568 specifies that the drive can perform bad sector remapping.
570 describes the total size of the disk. This value must be correct.
571 .It Nm the partition table
574 partition table, not the Microsoft partition table described in
578 The partition table can have up to 8 entries. It contains the following
582 The partition identifier is a single letter in the range
586 By convention, partition
588 is reserved to describe the entire disk.
590 is the size of the partition in sectors,
594 (megabytes - 1024*1024),
596 (gigabytes - 1024*1024*1024),
598 (percentage of free space AFTER removing any fixed-size partitions other
603 (all remaining free space AFTER fixed-size and percentage
604 partitions). For partition
608 indicates the entire disk. Lowercase versions of
613 Size and type should be specifed without any spaces between them.
615 Example: 2097152, 1g, 1024m and 1048576k are all the same size
616 (assuming 512-byte sectors).
618 is the offset of the start of the partition from the beginning of the
623 calculate the correct offset to use (the end of the previous partition plus
624 one, ignoring partition
629 will be interpreted as an offset of 0.
631 describes the purpose of the partition. The example shows all currently used
633 For UFS file systems and ccd partitions, use type
635 For Vinum drives, use type
637 Other common types are
641 By convention, partition
643 represents the entire slice and should be of type
647 does not enforce this convention.
649 also knows about a number of other partition types, none of which are in current
651 See the definitions starting with
654 .Pa /usr/include/sys/disklabel.h
659 and LFS file systems only, the fragment size. Defaults to 1024 for
660 partitions smaller than 1 GB, 4096 for partitions 1GB or larger.
664 and LFS file systems only, the block size. Defaults to 8192 for
665 partitions smaller than 1 GB, 16384 for partitions 1GB or larger.
669 file systems, the number of cylinders in a cylinder group. For LFS file
670 systems, the segment shift value. Defaults to 16 for
671 partitions smaller than 1 GB, 64 for partitions 1GB or larger.
674 The remainder of the line is a comment and shows the cylinder allocations based
675 on the obsolete (but possibly correct) geometry information about the drive.
676 The asterisk (*) indicates that the partition does not begin or end exactly on a
681 Display the in-core label for
685 When reading a label,
687 will allow you to specify the base disk name
688 even if the label resides on a slice. However, to be proper you should
689 specify the base disk name only if you are using a
690 .Dq dangerously-dedicated
691 label. Normally you specify the slice.
693 .Dl disklabel da0s1 > savedlabel
695 Save the in-core label for
699 This file can be used with the
701 flag to restore the label at a later date.
703 .Dl disklabel -w -r /dev/da0s1 da2212 foo
707 based on information for
711 Any existing bootstrap code will be clobbered.
713 .Dl disklabel -e -r da0s1
715 Read the on-disk label for
717 edit it and reinstall in-core as well as on-disk. Existing bootstrap code is
720 .Dl disklabel -e -r -n da0s1
722 Read the on-disk label for
724 edit it, and display what the new label would be (in sectors). It does
725 NOT install the new label either in-core or on-disk.
727 .Dl disklabel -r -w da0s1 auto
729 Try to auto-detect the required information from
731 and write a new label to the disk. Use another disklabel -e command to edit the
732 partitioning and file system information.
734 .Dl disklabel -R da0s1 savedlabel
736 Restore the on-disk and in-core label for
740 Existing bootstrap code is unaffected.
742 .Dl disklabel -R -n da0s1 label_layout
744 Display what the label would be for
746 using the partition layout in
748 This is useful for determining how much space would be alloted for various
749 partitions with a labelling scheme using
755 .Dl disklabel -B da0s1
757 Install a new bootstrap on
759 The boot code comes from
763 On-disk and in-core labels are unchanged.
765 .Dl disklabel -w -B /dev/da0s1 -b newboot1 -s newboot da2212
767 Install a new label and bootstrap.
768 The label is derived from disktab information for
770 and installed both in-core and on-disk.
771 The bootstrap code comes from the files
776 .Dl dd if=/dev/zero of=/dev/da0 bs=512 count=32
778 .Dl dd if=/dev/zero of=/dev/da0s1 bs=512 count=32
779 .Dl disklabel -w -B da0s1 auto
780 .Dl disklabel -e da0s1
782 Completely wipe any prior information on the disk, creating a new bootable
783 disk with a DOS partition table containing one
786 initialize the slice, then edit it to your needs. The
788 commands are optional, but may be necessary for some BIOSes to properly
791 This is an example disklabel that uses some of the new partition size types
796 which could be used as a source file for
798 .Dl disklabel -R ad0s1c new_label_file
799 .Bd -literal -offset 4n
808 sectors/cylinder: 1008
810 sectors/unit: 40959009
815 headswitch: 0 # milliseconds
816 track-to-track seek: 0 # milliseconds
820 # size offset fstype [fsize bsize bps/cpg]
821 a: 400M 0 4.2BSD 4096 16384 75 # (Cyl. 0 - 812*)
836 The kernel device drivers will not allow the size of a disk partition
837 to be decreased or the offset of a partition to be changed while it is open.
838 Some device drivers create a label containing only a single large partition
839 if a disk is unlabeled; thus, the label must be written to the
841 partition of the disk while it is open. This sometimes requires the desired
842 label to be set in two steps, the first one creating at least one other
843 partition, and the second setting the label on the new partition while shrinking
848 On some machines the bootstrap code may not fit entirely in the area
849 allocated for it by some filesystems.
850 As a result, it may not be possible to have filesystems on some partitions
854 When installing bootstrap code,
856 checks for these cases.
857 If the installed boot code would overlap a partition of type FS_UNUSED
858 it is marked as type FS_BOOT.
861 utility will disallow creation of filesystems on FS_BOOT partitions.
862 Conversely, if a partition has a type other than FS_UNUSED or FS_BOOT,
864 will not install bootstrap code that overlaps it.
866 When a disk name is given without a full pathname,
867 the constructed device name uses the
871 For the i386 architecture, the primary bootstrap sector contains
876 takes care to not clobber it when installing a bootstrap only
878 or when editing an existing label
880 but it unconditionally writes the primary bootstrap program onto
887 table by the dummy one in the bootstrap program. This is only of
888 concern if the disk is fully dedicated, so that the
891 starts at absolute block 0 on the disk.
894 does not perform all possible error checking. Warning *is* given if partitions
895 overlap; if an absolute offset does not match the expected offset; if the
897 partition does not start at 0 or does not cover the entire slice; if a
898 partition runs past the end of the device; and a number of other errors; but
899 no warning is given if space remains unused.