NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Use of disklabel, MBR and GPT

A few additional points:

"disklabel" is a term used by all 3 of the major BSD variants
(FreeBSd, NetBSd, and OpenBSD), but
with significant differences.  As a result of those differences, some
of the statements made are not
necessarily accurate in all cases.  For example, a type of disklabel
can be written to an OpenBSD
GPT partition rather than to the disk [P]MBR.

Writing a NetBSD disklabel with the eponymous utility will trash the
primary GPT on a GPT-formatted
disk (which can be recovered with NetBSD `gpt recover`).

On GPT disks, only OpenBSD uses an actual physical disklabel structure
on disk; the others refer to
a data structure that is fabricated.  NetBSD doesn't appear to
recognize OpenBSD filesystems at
all, and FreeBSD reports OpenBSD's partition as having an "invalid
disklabel".  In addition to
disklabel differences, the BSDs use different variations of UFS/FFS,
so filesystems are largely

Incidentally, it would be nice if NetBSD's installer included man
pages or equivalent documentation
(FreeBSD's has man pages and OpenBSD's programs have commands to emit
while many systems have programs with similar names and related
functionality, the details are
significantly different, and flying blind is a recipe for disaster.

The systems can (with significant effort) be made to work on a
multiboot system.  For example,
here are a few views of one such system.  The first is an excerpt of
'dk' lines from NetBSD

[     3.556584] dk0 at wd0: "EFI system partition", 204800 blocks at
2048, type: msdos
[     3.583865] dk1 at wd0: "Microsoft reserved partition", 32768
blocks at 206848, type: <unknown>
[     3.613876] dk2 at wd0: "MS Windows 10", 399767552 blocks at
239616, type: ntfs
[     3.643883] dk3 at wd0: "FreeBSD swap", 32768000 blocks at
400007168, type: swap
[     3.673894] dk4 at wd0: "FreeBSD", 399767552 blocks at 432775168, type: ffs
[     3.703905] dk5 at wd0: "NetBSD", 399773696 blocks at 832542720, type: ffs
[     3.733915] dk6 at wd0: "NetBSD swap", 32768000 blocks at
1232316416, type: swap
[     3.763926] dk7 at wd0: "OpenBSD", 399769600 blocks at 1265084416,
type: <unknown>
[     3.793936] dk8 at wd0: "OpenBSD swap", 32768000 blocks at
1664854016, type: ext2fs
[     3.823947] dk9 at wd0: "pclinuxos", 399769600 blocks at
1697622016, type: ext2fs
[     3.853958] dk10 at wd0: "linux-swap", 32768000 blocks at
2097391616, type: <unknown>
[     3.883968] dk11 at wd0: "data", 1775804416 blocks at 2130159616, type: ntfs
[     3.913979] dk12 at wd0: "MS recovery", 1062912 blocks at
3905966080, type: <unknown>
[     5.998829] root on dk5 dumps on dk3

The quoted text is from the GPT partition names, and with the
exception of "OpenBSD swap"
describes their function.  Note that NetBSD fails to identify some
filesystem types correctly
(e.g. pclinuxos is XFS, and OpenBSD uses a variant of UFS/FFS).  There
also appears to be
a bug where NetBSD claims that it "dumps on" the FreeBSD swap
partition, but there's no
mention of dk3 in /etc/fstab (where dump is supposed to get its information).

The short version of NetBSD's gpt utility provides similar information:

       start        size  index  contents
           0           1         PMBR
           1           1         Pri GPT header
           2          32         Pri GPT table
          34        2014         Unused
        2048      204800      1  GPT part - EFI System
      206848       32768      2  GPT part - Windows reserved
      239616   399767552      3  GPT part - Windows basic data
   400007168    32768000      5  GPT part - FreeBSD swap
   432775168   399767552      6  GPT part - FreeBSD UFS/UFS2
   832542720   399773696      7  GPT part - NetBSD FFSv1/FFSv2
  1232316416    32768000      8  GPT part - NetBSD swap
  1265084416   399769600      9  GPT part - 824cc7a0-36a8-11e3-890a-952519ad3f61
  1664854016    32768000     10  GPT part - Linux data
  1697622016   399769600     11  GPT part - Linux data
  2097391616    32768000     12  GPT part - Linux swap
  2130159616  1775804416     13  GPT part - Windows basic data
  3905964032        2048         Unused
  3905966080     1062912     14  GPT part - de94bba4-06d1-4d40-a16a-bfd50179d6ac
  3907028992         143         Unused
  3907029135          32         Sec GPT table
  3907029167           1         Sec GPT header

Note thathe OpenBSD partition is unrecognized, although it has the
exact GUID for
OpenBSD (
Likewise for the MS
Windows recovery environment.  The longer version (`gpt show -a`) provides some
additional details.  Note that the dk numbering starts at zero,
whereas the gpt indices
are 1-based.  The gpt utility is quite useful; I know of only two
shortcomings beyond
the failure to recognize some partition types and filesystems: 1)
short of groping through
embedded strings, there's no version identification for the program,
and 2) there appears
to be no facility for reporting or setting some GPT partition
attributes (hidden, diag, etc.).
`gpt` is the most usable and stable part of the NetBSD installer;
other bits seem to fail
to recognize and/or handle GPT, and much of the documentation is
MBR-specific (w/o
saying so).   NetBSD's disklabel command produces output which is
indeed "fictitious":

