Using Disklabel

After fdisk partitions (MBR or GPT partitions) have been created, disklabel is used to create OpenBSD filesystem partitions (OpenBSD disklabel partitions exist inside of an fdisk partition).

This guide is for creating disklabel partitions for a second disk.

NOTE: This guide does not cover how to layout OpenBSD partitions for a new install. Please see the disklabel partitioning guide for new installs, before reading this guide.

In this guide, we have a new disk we have just created MBR/GPT fdisk partitions for on sd1. We now want to edit the disklabel partitions:

$ doas disklabel -E sd1
Label editor (enter '?' for help at any prompt)

Type ? to show the help message:

sd1> ?
Available commands:
 ? | h    - show help                 n [part] - set mount point
 A        - auto partition all space  p [unit] - print partitions
 a [part] - add partition             q        - quit & save changes
 b        - set OpenBSD boundaries    R [part] - resize auto allocated partition
 c [part] - change partition size     r        - display free space
 D        - reset label to default    s [path] - save label to file
 d [part] - delete partition          U        - undo all changes
 e        - edit drive parameters     u        - undo last change
 g [d|u]  - [d]isk or [u]ser geometry w        - write label to disk
 i        - modify disklabel UID      X        - toggle expert mode
 l [unit] - print disk label header   x        - exit & lose changes
 M        - disklabel(8) man page     z        - delete all partitions
 m [part] - modify partition

Suffixes can be used to indicate units other than sectors:
 'b' (bytes), 'k' (kilobytes), 'm' (megabytes), 'g' (gigabytes) 't' (terabytes)
 'c' (cylinders), '%' (% of total disk), '&' (% of free space).
Values in non-sector units are truncated to the nearest cylinder boundary.

Each fdisk partition can be sliced into OpenBSD disklabel partitions with letters as labels. By convention, a partition is your root partition, b is your swap, and c is the entire disk.

To print the partitions in gigabytes:

sd1> p g
OpenBSD area: 64-1073736405; size: 512.0G; free: 512.0G
#                size           offset  fstype [fsize bsize   cpg]
  c:           512.0G                0  unused                    

If you already have the operating system installed on another disk, you just need 1 single partition: the a partition with the same size as the disk.

We want to add the a partition. We'll use defaults for offset, size, and FS type:

sd1> a a

We should leave the first logical track unused, so the first partition should start at sector 64:

offset: [64] 
size: [1073736341] 
FS type: [4.2BSD] 
sd1*> p g
OpenBSD area: 64-1073736405; size: 512.0G; free: 0.0G
#                size           offset  fstype [fsize bsize   cpg]
  a:           512.0G               64  4.2BSD   4096 32768     1 
  c:           512.0G                0  unused                    

Then write the changes to disk and quit:

sd1*> w
sd1> q
No label changes.

You'll now want to use newfs to construct the new filesystem.

Disklabel Unique ID (DUID)

disklabel(8) creates a disklabel unique identifier (DUID) for each disk. To find the DUID of a disk sd0:

  1. disklabel sd0 | grep duid

duid: fd7ecb3de7e46e12

We see this disk sd0 has a DUID of fd7ecb3de7e46e12.

Configuration files like /etc/fstab prefer DUIDs instead of relative device names because device ordering may change over time.