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