💾 Archived View for paritybit.ca › arboretum › sysadmin › openbsd-nas.gmi captured on 2023-01-29 at 03:01:52. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

OpenBSD NAS

← Back

The machine is a Dell Optiplex 3020MT with the following specs:

In addition to my normal OpenBSD Server Setup:

OpenBSD Server Setup

Creating the RAID 1 Array

Assuming `sd0` and `sd1` are the disks to be mirrored, and `sd3` is the result

(it may not be, check first and check output of bioctl):

# fdisk -gy sd0
# fdisk -gy sd1
# disklabel -E sd0
sd0> a a
offset: [64]
size: [<max>] *
FS type: [4.2BSD] RAID
sd0*> w
sd0> q
# disklabel sd0 > layout
# dislabel -R sd1 layout
# rm layout
# bioctl -c 1 -l sd0a,sd1a softraid0
# disklabel -E sd3
sd3> a a
offset: [0]
size: [<max>] *
FS type: [4.2BSD]
sd3*> w
sd3> q
# newfs sd3a

Then make note of the duid returned by `sysctl hw.disknames` for sd3 and, in `/etc/fstab`:

<duid>.a /var/syncthing ffs rw,nodev,nosuid,noatime,noexec 1 2

Note that syncthing on OpenBSD is configured by default to serve out of `/var/syncthing`. The `_syncthing` user must have `rwx` permissions on that directory.

Monitoring and Fixing the Array

Checking the status of the mirror can be done with the command:

# bioctl <duid>

and should be added to a daily cronjob/script.

Should a hard drive fail, assuming the replaced disk is `sd1`, the RAID can be rebuilt like so:

# disklabel -E sd1
sd0> a a
offset: [64]
size: [<max>] *
FS type: [4.2BSD] RAID
sd0*> w
sd0> q
# bioctl -R /dev/sd1a sd3

Syncthing

Since I'm running syncthing on this machine, I installed the `syncthing` package, and did the following to increase the number of open files allowed by the daemon:

# echo 'kern.maxfiles=131072' > /etc/sysctl.conf
# sysctl kern.maxfiles=131072
# cat >> /etc/login.conf
syncthing:\
        :openfiles=124042:\
        :tc=daemon:

The syncthing GUI only listens on the localhost address by default. To access this from my machines, I added the following line to `~/.ssh/config` under the entry for my server:

LocalForward 8385 127.0.0.1:8384

which lets me go to `localhost:8385` in my browser when I'm SSHed into the NAS.

Backups

Using OpenBSD's built-in `dump(1)`, after an initial dump of the filesystem is created at level `0`, incremental backups are done to an external drive from `/etc/daily.local`:

next_part "Backing up filesystems:"
dump -1auf /var/backups/syncthing/$(date +%Y%m%d).dump.1 /var/syncthing