xref: /openbsd-src/sbin/disklabel/disklabel.8 (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1.\"	$OpenBSD: disklabel.8,v 1.104 2011/09/04 08:29:46 jmc Exp $
2.\"	$NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $
3.\"
4.\" Copyright (c) 1987, 1988, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" Symmetric Computer Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"	@(#)disklabel.8	8.2 (Berkeley) 4/19/94
35.\"
36.Dd $Mdocdate: September 4 2011 $
37.Dt DISKLABEL 8
38.Os
39.Sh NAME
40.Nm disklabel
41.Nd read and write disk pack label
42.Sh SYNOPSIS
43.Nm disklabel
44.Op Fl c | d | t
45.Op Fl Av
46.Op Fl h | p Ar unit
47.Ar disk
48.Nm disklabel
49.Fl w
50.Op Fl c | d
51.Op Fl Anv
52.Ar disk Ar disktype
53.Op Ar packid
54.Nm disklabel
55.Fl e
56.Op Fl c | d
57.Op Fl Anv
58.Ar disk
59.Nm disklabel
60.Fl E
61.Op Fl c | d
62.Op Fl Anv
63.Op Fl F Ns | Ns Fl f Ar file
64.Ar disk
65.Nm disklabel
66.Fl R
67.Op Fl nv
68.Ar disk Ar protofile
69.Pp
70.Nm disklabel
71.Fl B\ \&
72.Op Fl nv
73.Op Fl b Ar boot1
74.Op Fl s Ar boot2
75.Ar disk
76.Op Ar disktype
77.Nm disklabel
78.Fl Bw
79.Op Fl nv
80.Op Fl b Ar boot1
81.Op Fl s Ar boot2
82.Ar disk Ar disktype
83.Op Ar packid
84.Nm disklabel
85.Fl BR
86.Op Fl nv
87.Op Fl b Ar boot1
88.Op Fl s Ar boot2
89.Ar disk Ar protofile
90.Op Ar disktype
91.Sh DESCRIPTION
92The
93.Nm
94utility can be used to install, examine, or modify the label on a disk drive or
95pack.
96The disk label contains information about disk characteristics
97.Pq size, type, etc.
98and the partition layout, stored on the disk itself.
99It is used by the operating system to optimize disk I/O and
100locate the filesystems resident on the disk.
101.Pp
102.Nm
103supports 15 configurable partitions,
104.Sq a
105through
106.Sq p ,
107excluding
108.Sq c .
109The
110.Sq c
111partition describes the entire physical disk, is automatically created
112by the kernel, and cannot be modified or deleted by
113.Nm .
114By convention, the
115.Sq a
116partition of the boot disk is the root partition, and the
117.Sq b
118partition of the boot disk is the swap partition,
119but all other letters can be used in any order for any other
120partitions as desired.
121.Pp
122The options are as follows:
123.Bl -tag -width Ds
124.It Fl A
125Automatically allocate all the disk space in the
126.Ox
127portion of the disk in the recommended manner.
128See
129.Sx AUTOMATIC DISK ALLOCATION ,
130below.
131.It Fl B
132Install bootstrap code.
133Some architectures instead require bootstrap code installation to be
134done using an
135.Xr installboot 8
136type program, as described in
137.Xr boot 8 .
138.It Fl b Ar boot1
139Specify the single level boot program, or the primary boot program,
140depending on the system boot architecture
141.Pq single or two-level .
142.It Fl c
143Clear the system's in-core copy of the label and update it based on
144the on-disk label.
145.It Fl d
146Use the
147.Em default
148label.
149This ignores any existing
150.Ox
151disk label on the disk.
152.It Fl E
153Use the built-in command-driven label editor described below.
154.It Fl e
155Edit an existing disk label using the editor specified in the
156.Ev EDITOR
157environment variable, or
158.Xr vi 1
159if none is specified.
160.It Fl F Ar file
161Write entries to
162.Ar file
163in
164.Xr fstab 5
165format for any partitions for which mount point information is known.
166The entries will be written using disklabel UIDs.
167The
168.Fl F
169flag is only valid when used in conjunction with the
170.Fl E
171or
172.Fl A
173flags.
174If
175.Ar file
176already exists, it will be overwritten.
177.It Fl f Ar file
178The same as
179.Fl F
180except that entries will be written using disk device names.
181.It Fl h
182Print partition sizes in human readable format.
183.It Fl n
184Make no permanent changes to the disklabel
185.Pq useful for debugging purposes .
186.It Fl p Ar unit
187Print partition sizes in
188.Ar unit
189instead of sectors.
190Valid units are b(ytes), c(ylinders), k(ilobytes), m(egabytes), g(igabytes)
191and t(erabytes).
192For operations other than displaying a partition the
193.Ql %
194(percent of total) and
195.Ql &
196(percent of free) units are also accepted.
197.It Fl R
198Restore a disk label that was formatted in a prior operation and
199saved in an
200.Tn ASCII
201file.
202.It Fl s Ar boot2
203On machines with a two-level bootstrap
204.Pq such as i386-based systems ,
205specify the secondary boot program.
206.It Fl t
207Format the label as a
208.Xr disktab 5
209entry.
210.It Fl v
211Print additional information during operation
212.Pq verbose mode .
213.It Fl w
214Write a standard label on the designated drive.
215.It Ar disk
216Specify the
217.Ar disk
218to operate on.
219It can be specified by its full pathname, by an abbreviated disk form,
220or by its disklabel UID.
221In its abbreviated form, the path to the device, the
222.Sq r
223denoting
224.Qq raw device ,
225and the partition letter, can all be omitted.
226For example, the first IDE disk can be specified as either
227.Pa /dev/rwd0c ,
228.Pa /dev/wd0c ,
229or
230.Ar wd0 .
231.It Ar disktype
232Specify a
233.Ar disktype
234entry from the
235.Xr disktab 5
236database.
237.It Ar packid
238Specify a pack identification string for the device
239.Pq see below .
240.It Ar protofile
241Used with the restore option
242.Pq Fl R
243to specify a file to read an ASCII label from.
244.El
245.Pp
246The first form of the command
247.Pq read
248is used to examine the label on the named disk drive.
249It will display all of the parameters associated with the drive
250and its partition layout.
251The kernel's in-core copy of the label is displayed; if
252the disk has no label, or the partition types on the disk are
253incorrect, the kernel may have constructed or modified the label.
254.Pp
255The second form of the command
256.Pq write
257is used to write a standard label on the designated drive.
258The drive parameters and partitions are taken from that file.
259If different disks of the same physical type are
260to have different partitions, it will be necessary to have separate
261disktab entries describing each, or to edit the label after
262installation as described below.
263The optional argument is a pack
264identification string, up to 16 characters long.
265The pack ID must be quoted if it contains blanks.
266The existing label will be updated via the in-core
267copy and any bootstrap code will be unaffected.
268.Pp
269In the third form of the command
270.Pq edit ,
271the label is read from the in-core kernel copy
272and then supplied to an editor for changes.
273If no editor is specified in an
274.Ev EDITOR
275environment variable,
276.Xr vi 1
277is used.
278When the editor terminates, the formatted label is reread and
279used to rewrite the disk label.
280Existing bootstrap code is unchanged.
281.Pp
282The built-in label editor
283.Pq fourth form
284provides a simple interactive label editor.
285Some commands or prompts take an optional unit.
286Available units are
287.Sq b
288for bytes,
289.Sq c
290for cylinders,
291.Sq k
292for kilobytes,
293.Sq m
294for megabytes,
295.Sq g
296for gigabytes,
297and
298.Sq t
299for terabytes.
300If no unit is given, the default is to use sectors
301(usually 512 bytes).
302Quantities will be rounded to the nearest
303cylinder when units are specified for sizes
304.Pq or offsets .
305Commands may be aborted by entering
306.Ql ^D
307.Pq Control-D .
308Entering
309.Ql ^D
310at the main
311.Ql >
312prompt will exit the editor.
313At prompts that request a size,
314.Ql *
315may be entered to indicate the rest of the available space.
316The editor commands are as follows:
317.Bl -tag -width "p [unit] "
318.It Cm \&? \*(Ba h
319Display help message with all available commands.
320There is also
321.Pq simple
322context-sensitive help available at most prompts.
323.It Cm A
324Allocate all the disk space in the recommended manner.
325See
326.Sx AUTOMATIC DISK ALLOCATION ,
327below.
328.It Cm a Op Ar part
329Add new partition.
330This option adds a new partition to the disk label.
331If no partition letter is specified
332.Pq a\-p ,
333the user will be prompted for one.
334.It Cm b
335Set
336.Ox
337disk boundaries.
338This option tells
339.Nm
340which parts of the disk it is allowed to modify.
341This option is probably only useful for ports with
342.Xr fdisk 8
343partition tables where the ending sector in the MBR is incorrect.
344The user may enter
345.Ql *
346at the
347.Dq Size
348prompt to indicate the entire size of the disk
349.Pq minus the starting sector .
350This is useful for disks where the
351fdisk partition table is incapable of storing the real size.
352Note: data may become corrupted if boundaries are extended such
353that they overlap with other resident operating systems.
354.It Cm c Op Ar part
355Change the size of an existing partition.
356If no partition is specified, the user will be prompted for one.
357The new size may be
358in terms of the aforementioned units and may also be prefixed with
359.Ql +
360or
361.Ql -
362to change the size by a relative amount.
363.It Cm D
364Sets the disk label to the default values as reported by the kernel.
365This simulates the case where there is no disk label.
366.It Cm d Op Ar part
367Delete an existing partition (or
368.Ql *
369to delete all partitions).
370If no partition is specified, the user will be prompted for one.
371.It Cm e
372Edit drive parameters.
373This option is used to set the following parameters:
374disk type, a descriptive label string, sectors/track,
375tracks/cylinder, sectors/cylinder, number of cylinders,
376total sectors, rpm, and interleave.
377.It Xo
378.Cm g
379.Op Ar d | u
380.Xc
381Set disk geometry based on what the
382.Em disk
383or
384.Em user
385thinks (the
386.Em user
387geometry is simply what the label said before
388.Nm
389made any changes).
390.It Cm i
391Change the disklabel UID, specified as a 16-character hexadecimal string.
392If set to all zeros, a new UID will automatically be allocated when the
393disklabel is written to disk.
394.It Cm l Op Ar unit
395Print the disk label header.
396.It Cm M
397Display this manual page.
398The manual page is piped through the pager specified by the
399.Ev PAGER
400environment variable or 'less' if
401.Ev PAGER
402is not set.
403.It Cm m Op Ar part
404Modify parameters for an existing partition.
405If no partition is specified, the user will be prompted for one.
406This option allows
407the user to change the filesystem type, starting offset, partition size,
408and mount point for the specified partition.
409If expert mode is enabled (see
410.Cm X
411below), then block fragment size, block size, and cylinders per group
412can also be modified.
413Note that not all parameters are configurable for non-BSD partitions.
414.It Cm n Op Ar part
415Name the mount point for an existing partition.
416If no partition is specified, the user will be prompted for one.
417This option is only valid if
418.Nm
419was invoked with the
420.Fl f
421flag.
422.It Cm p Op Ar unit
423Print the current partition list.
424If a
425.Em unit
426is given, the size and offsets are displayed in terms of the
427specified unit.
428If the unit is
429.Sq *
430it is automatically determined by the size of the smallest
431partition.
432.It Cm q
433Quit the editor.
434If any changes have been made, the user will be
435asked whether or not to save the changes to the on-disk label.
436.It Cm R Op Ar part
437Resize a partition in an automatically allocated label,
438compacting unused space between partitions with a higher offset.
439The last partition will be shrunk if necessary.
440Works only for automatically allocated labels with no spoofed partitions.
441.It Cm r
442Recalculate free space.
443This command displays all the free areas on the disk and the total
444number of free sectors.
445.It Cm s Op Ar path
446Save the label to a file in
447.Tn ASCII
448format (suitable for loading via the
449.Fl R
450option).
451If no path is specified, the user will be prompted for one.
452.It Cm U
453Undo all changes made since entering the editor.
454.It Cm u
455Undo
456.Pq or redo
457last change.
458Entering
459.Em u
460once will undo the last change.
461Entering it again will restore the change.
462.It Cm w
463Write the label to disk.
464This option will commit any changes to the on-disk label.
465.It Cm X
466Toggle
467.Dq expert mode .
468By default, some settings are reserved for experts only
469(such as the block and fragment size on ffs partitions).
470.It Cm x
471Exit the editor without saving any changes to the on-disk label.
472.It Cm z
473Zero out the existing partition table and mountpoint information,
474leaving only the 'c' partition.
475The drive parameters are not changed.
476.El
477.Pp
478In the restore form of the command
479.Pq fifth form ,
480the prototype file used to create the label should be in the same format
481as that produced when reading or editing a label.
482Comments are delimited by
483.Ar #
484and newline.
485Any existing bootstrap code will be unaffected.
486.Pp
487The final three forms of
488.Nm
489are used to install bootstrap code on machines where the bootstrap is
490part of the label.
491The bootstrap code is comprised of one or two boot programs,
492depending on the machine.
493.Pp
494When installing bootstrap code with the
495.Fl B
496flag, if the names are not explicitly given, standard boot programs
497will be used.
498The boot programs are located in
499.Pa /usr/mdec .
500The names of the programs are taken from the
501.Dq b0
502and
503.Dq b1
504parameters of the
505.Xr disktab 5
506entry for the disk if
507.Ar disktype
508was given and its disktab entry exists and includes those parameters.
509Otherwise, boot program names are derived from the name of the
510disk.
511These names are of the form
512.Pa basename Ns boot
513for the primary
514.Pq or only
515bootstrap, and
516.Pf boot Pa basename
517for the secondary bootstrap; for example,
518.Pa /usr/mdec/sdboot
519and
520.Pa /usr/mdec/bootsd
521if the disk device is
522.Em sd0 .
523.Pp
524The first of the three boot-installation forms is used to install
525bootstrap code without changing the existing label.
526It is essentially a read command with respect to the disk label itself
527and all options are related to the specification of the boot program
528as described previously.
529The final two forms are analogous to the basic write and restore versions
530except that they will install bootstrap code in addition to a new label.
531.Pp
532Note that when a disk has no real BSD disklabel, the kernel creates a
533default label so that the disk can be used.
534This default label will include other partitions found on the disk if
535they are supported on your architecture.
536For example, on systems that support
537.Xr fdisk 8
538partitions the default label will also include DOS and Linux partitions.
539However, these entries are not dynamic, they are fixed at the time
540.Nm
541is run.
542That means that subsequent changes that affect non-OpenBSD
543partitions will not be present in the default label,
544though they may be updated by hand.
545To see the default label, run
546.Nm
547with the
548.Fl d
549flag.
550.Nm
551can then be run with the
552.Fl e
553flag and any entries pasted as desired from the default label into the real one.
554.Sh AUTOMATIC DISK ALLOCATION
555The
556.Fl A
557option and the editor command
558.Cm A
559automatically create a disklabel with a set of partitions
560suitable for a majority of
561.Ox
562installations.
563Any existing
564.Ox
565disklabel on the disk is ignored, but native partitions
566that would normally be spoofed are preserved in the disklabel,
567and are not modified during the allocation process.
568.Pp
569Disk size determines the set of partitions which are created.
570Each partition is allocated space between a specified minimum
571and maximum.
572Each partition is allocated its minimum and remaining space
573is split between the partitions up to their maximum allowed space,
574which is a fixed percentage.
575Space left after all partitions have reached their maximum size
576is left unallocated.
577The sizes below are approximations,
578and may vary from architecture to architecture.
579.Pp
580.Sy Disks \*(Gt 7 Gigabytes
581.Bd -literal -offset indent -compact
582/		 5% of disk.  80M \(en 1G
583swap		 5% of disk.  80M \(en 2x max physical memory
584/tmp		 8% of disk. 120M \(en 4G
585/var		13% of disk.  80M \(en 2x size of crash dump
586/usr		 5% of disk. 900M \(en 2G
587/usr/X11R6	 3% of disk. 512M \(en 1G
588/usr/local	10% of disk.   2G \(en 10G
589/usr/src	 2% of disk.   1G \(en 2G
590/usr/obj	 4% of disk. 1.3G \(en 2G
591/home		45% of disk.   1G \(en 300G
592.Ed
593.Pp
594.Sy Disks \*(Gt 2 Gigabytes
595.Bd -literal -offset indent -compact
596/		 5% of disk. 800M \(en 2G
597swap		10% of disk.  80M \(en 2x max physical memory
598/usr		78% of disk. 900M \(en 3G
599/home		 7% of disk. 256M \(en 2G
600.Ed
601.Pp
602.Sy Disks \*(Gt 700 Megabytes
603.Bd -literal -offset indent -compact
604/		95% of disk. 700M \(en 4G
605swap		 5% of disk.   1M \(en 2x max physical memory
606.Ed
607.Sh FILES
608.Bl -tag -width Pa -compact
609.It Pa /etc/disklabels
610Directory for backup labels.
611.It Pa /etc/disktab
612Disk description file.
613.It Pa /usr/mdec/ Ns Em xx Ns boot
614Primary bootstrap.
615.It Pa /usr/mdec/boot Ns Em xx
616Secondary bootstrap.
617.El
618.Sh EXAMPLES
619Display the in-core label for sd0 as obtained via
620.Pa /dev/rsd0c :
621.Pp
622.Dl # disklabel sd0
623.Pp
624Create a label for sd0 based on information for
625.Dq sd2212
626found in
627.Pa /etc/disktab .
628Any existing bootstrap code will be clobbered.
629.Pp
630.Dl # disklabel -w /dev/rsd0c sd2212 foo
631.Pp
632Read the on-disk label from a disk with DUID 3eb7f9da875cb9ee,
633edit it and reinstall in-core as well as on-disk.
634Existing bootstrap code is unaffected.
635.Pp
636.Dl # disklabel -E 3eb7f9da875cb9ee
637.Pp
638Restore the on-disk and in-core label for sd0 from information in
639.Pa mylabel .
640Existing bootstrap code is unaffected.
641.Pp
642.Dl # disklabel -R sd0 mylabel
643.Pp
644Install a new bootstrap on sd0.
645The boot code comes from
646.Pa /usr/mdec/sdboot
647and possibly
648.Pa /usr/mdec/bootsd .
649On-disk and in-core labels are unchanged, but on some systems other
650information may be destroyed.
651Use with care.
652.Pp
653.Dl # disklabel -B sd0
654.Pp
655Install a new label and bootstrap.
656The label is derived from disktab information for
657.Dq sd2212
658and installed both in-core and
659on-disk.
660The bootstrap code comes from the file
661.Pa /usr/mdec/newboot .
662.Pp
663.Dl # disklabel -w -B /dev/rsd0c -b newboot sd2212
664.Sh DIAGNOSTICS
665The kernel device drivers will not allow the size of a disk partition
666to be decreased or the offset of a partition to be changed while
667it is open.
668Some device drivers create a label containing only a
669single large partition if a disk is unlabeled; thus, the label must
670be written to the
671.Sq a
672partition of the disk while it is open.
673This sometimes requires the desired label to be set in two steps,
674the first one creating at least one other partition, and the second
675setting the label on the new partition while shrinking the
676.Sq a
677partition.
678.Pp
679On some machines the bootstrap code may not fit entirely in the
680area allocated for it by some filesystems.
681As a result, it may
682not be possible to have filesystems on some partitions of a
683.Dq bootable
684disk.
685When installing bootstrap code,
686.Nm
687checks for these cases.
688If the installed boot code would overlap a partition of type
689.Dv FS_UNUSED
690it is marked as type
691.Dv FS_BOOT .
692The
693.Xr newfs 8
694utility will disallow creation of filesystems on
695.Dv FS_BOOT
696partitions.
697Conversely, if a partition has a type other than
698.Dv FS_UNUSED
699or
700.Dv FS_BOOT ,
701.Nm
702will not install bootstrap code that overlaps it.
703.Sh SEE ALSO
704.Xr disklabel 5 ,
705.Xr disktab 5 ,
706.Xr scan_ffs 8
707.Sh CAVEATS
708The maximum disk and partition size is 64PB.
709.Pp
710On some machines, such as Sparc and Sparc64, partition tables
711may not exhibit the full functionality described above.
712