xref: /openbsd/sbin/disklabel/disklabel.8 (revision 72c7c57a)
1.\"	$OpenBSD: disklabel.8,v 1.157 2024/03/22 21:49:52 jan 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: March 22 2024 $
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.Op Fl T Ar file
47.Ar disk
48.Nm disklabel
49.Fl w
50.Op Fl Acdnv
51.Op Fl T Ar file
52.Ar disk disktype
53.Op Ar packid
54.Nm disklabel
55.Fl e
56.Op Fl Acdnv
57.Op Fl T Ar file
58.Ar disk
59.Nm disklabel
60.Fl E
61.Op Fl Acdnv
62.Op Fl F Ns | Ns Fl f Ar file
63.Op Fl T Ar file
64.Ar disk
65.Nm disklabel
66.Fl R
67.Op Fl nv
68.Op Fl F Ns | Ns Fl f Ar file
69.Ar disk protofile
70.Sh DESCRIPTION
71The
72.Nm
73utility can be used to install, examine, or modify the label on a disk drive or
74pack.
75The disk label contains information about disk characteristics
76.Pq size, type, etc.
77and the partition layout, stored on the disk itself.
78It is used by the operating system to optimize disk I/O and
79locate the filesystems resident on the disk.
80.Pp
81.Nm
82supports 15 configurable partitions,
83.Sq a
84through
85.Sq p ,
86excluding
87.Sq c .
88The
89.Sq c
90partition describes the entire physical disk, is automatically created
91by the kernel, and cannot be modified or deleted by
92.Nm .
93By convention, the
94.Sq a
95partition of the boot disk is the root partition, and the
96.Sq b
97partition of the boot disk is the swap partition,
98but all other letters can be used in any order for any other
99partitions as desired.
100.Pp
101The options are as follows:
102.Bl -tag -width Ds
103.It Fl A
104Automatically allocate all the disk space in the
105.Ox
106portion of the disk in the recommended manner.
107See
108.Sx AUTOMATIC DISK ALLOCATION ,
109below.
110.It Fl c
111Clear the system's in-core copy of the label and update it based on
112the on-disk label.
113.It Fl d
114Use the
115.Em default
116label.
117This ignores any existing
118.Ox
119disk label on the disk.
120.It Fl E
121Use the built-in command-driven label editor described below.
122.It Fl e
123Edit an existing disk label using the editor specified in the
124.Ev EDITOR
125environment variable, or
126.Xr vi 1
127if none is specified.
128.It Fl F Ar file
129Write entries to
130.Ar file
131in
132.Xr fstab 5
133format for any partitions for which mount point information is known.
134The entries will be written using disklabel UIDs.
135The
136.Fl F
137flag is only valid when used in conjunction with the
138.Fl E
139or
140.Fl R
141flags.
142If
143.Ar file
144already exists, it will be overwritten.
145.It Fl f Ar file
146The same as
147.Fl F
148except that entries will be written using disk device names.
149.It Fl h
150Print partition sizes in human readable format.
151.It Fl n
152Make no permanent changes to the disklabel
153.Pq useful for debugging purposes .
154.It Fl p Ar unit
155Print partition sizes in
156.Ar unit
157instead of sectors.
158Valid units are b(ytes), c(ylinders), k(ilobytes), m(egabytes), g(igabytes)
159and t(erabytes).
160.It Fl R
161Restore a disk label that was formatted in a prior operation and
162saved in an ASCII file.
163.It Fl T Ar file
164Read the template for automatic allocation from
165.Ar file
166instead of using the builtin one.
167See
168.Sx AUTOMATIC DISK ALLOCATION
169below for the format.
170If
171.Ar file
172is a single dash
173.Pq Sq - ,
174the template is read from the standard input.
175.It Fl t
176Format the label as a
177.Xr disktab 5
178entry.
179.It Fl v
180Print additional information during operation
181.Pq verbose mode .
182.It Fl w
183Write a standard label on the designated drive.
184.It Ar disk
185Specify the
186.Ar disk
187to operate on.
188It can be specified by its full pathname, by an abbreviated disk form,
189or by its disklabel UID.
190In its abbreviated form, the path to the device, the
191.Sq r
192denoting
193.Qq raw device ,
194and the partition letter, can all be omitted.
195For example, the first IDE disk can be specified as either
196.Pa /dev/rwd0c ,
197.Pa /dev/wd0c ,
198or
199.Ar wd0 .
200.It Ar disktype
201Specify a
202.Ar disktype
203entry from the
204.Xr disktab 5
205database.
206.It Ar packid
207Specify a pack identification string for the device
208.Pq see below .
209.It Ar protofile
210Used with the restore option
211.Pq Fl R
212to specify a file to read an ASCII label from.
213.El
214.Pp
215The first form of the command
216.Pq read
217is used to examine the label on the named disk drive.
218It will display all of the parameters associated with the drive
219and its partition layout.
220The kernel's in-core copy of the label is displayed; if
221the disk has no label, or the partition types on the disk are
222incorrect, the kernel may have constructed or modified the label.
223.Pp
224The second form of the command
225.Pq write
226is used to write a standard label on the designated drive.
227The drive parameters and partitions are taken from that file.
228If different disks of the same physical type are
229to have different partitions, it will be necessary to have separate
230disktab entries describing each, or to edit the label after
231installation as described below.
232The optional argument is a pack
233identification string, up to 16 characters long.
234The pack ID must be quoted if it contains blanks.
235The existing label will be updated via the in-core
236copy.
237.Pp
238In the third form of the command
239.Pq edit ,
240the label is read from the in-core kernel copy
241and then supplied to an editor for changes.
242If no editor is specified in an
243.Ev EDITOR
244environment variable,
245.Xr vi 1
246is used.
247When the editor terminates, the formatted label is reread and
248used to rewrite the disk label.
249.Pp
250The built-in label editor
251.Pq fourth form
252provides a simple interactive label editor.
253The editor prompt contains information about the state of the edit
254process.
255.Pp
256.Dl Ar disk Ns *>
257.Pp
258Where
259.Ar disk
260is the name of the disk being edited,
261.Sq *
262means that the in-memory copy of the partition table has been modified but
263not yet written to disk.
264.Pp
265Some commands or prompts take an optional unit.
266Available units are
267.Sq b
268for bytes,
269.Sq c
270for cylinders,
271.Sq k
272for kilobytes,
273.Sq m
274for megabytes,
275.Sq g
276for gigabytes,
277and
278.Sq t
279for terabytes.
280If no unit is given, the default is to use sectors
281(usually 512 bytes).
282.Pp
283Quantities are rounded to the nearest
284cylinder when units are specified for sizes
285.Pq or offsets .
286At prompts that request a size,
287.Ql *
288may be entered to indicate the rest of the available space,
289.Sq %
290for percentage of total, and
291.Sq &
292for percentage free.
293Commands may be aborted by entering
294.Ql ^D
295.Pq Control-D .
296Entering
297.Ql ^D
298at the main prompt will exit the editor.
299.Pp
300The editor commands are as follows:
301.Bl -tag -width "p [unit] "
302.It Cm \&? | h
303Display help message with all available commands.
304There is also
305.Pq simple
306context-sensitive help available at most prompts.
307.It Cm A
308Allocate all the disk space in the recommended manner.
309See
310.Sx AUTOMATIC DISK ALLOCATION ,
311below.
312.It Cm a Op Ar part
313Add new partition.
314This option adds a new partition to the disk label.
315If no partition letter is specified
316.Pq a\-p ,
317the user will be prompted for one.
318.It Cm b
319Set
320.Ox
321disk boundaries.
322This option tells
323.Nm
324which parts of the disk it is allowed to modify.
325This option is probably only useful for ports with
326.Xr fdisk 8
327partition tables where the ending sector in the MBR is incorrect.
328The user may enter
329.Ql *
330at the
331.Dq Size
332prompt to indicate the entire size of the disk
333.Pq minus the starting sector .
334This is useful for disks where the
335fdisk partition table is incapable of storing the real size.
336Note: data may become corrupted if boundaries are extended such
337that they overlap with other resident operating systems.
338.It Cm c Op Ar part
339Change the size of an existing partition.
340If no partition is specified, the user will be prompted for one.
341The new size may be
342in terms of the aforementioned units and may also be prefixed with
343.Ql +
344or
345.Ql -
346to change the size by a relative amount.
347.It Cm D
348Sets the disk label to the default values as reported by the kernel.
349This simulates the case where there is no disk label.
350.It Cm d Op Ar part
351Delete an existing partition (or
352.Ql *
353to delete all partitions).
354If no partition is specified, the user will be prompted for one.
355.It Cm e
356Edit label description, e.g. 'UMIS RPJTJ256MED'.
357.It Cm i
358Change the disklabel UID, specified as a 16-character hexadecimal string.
359If set to all zeros, a new UID will automatically be allocated when the
360disklabel is written to disk.
361.It Cm l Op Ar unit
362Print the disk label header.
363.It Cm M
364Display this manual page.
365The manual page is piped through the pager specified by the
366.Ev PAGER
367environment variable or 'less' if
368.Ev PAGER
369is not set.
370.It Cm m Op Ar part
371Modify parameters for an existing partition.
372If no partition is specified, the user will be prompted for one.
373This option allows
374the user to change the filesystem type, starting offset, partition size,
375and mount point for the specified partition.
376.It Cm n Op Ar part
377Name the mount point for an existing partition.
378If no partition is specified, the user will be prompted for one.
379This option is only valid if
380.Nm
381was invoked with the
382.Fl f
383flag.
384.It Cm p Op Ar unit
385Print the current partition list.
386If a
387.Em unit
388is given, the size and offsets are displayed in terms of the
389specified unit.
390If the unit is
391.Sq * ,
392it is automatically determined by the size of the smallest
393partition.
394.It Cm q
395Quit the editor.
396If any changes have been made, the user will be
397asked whether or not to save the changes to the on-disk label.
398.It Cm R Op Ar part
399Resize a partition in an automatically allocated label,
400compacting unused space between partitions with a higher offset.
401The last partition will be shrunk if necessary.
402Works only for automatically allocated labels with no spoofed partitions.
403.It Cm r
404Recalculate free space.
405This command displays all the free areas on the disk and the total
406number of free sectors.
407.It Cm s Op Ar path
408Save the label to a file in ASCII format (suitable for loading via the
409.Fl R
410option).
411If no path is specified, the user will be prompted for one.
412.It Cm U
413Undo all changes made since entering the editor.
414.It Cm u
415Undo
416.Pq or redo
417last change.
418Entering
419.Em u
420once will undo the last change.
421Entering it again will restore the change.
422.It Cm w
423Write the label to disk.
424This option will commit any changes to the on-disk label.
425.It Cm x
426Exit the editor without saving any changes to the on-disk label.
427.It Cm z
428Zero out the existing partition table and mount point information,
429leaving only the 'c' partition.
430The drive parameters are not changed.
431.El
432.Pp
433In the restore form of the command
434.Pq fifth form ,
435the prototype file used to create the label should be in the same format
436as that produced when reading or editing a label.
437Comments are delimited by
438.Ar #
439and newline.
440.Pp
441Note that when a disk has no real
442.Bx
443disklabel, the kernel creates a
444default label so that the disk can be used.
445This default label will include other partitions found on the disk if
446they are supported on your architecture.
447For example, on systems that support
448.Xr fdisk 8
449partitions the default label will also include DOS and Linux partitions.
450However, these entries are not dynamic, they are fixed at the time
451.Nm
452is run.
453That means that subsequent changes that affect
454.Pf non- Ox
455partitions will not be present in the default label,
456though they may be updated by hand.
457To see the default label, run
458.Nm
459with the
460.Fl d
461flag.
462.Nm
463can then be run with the
464.Fl e
465flag and any entries pasted as desired from the default label into the real one.
466.Sh AUTOMATIC DISK ALLOCATION
467The
468.Fl A
469option and the editor command
470.Cm A
471create disklabels that distribute a disk's free space into a set of
472partitions appropriate for an
473.Ox
474installation.
475The exact set of partitions created depends on available free space,
476how fragmented the free space is
477and some machine dependent variables, but will be approximately:
478.Bl -column "/usr/X11R6" \
479"999MB \(en 999MB" "999MB \(en 999MB" "999MB \(en 999MB" \
480"< 700MB"
481.It \
482Ta Sy > 10GB Free Ta Sy > 2.5GB Ta Sy > 700MB Ta \
483Sy < 700MB
484.It Sy / \
485Ta 150MB \(en \0\01GB Ta 800MB \(en \0\02GB Ta 700MB \(en \0\04GB Ta \
4861MB \(en 2GB
487.It Sy swap \
488Ta \080MB \(en 256MB Ta \080MB \(en 256MB Ta \0\01MB \(en 256MB Ta
489.It Sy /usr \
490Ta 1.5GB \(en \030GB Ta 1.5GB \(en \030GB Ta Ta
491.It Sy /home \
492Ta \0\01GB \(en 300GB Ta 256MB \(en \0\02GB Ta Ta
493.It Sy /tmp \
494Ta 120MB \(en \0\04GB Ta Ta Ta
495.It Sy /var \
496Ta \080MB \(en \0\04GB Ta Ta Ta
497.It Sy /usr/X11R6 \
498Ta 384MB \(en \0\01GB Ta Ta Ta
499.It Sy /usr/local \
500Ta \0\01GB \(en \020GB Ta Ta Ta
501.It Sy /usr/src \
502Ta \0\02GB \(en \0\05GB Ta Ta Ta
503.It Sy /usr/obj \
504Ta \0\05GB \(en \0\06GB Ta Ta Ta
505.El
506.Pp
507The
508.Fl A
509option displays the partition set that would be created and
510.Fl wA
511writes it to disk.
512.Pp
513The default set can be overridden with
514.Fl T .
515Each line of input uses three fields to describe a partition.
516There must not be whitespace before the first field,
517fields are separated by whitespace and fields cannot contain whitespace.
518.Pp
519The first field is the partition's mount point or one of the
520special tokens
521.Sq RAID
522or
523.Sq SWAP .
524.Pp
525The second field is the partition size.
526This can be
527.Sq *
528to make the partition as large as possible,
529an exact size (e.g. 1G) or a size range
530(e.g. 1M-10G or 1G-*).
531.Pp
532The third field is the partition's share of any space left after all
533minimum sizes are accounted for.
534This is expressed as a percentage from 0 (the default) to 100
535(e.g. 37%).
536The last partition receives all remaining free space up to its
537maximum size no matter what percentage is specified.
538.Sh FILES
539.Bl -tag -width "/etc/disktabXXX"
540.It Pa /etc/disktab
541Disk description file.
542.El
543.Sh EXAMPLES
544Display, respectively, the current label, the default label and the
545default auto allocation for sd0:
546.Bd -literal -offset indent
547# disklabel sd0
548# disklabel -d sd0
549# disklabel -A sd0
550.Ed
551.Pp
552Write the default auto allocation to sd0:
553.Pp
554.Dl # disklabel -wA sd0
555.Pp
556Edit the label for the disk with DUID 3eb7f9da875cb9ee:
557.Pp
558.Dl # disklabel -E 3eb7f9da875cb9ee
559.Pp
560Restore the label for sd0 from information in
561.Pa mylabel :
562.Pp
563.Dl # disklabel -R sd0 mylabel
564.Pp
565Put largest contiguous area of free space on sd0 into a single RAID partition:
566.Dl # echo 'RAID *' | disklabel -wAT- sd0
567.Pp
568Write the auto allocation defined in
569.Pa /template
570to sd0:
571.Pp
572.Dl # disklabel -wAT/template sd0
573.Pp
574A template file that results in an auto allocation similar to the
575default one for a disk with 5GB of free space is:
576.Bl -column /home 1300MM256M 75% -offset indent
577.It / Ta \0800M\(en2G Ta \05%
578.It swap Ta \0\080M\(en256M Ta 10%
579.It /usr Ta 1300M\(en\)3G Ta 75%
580.It /home Ta \0256M\(en2G Ta 10%
581.El
582.Sh DIAGNOSTICS
583The kernel device drivers will not allow the size of a disk partition
584to be decreased or the offset of a partition to be changed while
585it is open.
586Some device drivers create a label containing only a
587single large partition if a disk is unlabeled; thus, the label must
588be written to the
589.Sq a
590partition of the disk while it is open.
591This sometimes requires the desired label to be set in two steps,
592the first one creating at least one other partition, and the second
593setting the label on the new partition while shrinking the
594.Sq a
595partition.
596.Sh SEE ALSO
597.Xr softraid 4 ,
598.Xr disklabel 5 ,
599.Xr disktab 5 ,
600.Xr installboot 8 ,
601.Xr scan_ffs 8
602.Sh HISTORY
603The
604.Nm
605utility appeared in
606.Bx 4.3 Tahoe .
607.Sh CAVEATS
608The maximum disk and partition size is 64PB.
609.Pp
610On some machines, such as Sparc64, partition tables
611may not exhibit the full functionality described above.
612