OpenBSD uses disklabel
to set up partitions on all hardware platforms. We used disklabel(8)
as part of the installation process, but you need to partition new disks before you can use them. (You can also use disklabel
to back up, restore, and duplicate partition tables.)
To view the current disklabel, just give the disk name as an argument. Here’s how to see the disklabel of the empty disk from the previous section:
# disklabel wd1 1 # /dev/rwd1c: … 2 duid: 0000000000000000 … 16 partitions: # size offset fstype [fsize bsize cpg] 3 c: 33554304 0 unused
This looks much like the disklabel we saw in Chapter 2, with a few critical differences.
First, note the device at 1. The disklabel
command accesses the raw device, but you should use the block device at the command line.
This label at 2 has no DUID. This is the default empty disklabel. We will generate a DUID later.
At 3, we see that this disk has only one partition, c, which represents the entire disk. You could create and use a filesystem on partition c, but it’s not standard practice to do so.
The simplest way to create partitions is to use the same interactive disklabel editor that we used to install OpenBSD. Give the disklabel editor the -E
flag and the disk name:
# disklabel -E wd1
Label editor (enter '?' for help at any prompt)
>
Now you can add, remove, and edit partitions, just as in Chapter 3.
Throughout the rest of the book, we’ll edit disklabels as needed to change partition and filesystem characteristics.
Before messing with a disk, back up its disklabel so that you can fall back to the old label if you screw up. You can back up the disklabel with this command:
# disklabel wd1 > wd1.disklabel.saved
To apply a saved disklabel to a disk, give disklabel
the -R
flag, the disk device, and the label file:
# disklabel -R wd1 wd1.disklabel.saved
This writes the saved label to the disk. You can use saved disklabels to duplicate partitioning across identical disks.
Now that you have partitions, let’s put a filesystem on them.