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