.\" Copyright (c) 1987, 1988, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Symmetric Computer Systems. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 .\" $FreeBSD: src/sbin/disklabel/disklabel.8,v 1.15.2.22 2003/04/17 17:56:34 trhodes Exp $ .\" .Dd July 21, 2018 .Dt DISKLABEL64 8 .Os .Sh NAME .Nm disklabel64 .Nd read and write 64 bit disk pack label .Sh SYNOPSIS .Nm .Op Fl r .Ar disk .Nm .Op Fl x .Ar disk .Nm .Fl w .Op Fl r .Op Fl n .Ar disk .Op Ar disktype Ns / Ns Cm auto Op Ar packid .Nm .Fl e .Op Fl r .Op Fl n .Ar disk .Nm .Fl R .Op Fl r .Op Fl n .Ar disk Ar protofile .Nm .Op Fl NW .Ar disk .Pp .Nm .Fl B .Oo .Fl b Ar boot1 .Fl s Ar boot2 .Oc .Ar disk .Oo Ar disktype Ns / Ns Cm auto Oc .Nm .Fl w .Fl B .Op Fl n .Oo .Fl b Ar boot1 .Fl s Ar boot2 .Oc .Ar disk .Op Ar disktype Ns / Ns Cm auto Op Ar packid .Nm .Fl R .Fl B .Op Fl n .Oo .Fl b Ar boot1 .Fl s Ar boot2 .Oc .Ar disk Ar protofile .Oo Ar disktype Ns / Ns Cm auto Oc .Sh DESCRIPTION The .Nm utility installs, examines or modifies a 64 bit label on a disk drive or pack. When writing the label, it can be used to change the drive identification, the disk partitions on the drive, or to replace a damaged label. There are several forms of the command that read (display), install or edit the label on a disk. In addition, .Nm can install bootstrap code. .Ss Raw or in-core label The disk label resides close to or at the beginning of each disk slice. For faster access, the kernel maintains a copy in core at all times. By default, most forms of the .Nm command access the in-core copy of the label. To access the raw (on-disk) copy, use the .Fl r option. This option allows a label to be installed on a disk without kernel support for a label, such as when labels are first installed on a system; it must be used when first installing a label on a disk. The specific effect of .Fl r is described under each command. .Ss Disk device name All .Nm forms require a disk device name, which should always be the raw device name representing the disk or slice. .Dx uses the following scheme for slice numbering: If the disk doesn't use GPT (typically laid out by .Xr gpt 8 ) , but e.g.\& MBR (typically laid out by .Xr fdisk 8 ) , then slice 0, e.g.\& .Pa da0s0 , represents the entire disk regardless of any DOS partitioning. Slice 0 is called the compatibility slice, and slice 1 and onward, e.g.\& .Pa da0s1 , represents a .Bx slice. If the disk does use GPT, then all slices are .Bx slices, slice 0 isn't special, it is just the first slice on the disk. You do not have to include the .Pa /dev/ path prefix when specifying the device. The .Nm utility will automatically prepend it. .Ss Reading the disk label To examine the label on a disk drive, use .Nm without options: .Pp .Nm .Op Fl r .Ar disk .Pp .Ar disk represents the raw disk in question, and may be in the form .Pa da0s1 or .Pa /dev/da0s1 . It will display all of the parameters associated with the drive and its partition layout. Unless the .Fl r flag is given, the kernel's in-core copy of the label is displayed; if the disk has no label, or the partition types on the disk are incorrect, the kernel may have constructed or modified the label. If the .Fl r flag is given, .Nm reads the label from the raw disk and displays it. Both versions are usually identical except in the case where a label has not yet been initialized or is corrupt. .Ss Writing a standard label To write a standard label, use the form .Pp .Nm .Fl w .Op Fl r .Op Fl n .Ar disk .Op Ar disktype Ns / Ns Cm auto Op Ar packid .Pp The required argument to .Nm is the drive to be labeled. The first optional argument is the drive type as described in the .Xr disktab 5 file, from which the drive parameters and partitions are taken. If not specified, then the .Cm auto type is assumed to make a virgin label for the disk as described below. If different disks of the same physical type are to have different partitions, it will be necessary to have separate disktab entries describing each, or to edit the label after installation as described below. The optional argument is a pack identification string, up to 63 characters long. The pack id must be quoted if it contains blanks. .Pp If the .Fl n flag is given, no data will be written to the device, and instead the disklabel that would have been written will be printed to stdout. .Pp If the .Fl r flag is given, the disk sectors containing the label and bootstrap will be written directly. A side-effect of this is that any existing bootstrap code will be overwritten and the disk rendered unbootable. See the boot options below for a method of writing the label and the bootstrap at the same time. If .Fl r is not specified, the existing label will be updated via the in-core copy and any bootstrap code will be unaffected. If the disk does not already have a label, the .Fl r flag must be used. In either case, the kernel's in-core label is replaced. .Pp For a virgin disk that is not known to .Xr disktab 5 , .Ar disktype can be specified as .Cm auto . In this case, the driver is requested to produce a virgin label for the disk. This might or might not be successful, depending on whether the driver for the disk is able to get the required data without reading anything from the disk at all. It will likely succeed for all SCSI disks, most IDE disks, and vnode devices. Writing a label to the disk is the only supported operation. .Pp For most harddisks, a label based on percentages for most partitions (and one partition with a size of .Ql * ) will produce a reasonable configuration. .Pp PC-based systems have special requirements in order for the BIOS to properly recognize a .Dx disklabel. Older systems may require what is known as a .Dq dangerously dedicated disklabel, which creates a fake DOS partition to work around problems older BIOSes have with modern disk geometries. On newer systems you generally want to create a normal DOS partition using .Ar fdisk and then create a .Dx disklabel within that slice. This is described later on in this page. .Pp Installing a new disklabel does not in of itself allow your system to boot a kernel using that label. You must also install boot blocks, which is described later on in this manual page. .Ss Editing an existing disk label To edit an existing disk label, use the form .Pp .Nm .Fl e .Op Fl r .Op Fl n .Ar disk .Pp This command reads the label from the in-core kernel copy, or directly from the disk if the .Fl r flag is also specified. The label is written to a file in ASCII and then supplied to an editor for changes. If no editor is specified in an .Ev EDITOR environment variable, .Xr vi 1 is used. When the editor terminates, the label file is used to rewrite the disk label. Existing bootstrap code is unchanged regardless of whether .Fl r was specified. If .Fl n is specified, no data will be written to the device, and instead the disklabel that would have been written will be printed to stdout. This is useful to see how a partitioning scheme will work out for a specific disk. .Ss Restoring a disk label from a file To restore a disk label from a file, use the form .Pp .Nm .Fl R .Op Fl r .Op Fl n .Ar disk Ar protofile .Pp .Nm is capable of restoring a disk label that was previously saved in a file in ASCII format. The prototype file used to create the label should be in the same format as that produced when reading or editing a label. Comments are delimited by .Ql # and newline. As when writing a new label, any existing bootstrap code will be clobbered if .Fl r is specified and will be unaffected otherwise. See the boot options below for a method of restoring the label and writing the bootstrap at the same time. If .Fl n is used, no data will be written to the device, and instead the disklabel that would have been written will be printed to stdout. This is useful to see how a partitioning scheme will work out for a specific disk. .Ss Enabling and disabling writing to the disk label area By default, it is not possible to write to the disk label area at the beginning of a disk. The disk driver arranges for .Xr write 2 and similar system calls to return .Er EROFS on any attempt to do so. If you need to write to this area (for example, to obliterate the label), use the form .Pp .Nm .Fl W .Ar disk .Pp To disallow writing to the label area after previously allowing it, use the command .Pp .Nm .Fl N .Ar disk .Ss Installing bootstraps The final three forms of .Nm are used to install bootstrap code, which allows boot from a .Xr HAMMER 5 , .Xr HAMMER2 5 , or .Xr UFS 5 file system. If you are creating a .Dq dangerously-dedicated slice for compatibility with older PC systems, you generally want to specify the compatibility slice, such as .Pa da0s0 . If you are creating a label within an existing DOS slice, you should specify the slice name such as .Pa da0s1 . Making a slice bootable can be tricky. If you are using a normal DOS slice you typically install (or leave) a standard MBR on the base disk and then install the .Dx bootblocks in the slice. .Pp .Nm .Fl B .Oo .Fl b Ar boot1 .Fl s Ar boot2 .Oc .Ar disk .Oo Ar disktype Ns / Ns Cm auto Oc .Pp This form installs the bootstrap only. It does not change the disk label. You should never use this command on the compatibility slice unless you intend to create a .Dq dangerously-dedicated disk, such as .Ar da0s0 . This command is typically run on a .Bx slice such as .Ar da0s1 . .Pp .Nm .Fl w .Fl B .Op Fl n .Oo .Fl b Ar boot1 .Fl s Ar boot2 .Oc .Ar disk .Op Ar disktype Ns / Ns Cm auto Op Ar packid .Pp This form corresponds to the .Dq write label command described above. In addition to writing a new volume label, it also installs the bootstrap. If run on the compatibility slice this command will create a .Dq dangerously-dedicated label. This command is normally run on a .Bx slice rather than the compatibility slice. If .Fl n is used, no data will be written to the device, and instead the disklabel that would have been written will be printed to stdout. .Pp .Nm .Fl R .Fl B .Op Fl n .Oo .Fl b Ar boot1 .Fl s Ar boot2 .Oc .Ar disk Ar protofile .Oo Ar disktype Ns / Ns Cm auto Oc .Pp This form corresponds to the .Dq restore label command described above. In addition to restoring the volume label, it also installs the bootstrap. If run on the compatibility slice this command will create a .Dq dangerously-dedicated label. This command is normally run on a .Bx slice rather than the compatibility slice. .Pp The bootstrap commands always access the disk directly, so it is not necessary to specify the .Fl r flag. If .Fl n is used, no data will be written to the device, and instead the disklabel that would have been written will be printed to stdout. .Pp The bootstrap code is comprised of two boot programs. Specify the name of the boot programs to be installed in one of these ways: .Bl -enum .It Specify the names explicitly with the .Fl b and .Fl s flags. .Fl b indicates the primary boot program and .Fl s the secondary boot program. The boot programs are normally located in .Pa /boot . .It If the .Fl b and .Fl s flags are not specified, but .Ar disktype was specified, the names of the programs are taken from the .Dq b0 and .Dq b1 parameters of the .Xr disktab 5 entry for the disk if the disktab entry exists and includes those parameters. .It Otherwise, the default boot image names are used: .Pa /boot/boot1_64 and .Pa /boot/boot2_64 for the standard stage1 and stage2 boot images. .El .Ss Initializing/Formatting a bootable disk from scratch To initialize a disk from scratch the following sequence is recommended. Please note that this will wipe everything that was previously on the disk, including any .No non- Ns Dx slices. .Bl -enum .It Use .Xr gpt 8 or .Xr fdisk 8 to initialize the hard disk, and create a GPT or MBR slice table, referred to as the .Dq "partition table" in .Tn DOS . .It Use .Nm or .Xr disklabel32 8 to define partitions on .Dx slices created in the previous step. .It Finally use .Xr newfs_hammer 8 , .Xr newfs_hammer2 8 , or .Xr newfs 8 to create file systems on new partitions. .El .Pp A typical partitioning scheme would be to have an .Ql a partition of approximately 1 GB for .Pa /boot to hold the current, old (and backup) kernels and modules, a .Ql b partition for swap (suggested to be at least the same size as the physical memory), and finally a .Ql d partition for the root file system (usually all remaining space). Your mileage may vary. .Pp .Dl "gpt init -f -B da0" .Dl "disklabel64 -B -r -w da0s1" .Dl "disklabel64 -e da0s1" .Ss Expanding the disklabel The .Fl x[x] option may be used to expand an existing disklabel to cover an expanded storage device. This is useful when an image is copied to larger underlying storage. If specified twice, the last partition will also be expanded to fill the area. Mounted HAMMER2 filesystems can also be expanded to cover the new space in the partition. .Pp .Dl "gpt expand da0" .Dl "disklabel64 -xx da0s1" .Dl "hammer2 growfs /blahblah" .Sh ALIGNMENT When a virgin disklabel64 is laid down a .Dx 2.5 or later kernel will align the partition start offset relative to the physical drive instead of relative to the slice start. This overcomes the issue of fdisk creating a badly aligned slice by default. The kernel will use a 1MiB (1024 * 1024 byte) alignment. The purpose of this alignment is to match swap and cluster operations against the physical block size of the underlying device. .Pp Even though nearly all devices still report a logical sector size of 512, newer hard drives are starting to use larger physical sector sizes and, in particular, solid state drives (SSDs) use a physical block size of 64K (SLC) or 128K (MLC). We choose a 1 megabyte alignment to cover our bases down the road. 64-bit disklabels are not designed to be put on ultra-tiny storage devices. .Pp It is worth noting that aligning cluster operations is particularly important for SSDs and doubly so when .Xr swapcache 8 is used with a SSD. Swapcache is able to use large bulk writes which greatly reduces the degree of write magnification on SSD media and it is possible to get upwards of 5x more endurance out of the device than the vendor spec sheet indicates. .Sh FILES .Bl -tag -width ".Pa /boot/boot2_64" -compact .It Pa /boot/boot1_64 Default stage1 boot image. .It Pa /boot/boot2_64 Default stage2 boot image. .It Pa /etc/disktab Disk description file. .El .Sh SAVED FILE FORMAT The .Nm utility uses an .Tn ASCII version of the label when examining, editing, or restoring a disk label. An example shows as below: .Bd -literal -offset 4n # /dev/ad0s1: # # Calculated informational fields for the slice: # # boot space: 1012224 bytes # data space: 156286976 blocks # 152624.00 MB (160037863424 bytes) # # NOTE: The partition data base and stop are physically # aligned instead of slice-relative aligned. # # All byte equivalent offsets must be aligned. # diskid: 5dc53a64-c5e5-11e7-8aec-011d0988acd3 label: boot2 data base: 0x000000001000 partitions data base: 0x0000000f8200 partitions data stop: 0x0025430f8200 backup label: 0x002543157200 total size: 0x002543158200 # 152625.34 MB alignment: 4096 display block size: 1024 # for partition display and edit only 16 partitions: # size offset fstype fsuuid a: 1048576 0 4.2BSD # 1024.000MB b: 16777216 1048576 swap # 16384.000MB d: 138461184 17825792 HAMMER # 135216.000MB a-stor_uuid: 7f1ff0ee-c5ec-11e7-8aec-011d0988acd3 b-stor_uuid: 7f1ff0fc-c5ec-11e7-8aec-011d0988acd3 d-stor_uuid: 7f1ff108-c5ec-11e7-8aec-011d0988acd3 .Ed .Pp Lines starting with a .Ql # mark are comments. The specifications which can be changed are: .Bl -inset .It Ar label is an optional label, set by the .Ar packid option when writing a label. .It Ar "the partition table" is the .Ux partition table, not the .Tn DOS partition table described in .Xr fdisk 8 . .El .Pp The partition table can have up to 16 entries. It contains the following information: .Bl -tag -width indent .It Ar # The partition identifier is a single letter in the range .Ql a to .Ql p . .It Ar size The size of the partition in sectors, .Cm K (kilobytes - 1024), .Cm M (megabytes - 1024*1024), .Cm G (gigabytes - 1024*1024*1024), .Cm T (terabytes - 1024*1024*1024*1024), .Cm % (percentage of free space .Em after removing any fixed-size partitions), .Cm * (all remaining free space .Em after fixed-size and percentage partitions). Lowercase versions of .Cm K , M , G , and .Cm T are allowed. Size and type should be specified without any spaces between them. .Pp Example: 2097152, 1G, 1024M and 1048576K are all the same size (assuming 512-byte sectors). .It Ar offset The offset of the start of the partition from the beginning of the drive in sectors, or .Cm * to have .Nm calculate the correct offset to use (the end of the previous partition plus one. .It Ar fstype The name of the filesystem type for the partition (case insensitive). For .Xr UFS 5 file systems, use type .Cm 4.2BSD . For .Xr HAMMER 5 file systems, use type .Cm HAMMER . For .Xr hammer2 8 file systems, use type .Cm HAMMER2 . For .Xr ccd 4 partitions, use type .Cm ccd . For Vinum drives, use type .Cm vinum . Other common types are .Cm swap and .Cm unused . The .Nm utility also knows about a number of other partition types, none of which are in current use. (See .Dv fstypenames in .In sys/dtype.h for more details). .El .Pp The remainder of the line is a comment and shows the size of the partition in MB. .Sh EXAMPLES .Dl "disklabel64 da0s1" .Pp Display the in-core label for the first slice of the .Pa da0 disk, as obtained via .Pa /dev/da0s1 . (If the disk is .Dq dangerously-dedicated , the compatibility slice name should be specified, such as .Pa da0s0 . ) .Pp .Dl "disklabel64 da0s1 > savedlabel" .Pp Save the in-core label for .Pa da0s1 into the file .Pa savedlabel . This file can be used with the .Fl R option to restore the label at a later date. .Pp .Dl "disklabel64 -e -r da0s1" .Pp Read the on-disk label for .Pa da0s1 , edit it, and reinstall in-core as well as on-disk. Existing bootstrap code is unaffected. .Pp .Dl "disklabel64 -e -r -n da0s1" .Pp Read the on-disk label for .Pa da0s1 , edit it, and display what the new label would be. It does .Em not install the new label either in-core or on-disk. .Pp .Dl "disklabel64 -r -w da0s1" .Pp Try to auto-detect the required information from .Pa da0s1 , and write a new label to the disk. Use another .Nm Fl e command to edit the partitioning information. .Pp .Dl "disklabel64 -R da0s1 savedlabel" .Pp Restore the on-disk and in-core label for .Pa da0s1 from information in .Pa savedlabel . Existing bootstrap code is unaffected. .Pp .Dl "disklabel64 -R -n da0s1 label_layout" .Pp Display what the label would be for .Pa da0s1 using the partition layout in .Pa label_layout . This is useful for determining how much space would be allotted for various partitions with a labelling scheme using .Cm % Ns -based or .Cm * partition sizes. .Pp .Dl "disklabel64 -B da0s1" .Pp Install a new bootstrap on .Pa da0s1 . The boot code comes from .Pa /boot/boot1_64 and possibly .Pa /boot/boot2_64 . On-disk and in-core labels are unchanged. .Pp .Dl "disklabel64 -w -B /dev/da0s1 -b newboot1 -s newboot2" .Pp Install a new label and bootstrap, with bootstrap code comes from the files .Pa newboot1 and .Pa newboot2 . .Pp .Dl "dd if=/dev/zero of=/dev/da0 bs=512 count=32" .Dl "fdisk -BI da0" .Dl "dd if=/dev/zero of=/dev/da0s1 bs=512 count=32" .Dl "disklabel64 -w -B da0s1" .Dl "disklabel64 -e da0s1" .Pp Completely wipe any prior information on the disk, creating a new bootable disk with a DOS partition table containing one .Dq whole-disk slice. Then initialize the slice, then edit it to your needs. The .Pa dd commands are optional, but may be necessary for some BIOSes to properly recognize the disk. .Pp .Dl "disklabel64 -W da0s1" .Dl "dd if=/dev/zero of=/dev/da0s1 bs=512 count=32" .Dl "disklabel32 -r -w da0s1" .Dl "disklabel32 -N da0s1" .Pp Completely wipe any prior information on the slice, and install the old 32-bit label. The wiping is needed because both .Nm disklabel32 and .Nm , as a safety measure, won't do any operations if label with other format is already installed. .Pp This is an example disklabel that uses some of the new partition size types such as .Cm % , M , G , T , and .Cm * , which could be used as a source file for: .Pp .Dl "disklabel64 -R ad0s1 new_label_file" .Bd -literal -offset 4n # /dev/ad0s1: # # Calculated informational fields for the slice: # # boot space: 1012224 bytes # data space: 156286976 blocks # 152624.00 MB (160037863424 bytes) # # NOTE: The partition data base and stop are physically # aligned instead of slice-relative aligned. # # All byte equivalent offsets must be aligned. # diskid: 5dc53a64-c5e5-11e7-8aec-011d0988acd3 label: boot2 data base: 0x000000001000 partitions data base: 0x0000000f8200 partitions data stop: 0x0025430f8200 backup label: 0x002543157200 total size: 0x002543158200 # 152625.34 MB alignment: 4096 display block size: 1024 # for partition display and edit only 16 partitions: # size offset fstype fsuuid a: 1024M 0 4.2BSD b: 4G * swap d: 2G * 4.2BSD e: 2048M * 4.2BSD f: 4G * 4.2BSD g: 4G * 4.2BSD h: 50G * HAMMER i: * * HAMMER2 j: 5g * ccd k: 5120m * vinum .Ed .Sh DIAGNOSTICS The kernel device drivers will not allow the size of a disk partition to be decreased or the offset of a partition to be changed while it is open. Some device drivers create a label containing only a single large partition if a disk is unlabeled; thus, the label must be written to the .Ql a partition of the disk while it is open. This sometimes requires the desired label to be set in two steps, the first one creating at least one other partition, and the second setting the label on the new partition while shrinking the .Ql a partition. .Sh SEE ALSO .Xr dd 1 , .Xr uuid 3 , .Xr ccd 4 , .Xr disklabel64 5 , .Xr disktab 5 , .Xr boot0cfg 8 , .Xr diskinfo 8 , .Xr disklabel32 8 , .Xr fdisk 8 , .Xr gpt 8 , .Xr hammer2 8 , .Xr newfs 8 , .Xr newfs_hammer 8 , .Xr newfs_hammer2 8 , .Xr vinum 8 .Sh BUGS The .Nm utility does not perform all possible error checking. Warning .Em is given if partitions overlap; if an absolute offset does not match the expected offset; if a partition runs past the end of the device; and a number of other errors; but no warning is given if space remains unused. .Pp The .Xr disktab 5 support is not implemented.