xref: /netbsd-src/sbin/disklabel/disklabel.8 (revision 400b2bc13cc374b12ae3265b47fe84e039ce21a1)
1*400b2bc1Swiz.\"	$NetBSD: disklabel.8,v 1.70 2019/07/02 16:47:19 wiz Exp $
20114e805Scgd.\"
3965c81a8Shpeyerl.\" Copyright (c) 1987, 1988, 1991, 1993
4965c81a8Shpeyerl.\"	The Regents of the University of California.  All rights reserved.
561f28255Scgd.\"
661f28255Scgd.\" This code is derived from software contributed to Berkeley by
761f28255Scgd.\" Symmetric Computer Systems.
861f28255Scgd.\"
961f28255Scgd.\" Redistribution and use in source and binary forms, with or without
1061f28255Scgd.\" modification, are permitted provided that the following conditions
1161f28255Scgd.\" are met:
1261f28255Scgd.\" 1. Redistributions of source code must retain the above copyright
1361f28255Scgd.\"    notice, this list of conditions and the following disclaimer.
1461f28255Scgd.\" 2. Redistributions in binary form must reproduce the above copyright
1561f28255Scgd.\"    notice, this list of conditions and the following disclaimer in the
1661f28255Scgd.\"    documentation and/or other materials provided with the distribution.
17bf07c871Sagc.\" 3. Neither the name of the University nor the names of its contributors
1861f28255Scgd.\"    may be used to endorse or promote products derived from this software
1961f28255Scgd.\"    without specific prior written permission.
2061f28255Scgd.\"
2161f28255Scgd.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2261f28255Scgd.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2361f28255Scgd.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2461f28255Scgd.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2561f28255Scgd.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2661f28255Scgd.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2761f28255Scgd.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2861f28255Scgd.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2961f28255Scgd.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3061f28255Scgd.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3161f28255Scgd.\" SUCH DAMAGE.
3261f28255Scgd.\"
337322d6fbSmycroft.\"	@(#)disklabel.8	8.2 (Berkeley) 4/19/94
34346aa5ddScgd.\"
35*400b2bc1Swiz.Dd July 2, 2019
3666db4d4bSjtc.Dt DISKLABEL 8
3773f545bbSwiz.Os
3866db4d4bSjtc.Sh NAME
3966db4d4bSjtc.Nm disklabel
4066db4d4bSjtc.Nd read and write disk pack label
4166db4d4bSjtc.Sh SYNOPSIS
4279bd2ddbSdsl.\" disklabel: read label
43990562bfSwiz.Nm
441b979fccSmlelstv.Op Fl ACDFmnrtv
45874b0026Schristos.Op Fl B Ar endian
461b979fccSmlelstv.Op Fl L Ar sector
47874b0026Schristos.Op Fl M Ar machine
481b979fccSmlelstv.Op Fl O Ar offset
491b979fccSmlelstv.Op Fl P Ar size
5066db4d4bSjtc.Ar disk
5179bd2ddbSdsl.\" disklabel -e: read/modify/write using $EDITOR
5279bd2ddbSdsl.Nm
5379bd2ddbSdsl.Fl e
541b979fccSmlelstv.Op Fl CDFImnrv
55874b0026Schristos.Op Fl B Ar endian
561b979fccSmlelstv.Op Fl L Ar sector
57874b0026Schristos.Op Fl M Ar machine
581b979fccSmlelstv.Op Fl O Ar offset
591b979fccSmlelstv.Op Fl P Ar size
6079bd2ddbSdsl.Ar disk
6179bd2ddbSdsl.\" disklabel -i: read/modify/write using builtin commands
6279bd2ddbSdsl.Nm
6379bd2ddbSdsl.Fl i
641b979fccSmlelstv.Op Fl DFImnrv
65874b0026Schristos.Op Fl B Ar endian
661b979fccSmlelstv.Op Fl L Ar sector
67874b0026Schristos.Op Fl M Ar machine
681b979fccSmlelstv.Op Fl O Ar offset
691b979fccSmlelstv.Op Fl P Ar size
7079bd2ddbSdsl.Ar disk
7179bd2ddbSdsl.\" disklabel -R: write from edited output
7279bd2ddbSdsl.Nm
7379bd2ddbSdsl.Fl R
741b979fccSmlelstv.Op Fl DFmnrv
75874b0026Schristos.Op Fl B Ar endian
761b979fccSmlelstv.Op Fl L Ar sector
77874b0026Schristos.Op Fl M Ar machine
781b979fccSmlelstv.Op Fl O Ar offset
791b979fccSmlelstv.Op Fl P Ar size
8079bd2ddbSdsl.Ar disk Ar protofile
8179bd2ddbSdsl.\" disklabel -w: write from disctab entry
82990562bfSwiz.Nm
8366db4d4bSjtc.Fl w
841b979fccSmlelstv.Op Fl DFmnrv
85874b0026Schristos.Op Fl B Ar endian
861b979fccSmlelstv.Op Fl L Ar sector
87874b0026Schristos.Op Fl M Ar machine
881b979fccSmlelstv.Op Fl O Ar offset
891b979fccSmlelstv.Op Fl P Ar size
90593d6c65Sabs.Op Fl f Ar disktab
91965c81a8Shpeyerl.Ar disk Ar disktype
92965c81a8Shpeyerl.Oo Ar packid Oc
9379bd2ddbSdsl.\" disklabel -NW: disallow/allow writes to the label sector
94990562bfSwiz.Nm
9566db4d4bSjtc.Op Fl NW
96965c81a8Shpeyerl.Ar disk
9791af0d68Sjmmv.\" disklabel -l: list all know file system types
9891af0d68Sjmmv.Nm
9991af0d68Sjmmv.Fl l
10066db4d4bSjtc.Sh DESCRIPTION
10195b3ccaaSlukem.Nm
10282924459Swizcan be used to install, examine, or modify the label on a disk drive or pack.
10379bd2ddbSdslWhen writing the label, it can be used to change the drive identification,
10479bd2ddbSdslthe disk partitions on the drive, or to replace a damaged label.
10501a274e0Sfair.Pp
106534f9a7aSgmcgarryThe
107*400b2bc1Swiz.Fl e , i , l , N , R , W ,
10879bd2ddbSdsland
109*400b2bc1Swiz.Fl w
11091af0d68Sjmmvoptions determine the basic operation.
11191af0d68SjmmvIf none are specified the label
11279bd2ddbSdslis displayed.
11379bd2ddbSdsl.Bl -tag -width flag
11479bd2ddbSdsl.It Fl e
11582924459SwizEdit the existing label (using
11682924459Swiz.Ev EDITOR )
11782924459Swizand write it back to the disk.
11882924459SwizIf
11982924459Swiz.Ev EDITOR
12082924459Swizis undefined, then
12166db4d4bSjtc.Xr vi 1
12261f28255Scgdis used.
12379bd2ddbSdsl.It Fl i
12479bd2ddbSdslInteractively update the existing label and write it back to the disk.
12591af0d68Sjmmv.It Fl l
12691af0d68SjmmvShow all known file system types (those that can be specified along a
12791af0d68Sjmmvpartition within the label) and exit.
128*400b2bc1Swiz.It Fl N
129*400b2bc1SwizDisallow writes to the disk sector that contains the label.
130*400b2bc1SwizThis is the default state.
13179bd2ddbSdsl.It Fl R
13279bd2ddbSdslWrite (restore) a label by reading it from
13379bd2ddbSdsl.Ar protofile .
13479bd2ddbSdslThe file should be in the same format as the default output.
135*400b2bc1Swiz.It Fl W
136*400b2bc1SwizAllow writes to the disk sector that contains the label.
137*400b2bc1SwizThis state may not persist if no programs have the disk open.
13879bd2ddbSdsl.It Fl w
13979bd2ddbSdslWrite a standard label for the specified
14079bd2ddbSdsl.Ar disktype .
14179bd2ddbSdslSee
14279bd2ddbSdsl.Xr disktab 5 .
14379bd2ddbSdsl.El
14472fbacb3Schristos.Pp
14579bd2ddbSdslThe majority of the rest of the options affect more than one form of the
14679bd2ddbSdslcommand:
14779bd2ddbSdsl.Bl -tag -width flag
14879bd2ddbSdsl.It Fl A
14979bd2ddbSdslRead all labels from the disk, including ones deleted with
150458252ceSpk.Nm
15179bd2ddbSdsl.Fl D .
15279bd2ddbSdslImplies
15379bd2ddbSdsl.Fl r .
154874b0026Schristos.It Fl B Ar endian
155874b0026SchristosSpecify the byteorder of the label to be written.
156874b0026SchristosIt should be:
157874b0026Schristos.Dq be
158874b0026Schristosor
159874b0026Schristos.Dq le .
16079bd2ddbSdsl.It Fl C
16182924459SwizOutput the partition offset and size values in
16282924459Swiz.Aq cylinder/head/sector
16382924459Swizformat.
16482924459SwizNote this format is always accepted on input with either the
16596088218Swiz.Fl e
16696088218Swizor
16796088218Swiz.Fl R
16882924459Swizflags.
16979bd2ddbSdsl.It Fl D
170a3b62134SperryDelete all existing labels (by 1's complementing the magic number) before
17179bd2ddbSdslwriting any labels to their default location.
17279bd2ddbSdslImplies
17379bd2ddbSdsl.Fl r .
17479bd2ddbSdslIf
17579bd2ddbSdsl.Fl D
17679bd2ddbSdslis specified without a request to write the label, then existing labels are
17779bd2ddbSdsljust deleted.
17879bd2ddbSdsl.It Fl F
17979bd2ddbSdslTreat
18079bd2ddbSdsl.Ar disk
18179bd2ddbSdslas a regular file.
18282924459SwizThis suppresses all
18382924459Swiz.Xr ioctl 2
18482924459Swizcalls, and is the default if
18579bd2ddbSdsl.Ar disk
18679bd2ddbSdslis a regular file.
18779bd2ddbSdsl.Ar disk
18879bd2ddbSdslis always opened using
18982924459Swiz.Xr opendisk 3
19079bd2ddbSdsleven if
19179bd2ddbSdsl.Fl F
19279bd2ddbSdslis specified.
19379bd2ddbSdslImplies
19479bd2ddbSdsl.Fl r .
195*400b2bc1Swiz.It Fl f Ar disktab
196*400b2bc1SwizSpecify the name of a file to use instead of
197*400b2bc1Swiz.Pa /etc/disktab .
19879bd2ddbSdsl.It Fl I
19979bd2ddbSdslIf a label cannot be read from
20079bd2ddbSdsl.Ar disk
20179bd2ddbSdslrequest the default one from the kernel.
20279bd2ddbSdslImplies
20379bd2ddbSdsl.Fl r .
204*400b2bc1Swiz.It Fl L Ar sector
205*400b2bc1SwizSpecify the relative sector number of the disklabel
206*400b2bc1Swizsimilar to the environment variable
207*400b2bc1Swiz.Ev DISKLABELSECTOR .
208874b0026Schristos.It Fl M Ar machine
209874b0026SchristosSpecify the machine to generate a label for.
210874b0026SchristosDefaults to the current machine it is compiled for.
2111b979fccSmlelstvSpecific details can be overridden via environment
2121b979fccSmlelstvand with the options
213*400b2bc1Swiz.Fl B , L , m , n , O ,
2141b979fccSmlelstvand
215*400b2bc1Swiz.Fl P .
216874b0026Schristos.It Fl m
217*400b2bc1SwizExpect the label to have an MBR.
2181b979fccSmlelstv.It Fl n
219*400b2bc1SwizExpect the label not to have an MBR.
220*400b2bc1Swiz.It Fl O Ar offset
221*400b2bc1SwizSpecify the relative byte offset of the disklabel
222*400b2bc1Swizsimilar to the environment variable
223*400b2bc1Swiz.Ev DISKLABELOFFSET .
224*400b2bc1Swiz.It Fl P Ar size
225*400b2bc1SwizSpecify the size of the partition table.
22679bd2ddbSdsl.It Fl r
22782924459SwizRead/write the disk directly rather than using
22882924459Swiz.Xr ioctl 2
22982924459Swizrequests on the kernel.
23079bd2ddbSdslWhen writing a label, the kernel will be told about the label before the
23179bd2ddbSdsllabel is written and asked to write afterwards.
232a11e4d8dSsevanThis is the historic behaviour and can be suppressed by specifying
23379bd2ddbSdsl.Fl F .
23479bd2ddbSdsl.It Fl t
23579bd2ddbSdslFormat the output as a
23679bd2ddbSdsl.Xr disktab 5
23779bd2ddbSdslentry.
23879bd2ddbSdsl.It Fl v
23979bd2ddbSdslBe verbose about the operations being done, in particular the disk sectors
24079bd2ddbSdslbeing read and written.
24179bd2ddbSdslSpecifying
24279bd2ddbSdsl.Fl v
24379bd2ddbSdslmore than once will increase the verbosity.
24479bd2ddbSdsl.El
24566db4d4bSjtc.Pp
24682924459SwizOn systems that expect to have disks with MBR partitions (see
24779bd2ddbSdsl.Xr fdisk 8 )
24895b3ccaaSlukem.Nm
24982924459Swizwill find, and update if requested, labels in the first 8k of type 169
25082924459Swiz.Pq Nx
25182924459SwizMBR labels and within the first 8k of the physical disk.
25279bd2ddbSdslOn other systems
25379bd2ddbSdsl.Nm
25479bd2ddbSdslwill only look at the start of the disk.
25582924459SwizThe offset at which the labels are written is also system dependent.
25666db4d4bSjtc.Pp
25795b3ccaaSlukem.Nm
25879bd2ddbSdslwill detect byteswapped labels, but currently cannot display them.
259fe6b4c31Sfvdl.Pp
260506fe182SdslPrevious versions of
261fe6b4c31Sfvdl.Nm
262506fe182Sdslcould update the bootstrap code on some architectures.
263506fe182SdslThis functionality has been subsumed by
264506fe182Sdsl.Xr installboot 8 .
265e74a53f0Swiz.Sh FILES
266e74a53f0Swiz.Bl -tag -width /etc/disktab -compact
267e74a53f0Swiz.It Pa /etc/disktab
268e74a53f0Swiz.El
2690e4b8938Ssnj.Sh EXIT STATUS
2700e4b8938SsnjThe exit status of
2710e4b8938Ssnj.Nm
2720e4b8938Ssnjis set to indicate any errors or warnings.
2730e4b8938SsnjThe values used are:
2740e4b8938Ssnj.Bl -tag -width indent
2750e4b8938Ssnj.It 0
2760e4b8938SsnjThe
2770e4b8938Ssnj.Nm
2780e4b8938Ssnjutility has completed successfully.
2790e4b8938Ssnj.It 1
28082924459SwizA fatal error has occurred, such as unknown options passed on the
28182924459Swizcommand line, or writing the disklabel failed.
2820e4b8938Ssnj.It 4
2830e4b8938SsnjAn I/O error of some sort occurred.
2840e4b8938Ssnj.It 101..n
285a11e4d8dSsevanOne or more warnings occurred while reading the disklabel.
2860e4b8938SsnjSubtract 100 to get the number of warnings detected.
2870e4b8938Ssnj.El
288965c81a8Shpeyerl.Sh EXAMPLES
28982924459Swiz.Dl Ic disklabel sd0
290965c81a8Shpeyerl.Pp
291965c81a8ShpeyerlDisplay the in-core label for sd0 as obtained via
292965c81a8Shpeyerl.Pa /dev/rsd0c .
293965c81a8Shpeyerl.Pp
294e115d851Sabs.Dl Ic disklabel -i -r sd0
295e115d851Sabs.Pp
296e115d851SabsRead the on-disk label for sd0, edit it using the built-in interactive editor and reinstall in-core as well
297e115d851Sabsas on-disk.
298e115d851Sabs.Pp
299e115d851Sabs.Dl Ic disklabel -i -I sd0
300e115d851Sabs.Pp
301a11e4d8dSsevanAs previous, but do not fail if there was no label on the disk yet;
302e115d851Sabsprovide some default values instead.
303e115d851Sabs.Pp
304e115d851Sabs.Dl Ic disklabel -e -I sd0
305e115d851Sabs.Pp
306e115d851SabsAs previous, only edit using $EDITOR
307e115d851Sabs.Pp
30882924459Swiz.Dl Ic disklabel -w -r /dev/rsd0c sd2212 foo
309965c81a8Shpeyerl.Pp
310bd9e498eSwizCreate a label for sd0 based on information for
311bd9e498eSwiz.Dq sd2212
312bd9e498eSwizfound in
31394caee8dShpeyerl.Pa /etc/disktab ,
31494caee8dShpeyerlusing
31594caee8dShpeyerl.Pa foo
31694caee8dShpeyerlas the disk pack label.
317bd9e498eSwizIf you do not have an entry for your disk in
31894caee8dShpeyerl.Pa /etc/disktab ,
31994caee8dShpeyerlyou can use this style to put
320bd9e498eSwizan initial label onto a new disk.
321bd9e498eSwizThen dump the label to a file (using
32201869ca4Swiz.Ic disklabel sd0 > protofile ) ,
32394caee8dShpeyerlediting the file, and replacing the label with
32482924459Swiz.Ic disklabel -R sd0 protofile .
325965c81a8Shpeyerl.Pp
32682924459Swiz.Dl Ic disklabel -R sd0 mylabel
327965c81a8Shpeyerl.Pp
328965c81a8ShpeyerlRestore the on-disk and in-core label for sd0 from information in
329965c81a8Shpeyerl.Pa mylabel .
33066db4d4bSjtc.Sh DIAGNOSTICS
33161f28255ScgdThe kernel device drivers will not allow the size of a disk partition
33261f28255Scgdto be decreased or the offset of a partition to be changed while it is open.
33361f28255ScgdSome device drivers create a label containing only a single large partition
334bd9e498eSwizif a disk is unlabeled; thus, the label must be written to the
335bd9e498eSwiz.Dq a
33661f28255Scgdpartition of the disk while it is open.
33761f28255ScgdThis sometimes requires the desired label to be set in two steps,
33861f28255Scgdthe first one creating at least one other partition,
33961f28255Scgdand the second setting the label on the new partition
340bd9e498eSwizwhile shrinking the
341bd9e498eSwiz.Dq a
342bd9e498eSwizpartition.
34396088218Swiz.Sh SEE ALSO
34479bd2ddbSdsl.Xr opendisk 3 ,
34596088218Swiz.Xr disklabel 5 ,
34696088218Swiz.Xr disktab 5 ,
347a21d1e7aSlukem.Xr dkctl 8 ,
34896088218Swiz.Xr fdisk 8 ,
349e0f66530Schristos.Xr gpt 8 ,
35096088218Swiz.Xr installboot 8 ,
351f05120b3Swiz.Xr mbrlabel 8 ,
352f05120b3Swiz.Xr mscdlabel 8
353a11e4d8dSsevan.Sh HISTORY
354a11e4d8dSsevanThe
355a11e4d8dSsevan.Nm
356a11e4d8dSsevanutility appeared in
357a11e4d8dSsevan.Bx 4.3 Tahoe .
35866db4d4bSjtc.Sh BUGS
359e0f66530SchristosThe
360e0f66530Schristos.Nm
361e0f66530Schristosstructure stored on disk cannot support partitions/disks greater than 2TB.
362e0f66530SchristosPlease use
363e74a53f0Swiz.Xr gpt 8
364e0f66530Schristosand
365e0f66530Schristos.Xr dkctl 8
366e0f66530Schristosto manage partitions and disks larger than 2TB.
367e0f66530Schristos.Pp
368a1ba72f3SchristosIf the disk partition is not specified in the disk name
369bd9e498eSwiz(i.e.,
37082924459Swiz.Ar xy0
371bd9e498eSwizinstead of
37282924459Swiz.Ar /dev/rxy0c ) ,
37395b3ccaaSlukem.Nm
374bd9e498eSwizwill construct the full pathname of the disk and use the
375bd9e498eSwiz.Dq d
376bd9e498eSwizpartition on i386, hpcmips, or arc, and the
377bd9e498eSwiz.Dq c
378bd9e498eSwizpartition on all others.
379d5adc82dSfair.Pp
380bd9e498eSwizOn the sparc, sparc64, sun2, and sun3
381d5adc82dSfair.Nx
382d5adc82dSfairsystems, the size of each partition must be a multiple of the number
383bd9e498eSwizof sectors per cylinder (i.e., each partition must be an integer
384d5adc82dSfairnumber of cylinders), or the boot ROMs will declare the label
385d5adc82dSfairinvalid and fail to boot the system.
386b58a4f15Sfair.Pp
387b58a4f15SfairIn addition, the
388b58a4f15Sfair.Fl r
38982924459Swizoption should never be used on a sparc, sparc64, sun2, or sun3 system
39046d320c7Sfredetteboot disk - the
391b58a4f15Sfair.Nx
392b58a4f15Sfairkernel translates the
393b58a4f15Sfair.Nx
394b58a4f15Sfairdisk label into a SunOS compatible format (which is required by the
395bd9e498eSwizboot PROMs) when it writes the label.
396bd9e498eSwizUsing the
397b58a4f15Sfair.Fl r
398bd9e498eSwizflag causes
399b58a4f15Sfair.Nm
400b58a4f15Sfairto write directly to disk, and bypass the format translation.
401b58a4f15SfairThis will result in a disk label that the PROMs will not recognize,
402b58a4f15Sfairand that therefore cannot be booted from.
4031b979fccSmlelstv.Pp
4041b979fccSmlelstvThe
4051b979fccSmlelstv.Fl m
4061b979fccSmlelstvflag previously toggled between using an MBR and not using an MBR,
4071b979fccSmlelstvwith the default being implied by the machine type.
4081b979fccSmlelstvIt now always enables MBR mode, independent of the machine default.
4091b979fccSmlelstvUse the
4101b979fccSmlelstv.Fl n
4111b979fccSmlelstvflag to disable MBR mode.
412