# /dev/rwd0:
type: ESDI
disk: wd0
label: fictitious
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 16
sectors/cylinder: 1008
cylinders: 3876021
total sectors: 3907029168
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0

4 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a: 3907029168         0     4.2BSD      0     0     0  # (Cyl.      0
- 3876020)
 d: 3907029168         0     unused      0     0        # (Cyl.      0
- 3876020)
disklabel: boot block size 0
disklabel: super block size 0

(for one thing, this particular disk spins at 5400 RPM, not 3600;
NetBSD disklabel
also claims 3600 "rpm" for SSDs and flash drives).

If a GPT label name (up to 36 UTF-16LE characters per Wikipedia)
contains no whitespace
characters, NetBSD's /etc/fstab can use the label, as in

NAME=data       /media/dk11     ntfs-3g rw,noatime      0 0

FreeBSD's /etc/fstab allows URI-like hex-encoded escapes for whitespace
characters, so on FreeBSD, the following works:

/dev/gpt/FreeBSD        /               ufs     rw
                         1       1
/dev/gpt/FreeBSD%20swap        none       swap    sw       0       0
/dev/gpt/data         /media/ada0p12  ntfs-3g
rw,noatime,mountprog=/usr/local/bin/ntfs-3g     0       0

FreeBSD creates device files under /dev/gpt (for labels) and /dev/gptid (for
UUIDs) for some partitions (fixed drives, but apparently not removable/portable
media, even when booting from those).  FreeBSD has a `gpart` utility.

OpenBSD has its own peculiar fstab notation, so it uses:

0e60da33d75f54ca.b      none            swap    sw
0e60da33d75f54ca.a      /               ffs     rw,wxallowed    1 1
0e60da33d75f54ca.i      /boot/EFI       msdos   rw,noatime      0 0

and mounting an NTFS partition read/write on OpenBSD doesn't work using
fstab (it winds up being read-only, and getting R/W NTFS mounts
requires some trickery to handle automatically at boot time).  OpenBSD has its
own variants of  `fdisk` and `disklabel` (both with built-in manual pages).

PCLinuxOS fstab is flexible; it can use UUIDs or (non-whitespace) labels, as in:

UUID=5e6c896b-1e1d-437d-8ea9-12590c54c259 / xfs defaults 1 1
UUID=7EEC-CDA9 /boot/EFI vfat defaults 0 0
LABEL=data /media/data ntfs-3g defaults,nofail 0 0

So GPT works reasonably well across various OSes, to the extent that
each OS supports (and documents support for) it; MBR for multiboot of
more than a very few OSes tends to be a problem, and BSD-specific
disklabel is largely an anachronism (and is incompatible between BSD

Home | Main Index | Thread Index | Old Index