Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
.\"	$NetBSD: disklabel.8,v 1.70 2019/07/02 16:47:19 wiz 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 July 2, 2019
.Dt DISKLABEL 8
.Os
.Sh NAME
.Nm disklabel
.Nd read and write disk pack label
.Sh SYNOPSIS
.\" disklabel: read label
.Nm
.Op Fl ACDFmnrtv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Ar disk
.\" disklabel -e: read/modify/write using $EDITOR
.Nm
.Fl e
.Op Fl CDFImnrv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Ar disk
.\" disklabel -i: read/modify/write using builtin commands
.Nm
.Fl i
.Op Fl DFImnrv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Ar disk
.\" disklabel -R: write from edited output
.Nm
.Fl R
.Op Fl DFmnrv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Ar disk Ar protofile
.\" disklabel -w: write from disctab entry
.Nm
.Fl w
.Op Fl DFmnrv
.Op Fl B Ar endian
.Op Fl L Ar sector
.Op Fl M Ar machine
.Op Fl O Ar offset
.Op Fl P Ar size
.Op Fl f Ar disktab
.Ar disk Ar disktype
.Oo Ar packid Oc
.\" disklabel -NW: disallow/allow writes to the label sector
.Nm
.Op Fl NW
.Ar disk
.\" disklabel -l: list all know file system types
.Nm
.Fl l
.Sh DESCRIPTION
.Nm
can be used to install, examine, or modify the label on a disk drive or pack.
When writing the label, it can be used to change the drive identification,
the disk partitions on the drive, or to replace a damaged label.
.Pp
The
.Fl e , i , l , N , R , W ,
and
.Fl w
options determine the basic operation.
If none are specified the label
is displayed.
.Bl -tag -width flag
.It Fl e
Edit the existing label (using
.Ev EDITOR )
and write it back to the disk.
If
.Ev EDITOR
is undefined, then
.Xr vi 1
is used.
.It Fl i
Interactively update the existing label and write it back to the disk.
.It Fl l
Show all known file system types (those that can be specified along a
partition within the label) and exit.
.It Fl N
Disallow writes to the disk sector that contains the label.
This is the default state.
.It Fl R
Write (restore) a label by reading it from
.Ar protofile .
The file should be in the same format as the default output.
.It Fl W
Allow writes to the disk sector that contains the label.
This state may not persist if no programs have the disk open.
.It Fl w
Write a standard label for the specified
.Ar disktype .
See
.Xr disktab 5 .
.El
.Pp
The majority of the rest of the options affect more than one form of the
command:
.Bl -tag -width flag
.It Fl A
Read all labels from the disk, including ones deleted with
.Nm
.Fl D .
Implies
.Fl r .
.It Fl B Ar endian
Specify the byteorder of the label to be written.
It should be:
.Dq be
or
.Dq le .
.It Fl C
Output the partition offset and size values in
.Aq cylinder/head/sector
format.
Note this format is always accepted on input with either the
.Fl e
or
.Fl R
flags.
.It Fl D
Delete all existing labels (by 1's complementing the magic number) before
writing any labels to their default location.
Implies
.Fl r .
If
.Fl D
is specified without a request to write the label, then existing labels are
just deleted.
.It Fl F
Treat
.Ar disk
as a regular file.
This suppresses all
.Xr ioctl 2
calls, and is the default if
.Ar disk
is a regular file.
.Ar disk
is always opened using
.Xr opendisk 3
even if
.Fl F
is specified.
Implies
.Fl r .
.It Fl f Ar disktab
Specify the name of a file to use instead of
.Pa /etc/disktab .
.It Fl I
If a label cannot be read from
.Ar disk
request the default one from the kernel.
Implies
.Fl r .
.It Fl L Ar sector
Specify the relative sector number of the disklabel
similar to the environment variable
.Ev DISKLABELSECTOR .
.It Fl M Ar machine
Specify the machine to generate a label for.
Defaults to the current machine it is compiled for.
Specific details can be overridden via environment
and with the options
.Fl B , L , m , n , O ,
and
.Fl P .
.It Fl m
Expect the label to have an MBR.
.It Fl n
Expect the label not to have an MBR.
.It Fl O Ar offset
Specify the relative byte offset of the disklabel
similar to the environment variable
.Ev DISKLABELOFFSET .
.It Fl P Ar size
Specify the size of the partition table.
.It Fl r
Read/write the disk directly rather than using
.Xr ioctl 2
requests on the kernel.
When writing a label, the kernel will be told about the label before the
label is written and asked to write afterwards.
This is the historic behaviour and can be suppressed by specifying
.Fl F .
.It Fl t
Format the output as a
.Xr disktab 5
entry.
.It Fl v
Be verbose about the operations being done, in particular the disk sectors
being read and written.
Specifying
.Fl v
more than once will increase the verbosity.
.El
.Pp
On systems that expect to have disks with MBR partitions (see
.Xr fdisk 8 )
.Nm
will find, and update if requested, labels in the first 8k of type 169
.Pq Nx
MBR labels and within the first 8k of the physical disk.
On other systems
.Nm
will only look at the start of the disk.
The offset at which the labels are written is also system dependent.
.Pp
.Nm
will detect byteswapped labels, but currently cannot display them.
.Pp
Previous versions of
.Nm
could update the bootstrap code on some architectures.
This functionality has been subsumed by
.Xr installboot 8 .
.Sh FILES
.Bl -tag -width /etc/disktab -compact
.It Pa /etc/disktab
.El
.Sh EXIT STATUS
The exit status of
.Nm
is set to indicate any errors or warnings.
The values used are:
.Bl -tag -width indent
.It 0
The
.Nm
utility has completed successfully.
.It 1
A fatal error has occurred, such as unknown options passed on the
command line, or writing the disklabel failed.
.It 4
An I/O error of some sort occurred.
.It 101..n
One or more warnings occurred while reading the disklabel.
Subtract 100 to get the number of warnings detected.
.El
.Sh EXAMPLES
.Dl Ic disklabel sd0
.Pp
Display the in-core label for sd0 as obtained via
.Pa /dev/rsd0c .
.Pp
.Dl Ic disklabel -i -r sd0
.Pp
Read the on-disk label for sd0, edit it using the built-in interactive editor and reinstall in-core as well
as on-disk.
.Pp
.Dl Ic disklabel -i -I sd0
.Pp
As previous, but do not fail if there was no label on the disk yet;
provide some default values instead.
.Pp
.Dl Ic disklabel -e -I sd0
.Pp
As previous, only edit using $EDITOR
.Pp
.Dl Ic disklabel -w -r /dev/rsd0c sd2212 foo
.Pp
Create a label for sd0 based on information for
.Dq sd2212
found in
.Pa /etc/disktab ,
using
.Pa foo
as the disk pack label.
If you do not have an entry for your disk in
.Pa /etc/disktab ,
you can use this style to put
an initial label onto a new disk.
Then dump the label to a file (using
.Ic disklabel sd0 > protofile ) ,
editing the file, and replacing the label with
.Ic disklabel -R sd0 protofile .
.Pp
.Dl Ic disklabel -R sd0 mylabel
.Pp
Restore the on-disk and in-core label for sd0 from information in
.Pa mylabel .
.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
.Dq 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
.Dq a
partition.
.Sh SEE ALSO
.Xr opendisk 3 ,
.Xr disklabel 5 ,
.Xr disktab 5 ,
.Xr dkctl 8 ,
.Xr fdisk 8 ,
.Xr gpt 8 ,
.Xr installboot 8 ,
.Xr mbrlabel 8 ,
.Xr mscdlabel 8
.Sh HISTORY
The
.Nm
utility appeared in
.Bx 4.3 Tahoe .
.Sh BUGS
The
.Nm
structure stored on disk cannot support partitions/disks greater than 2TB.
Please use
.Xr gpt 8
and
.Xr dkctl 8
to manage partitions and disks larger than 2TB.
.Pp
If the disk partition is not specified in the disk name
(i.e.,
.Ar xy0
instead of
.Ar /dev/rxy0c ) ,
.Nm
will construct the full pathname of the disk and use the
.Dq d
partition on i386, hpcmips, or arc, and the
.Dq c
partition on all others.
.Pp
On the sparc, sparc64, sun2, and sun3
.Nx
systems, the size of each partition must be a multiple of the number
of sectors per cylinder (i.e., each partition must be an integer
number of cylinders), or the boot ROMs will declare the label
invalid and fail to boot the system.
.Pp
In addition, the
.Fl r
option should never be used on a sparc, sparc64, sun2, or sun3 system
boot disk - the
.Nx
kernel translates the
.Nx
disk label into a SunOS compatible format (which is required by the
boot PROMs) when it writes the label.
Using the
.Fl r
flag causes
.Nm
to write directly to disk, and bypass the format translation.
This will result in a disk label that the PROMs will not recognize,
and that therefore cannot be booted from.
.Pp
The
.Fl m
flag previously toggled between using an MBR and not using an MBR,
with the default being implied by the machine type.
It now always enables MBR mode, independent of the machine default.
Use the
.Fl n
flag to disable MBR mode.