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.\" 4. Neither the name of the University nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 32.\" $FreeBSD$ 33.\" 34.Dd March 15, 2003 35.Dt BSDLABEL 8 36.Os 37.Sh NAME 38.Nm bsdlabel 39.Nd read and write disk pack label 40.Sh SYNOPSIS 41.Nm 42.Op Fl A 43.Ar disk | Fl f Ar file 44.Nm 45.Fl w 46.Op Fl \&An 47.Op Fl B Op Fl b Ar boot 48.Op Fl m Ar machine 49.Ar disk | Fl f Ar file 50.Op Ar type 51.Nm 52.Fl e 53.Op Fl \&An 54.Op Fl B Op Fl b Ar boot 55.Op Fl m Ar machine 56.Ar disk | Fl f Ar file 57.Nm 58.Fl R 59.Op Fl \&An 60.Op Fl B Op Fl b Ar boot 61.Op Fl m Ar machine 62.Op Fl f 63.Ar disk | Fl f Ar file 64.Ar protofile 65.Sh DESCRIPTION 66The 67.Nm 68utility 69installs, examines or modifies the 70.Bx 71label on a disk partition, or on a file containing a partition image. 72In addition, 73.Nm 74can install bootstrap code. 75.Ss Disk Device Name 76When specifying the device (i.e., when the 77.Fl f 78option is not used), 79the 80.Pa /dev/ 81path prefix may be omitted; 82the 83.Nm 84utility will automatically prepend it. 85.Ss General Options 86The 87.Fl A 88option enables processing of the historical parts of the 89.Bx 90label. 91If the option is not given, suitable values are set for these fields. 92.Pp 93The 94.Fl f 95option tells 96.Nm 97that the program will operate on a file instead of a disk partition. 98.Pp 99The 100.Fl n 101option stops the 102.Nm 103program right before the disk would have been modified, and displays 104the result instead of writing it. 105.Pp 106The 107.Fl m Ar machine 108argument forces 109.Nm 110to use a layout suitable for a different architecture. 111Current valid values are 112.Ar i386 , 113.Ar amd64 , 114.Ar ia64 , 115.Ar pc98 , 116and 117.Ar alpha . 118If this option is omitted, 119.Nm 120will use a layout suitable for the current machine. 121.Ss Reading the Disk Label 122To examine the label on a disk drive, use 123.Nm 124without options: 125.Pp 126.Nm 127.Op Fl A 128.Op Fl m Ar machine 129.Ar disk 130.Pp 131.Ar disk 132represents the disk in question, and may be in the form 133.Pa da0 134or 135.Pa /dev/da0 . 136It will display the partition layout. 137.Ss Writing a Standard Label 138To write a standard label, use the form 139.Pp 140.Nm 141.Fl w 142.Op Fl \&An 143.Op Fl m Ar machine 144.Ar disk 145.Op Ar type 146.Pp 147If the drive type is specified, the entry of that name in the 148.Xr disktab 5 149file is used; otherwise a default layout is used. 150.Ss Editing an Existing Disk Label 151To edit an existing disk label, use the form 152.Pp 153.Nm 154.Fl e 155.Op Fl \&An 156.Op Fl m Ar machine 157.Ar disk 158.Pp 159This command opens the disk label in the default editor, and when the editor 160exits, the label is validated and if OK written to disk. 161.Ss Restoring a Disk Label From a File 162To restore a disk label from a file, use the form 163.Pp 164.Nm 165.Fl R 166.Op Fl \&An 167.Op Fl m Ar machine 168.Ar disk protofile 169.Pp 170.Nm 171is capable of restoring a disk label that was previously saved in a file in 172.Tn ASCII 173format. 174The prototype file used to create the label should be in the same format as that 175produced when reading or editing a label. 176Comments are delimited by 177.Ql # 178and newline. 179.Ss Installing Bootstraps 180If the 181.Fl B 182argument is specified, bootstrap code will be read from the file 183.Pa /boot/boot 184and written to the disk. 185The 186.Fl b Ar boot 187argument allows a different file to be used. 188.Sh FILES 189.Bl -tag -width ".Pa /etc/disktab" -compact 190.It Pa /boot/boot 191Default boot image. 192.It Pa /etc/disktab 193Disk description file. 194.El 195.Sh SAVED FILE FORMAT 196The 197.Nm 198utility 199uses an 200.Tn ASCII 201version of the label when examining, editing, or restoring a disk 202label. 203The format is: 204.Bd -literal -offset 4n 205 2068 partitions: 207# size offset fstype [fsize bsize bps/cpg] 208 a: 81920 0 4.2BSD 1024 8192 16 209 b: 160000 81920 swap 210 c: 1173930 0 unused 0 0 # "raw" part, don't edit 211.Ed 212.Pp 213If the 214.Fl A 215option is specified, the format is: 216.Bd -literal -offset 4n 217# /dev/da1c: 218type: SCSI 219disk: da0s1 220label: 221flags: 222bytes/sector: 512 223sectors/track: 51 224tracks/cylinder: 19 225sectors/cylinder: 969 226cylinders: 1211 227sectors/unit: 1173930 228rpm: 3600 229interleave: 1 230trackskew: 0 231cylinderskew: 0 232headswitch: 0 # milliseconds 233track-to-track seek: 0 # milliseconds 234drivedata: 0 235 2368 partitions: 237# size offset fstype [fsize bsize bps/cpg] 238 a: 81920 0 4.2BSD 1024 8192 16 239 b: 160000 81920 swap 240 c: 1173930 0 unused 0 0 # "raw" part, don't edit 241.Ed 242.Pp 243Lines starting with a 244.Ql # 245mark are comments. 246.Pp 247The partition table can have up to 8 entries. 248It contains the following information: 249.Bl -tag -width indent 250.It Ar # 251The partition identifier is a single letter in the range 252.Ql a 253to 254.Ql h . 255By convention, partition 256.Ql c 257is reserved to describe the entire disk. 258.It Ar size 259The size of the partition in sectors, 260.Cm K 261(kilobytes - 1024), 262.Cm M 263(megabytes - 1024*1024), 264.Cm G 265(gigabytes - 1024*1024*1024), 266.Cm % 267(percentage of free space 268.Em after 269removing any fixed-size partitions other than partition 270.Ql c ) , 271or 272.Cm * 273(all remaining free space 274.Em after 275fixed-size and percentage partitions). 276For partition 277.Ql c , 278a size of 279.Cm * 280indicates the entire disk. 281Lowercase versions of 282.Cm K , M , 283and 284.Cm G 285are allowed. 286Size and type should be specified without any spaces between them. 287.Pp 288Example: 2097152, 1G, 1024M and 1048576K are all the same size 289(assuming 512-byte sectors). 290.It Ar offset 291The offset of the start of the partition from the beginning of the 292drive in sectors, or 293.Cm * 294to have 295.Nm 296calculate the correct offset to use (the end of the previous partition plus 297one, ignoring partition 298.Ql c . 299For partition 300.Ql c , 301.Cm * 302will be interpreted as an offset of 0. 303.It Ar fstype 304Describes the purpose of the partition. 305The example shows all currently used partition types. 306For 307.Tn UFS 308file systems and 309.Xr ccd 4 310partitions, use type 311.Cm 4.2BSD . 312For Vinum drives, use type 313.Cm vinum . 314Other common types are 315.Cm swap 316and 317.Cm unused . 318By convention, partition 319.Ql c 320represents the entire slice and should be of type 321.Cm unused , 322though 323.Nm 324does not enforce this convention. 325The 326.Nm 327utility 328also knows about a number of other partition types, 329none of which are in current use. 330(See the definitions starting with 331.Dv FS_UNUSED 332in 333.In sys/disklabel.h 334for more details.) 335.It Ar fsize 336For 337.Cm 4.2BSD 338and 339.Tn LFS 340file systems only, the fragment size. 341Defaults to 1024 for partitions smaller than 1GB, 3424096 for partitions 1GB or larger. 343.It Ar bsize 344For 345.Cm 4.2BSD 346and 347.Tn LFS 348file systems only, the block size. 349Defaults to 8192 for partitions smaller than 1GB, 35016384 for partitions 1GB or larger. 351.It Ar bps/cpg 352For 353.Cm 4.2BSD 354file systems, the number of cylinders in a cylinder group. 355For 356.Tn LFS 357file systems, the segment shift value. 358Defaults to 16 for partitions smaller than 1GB, 35964 for partitions 1GB or larger. 360.El 361.Sh EXAMPLES 362.Dl "bsdlabel da0s1" 363.Pp 364Display the label for the first slice of the 365.Pa da0 366disk, as obtained via 367.Pa /dev/da0s1 . 368.Pp 369.Dl "bsdlabel da0s1 > savedlabel" 370.Pp 371Save the in-core label for 372.Pa da0s1 373into the file 374.Pa savedlabel . 375This file can be used with the 376.Fl R 377option to restore the label at a later date. 378.Pp 379.Dl "bsdlabel -w /dev/da0s1" 380.Pp 381Create a label for 382.Pa da0s1 . 383.Pp 384.Dl "bsdlabel -e da0s1" 385.Pp 386Read the label for 387.Pa da0s1 , 388edit it, and install the result. 389.Pp 390.Dl "bsdlabel -e -n da0s1" 391.Pp 392Read the on-disk label for 393.Pa da0s1 , 394edit it, and display what the new label would be (in sectors). 395It does 396.Em not 397install the new label either in-core or on-disk. 398.Pp 399.Dl "bsdlabel -w da0s1" 400.Pp 401Write a default label on 402.Pa da0s1 . 403Use another 404.Nm Fl e 405command to edit the 406partitioning and file system information. 407.Pp 408.Dl "bsdlabel -R da0s1 savedlabel" 409.Pp 410Restore the on-disk and in-core label for 411.Pa da0s1 412from information in 413.Pa savedlabel . 414.Pp 415.Dl "bsdlabel -R -n da0s1 label_layout" 416.Pp 417Display what the label would be for 418.Pa da0s1 419using the partition layout in 420.Pa label_layout . 421This is useful for determining how much space would be allotted for various 422partitions with a labeling scheme using 423.Cm % Ns -based 424or 425.Cm * 426partition sizes. 427.Pp 428.Dl "bsdlabel -B da0s1" 429.Pp 430Install a new bootstrap on 431.Pa da0s1 . 432The boot code comes from 433.Pa /boot/boot . 434.Pp 435.Dl "bsdlabel -w -B -b newboot /dev/da0s1" 436.Pp 437Install a new label and bootstrap. 438The bootstrap code comes from the file 439.Pa newboot 440in the current working directory. 441.Bd -literal -offset indent 442dd if=/dev/zero of=/dev/da0 bs=512 count=32 443fdisk -BI da0 444dd if=/dev/zero of=/dev/da0s1 bs=512 count=32 445bsdlabel -w -B da0s1 446bsdlabel -e da0s1 447.Ed 448.Pp 449Completely wipe any prior information on the disk, creating a new bootable 450disk with a 451.Tn DOS 452partition table containing one slice, covering the whole disk. 453Initialize the label on this slice, 454then edit it. 455The 456.Xr dd 1 457commands are optional, but may be necessary for some 458.Tn BIOS Ns es 459to properly 460recognize the disk. 461.Pp 462This is an example disk label that uses some of the new partition size types 463such as 464.Cm % , M , G , 465and 466.Cm * , 467which could be used as a source file for 468.Dq Li "bsdlabel -R ad0s1c new_label_file" : 469.Bd -literal -offset 4n 470# /dev/ad0s1c: 471 4728 partitions: 473# size offset fstype [fsize bsize bps/cpg] 474 a: 400M 0 4.2BSD 4096 16384 75 # (Cyl. 0 - 812*) 475 b: 1G * swap 476 c: * * unused 477 e: 204800 * 4.2BSD 478 f: 5g * 4.2BSD 479 g: * * 4.2BSD 480.Ed 481.Sh DIAGNOSTICS 482The kernel device drivers will not allow the size of a disk partition 483to be decreased or the offset of a partition to be changed while it is open. 484.Sh COMPATIBILITY 485Due to the use of an 486.Vt u_int32_t 487to store the number of sectors, 488.Bx 489labels are restricted to a maximum of 2^32-1 sectors. 490This usually means 2TB of disk space. 491Larger disks should be partitioned using another method such as 492.Xr gpt 8 . 493.Pp 494The various 495.Bx Ns s 496all use slightly different versions of 497.Bx 498labels and 499are not generally compatible. 500.Sh SEE ALSO 501.Xr ccd 4 , 502.Xr geom 4 , 503.Xr md 4 , 504.\" Xr bsdlabel 5 , 505.Xr disktab 5 , 506.Xr boot0cfg 8 , 507.Xr fdisk 8 , 508.Xr gpt 8 509