Using OpenBSD as a host for VMs. Part 4. Storage setup

Create storage for VMs

In this post I’ll create storage for VMs.

Prepare

For VM storage I will use four 500 GB HDDs. These drives will be used as a software RAID 5. The RAID will be encrypted and mounted at /mnt/vm/data.

To show the list of available disks, run:

sysctl hw.disknames

The output should look like this:

List of available disks

In this case, sd2, sd3, sd4, and sd5 are SATA HDDs to be used as VM storage.

Build the RAID 5 storage

To build this RAID, I will use the official OpenBSD FAQ.

Create partition tables

First, create partition tables with fdisk(8):

fdisk -iy sd2 && fdisk -iy sd3 && fdisk -iy sd4 && fdisk -iy sd5

Create partition tables

Create the partition layout

Create the partition layout on the first device via disklabel(8):

disklabel -E sd2

Create partition layout

Copy the partition layout to the other devices:

disklabel sd2 > layout
disklabel -R sd3 layout
disklabel -R sd4 layout
disklabel -R sd5 layout
rm layout

Copy the partition layout to the other devices

Assemble the RAID 5 array

Assemble the RAID 5 array with the bioctl(8) command:

bioctl -c 5 -l sd2a,sd3a,sd4a,sd5a softraid0

Assemble the RAID 5 array

The created RAID 5 device node is sd8.

Create the device node:

cd /dev && sh MAKEDEV sd8

Zero the first chunk:

dd if=/dev/zero of=/dev/rsd8c bs=1m count=1

Create the encrypted data container

Create partition tables and a layout for the data container:

fdisk -iy sd8
disklabel -E sd8

Create partition tables and a layout for the data container

Assemble the encrypted data container:

bioctl -c C -l /dev/sd8a softraid0

Assemble the encrypted data container

The encrypted device node is sd9.

Create the device node:

cd /dev && sh MAKEDEV sd9

Zero the first chunk:

dd if=/dev/zero of=/dev/rsd9c bs=1m count=1

Create a file system on the data container

Create partition tables and a layout on the encrypted data container:

fdisk -iy sd9
disklabel -E sd9

Create a new file system:

newfs /dev/rsd9a

Create partition tables and a layout on the encrypted data container

Mount the created RAID

Create the mount point:

mkdir -p /mnt/vm/data

Get the disklabel UID of the encrypted data container:

sysctl hw.disknames

Get the disklabel UID of the encrypted data container

Edit /etc/fstab to mount the VM data container like this:

521a068f7c44f4f0.a /mnt/vm/data ffs rw,nodev,nosuid 1 2

Conclusion

I created RAID 5 storage for VM data with an encrypted container.