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