OpenBSD NAS
I've decommissioned this system since I couldn't bring it with me when moving, but this page might still be useful in the future.
The machine is a Dell Optiplex 3020MT with the following specs:
- CPU: i3-4150 @ 3.50GHz (2C/4T)
- RAM: 2+4GB DDR3
- Boot: Samsung 870 EVO 250GB SSD
- Storage: Mirror of Two HGST HDN726040ALE614 (4TB) HDDs
- Backup Storage: Seagate Expansion 8TB External HDD
In addition to my normal 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), a level 0 dump of the filesystem is created
once a month followed by daily incremental backups at level 1:
next_part "Creating new level 0 dump..."
dump -0auf /var/backups/syncthing/$(date +%Y%m%d).dump.0 /var/syncthing
next_part "Backing up filesystems:"
dump -1auf /var/backups/syncthing/$(date +%Y%m%d).dump.1 /var/syncthing