Historically, my first NAS system was running NetBSD operating system (5th release if I am not mistaken), however after a hardware update, I was forced to switch to the Debian Linux due to hardware support issues at that time. Since then I have used few different distributions for over a decade (mainly Arch and Artix). Several years ago I upgraded the underlying platform again with the hopes to use it for at least as long as my previous system. This NAS setup is based on Biostar FX9830M motherboard. My goal in doing so is to make setup as cheap as possible by scrapping various parts from my closet. Unfortunately, it didn’t workout as planned, mainly due to uncomfortably noisy operation of aforementioned motherboad’s CPU fan, which I have never managed to remedy (unusual fan connector and cooling solution is a limiting factor, requiring to do custom solutions without knowing if that solution will work). In addition, the compact case didn’t provide enough airflow leading to slightly overheating HDDs which may affect their operational lifetime. Thus, I decided that it may be a good chance to come back to a long time dream of switching back to NetBSD in my NAS setup and I acquired QNAP TVS-675 NAS system for this purpose.
Under the hood it uses Zhaoxin KaiXian KX-U6580 8-core x86-64 CPU, has 6 HDD bays, has an option to add two PCIe Gen 3 x4 cards (the slot allows to attach longer cards thanks to the cut at the back of it), and supports NVMe expansion slots. It is almost a typical x86-64 PC, just wrapped into a “fancy” case specifically designed for NAS purposes. It operates pretty silently by default, with only audible noise coming from HDDs themselves during heavy operations (once high capacity SSDs are cheap enough I may switch to them).
The installation of the NetBSD 10.0 didn’t bring any surprises and went smoothly, however I faced the first issue just after the first reboot. There was no support to boot directly from SATA SSD (limitation of the system’s BIOS). Only the USB boot devices are supported. As a result, I started to look into options somehow to start booting from USB, to switch the root system to the SSD partition at the subsequent stages of the boot process. After reading a few resources (will mention them at the end of the article) and consulting the NetBSD developers, I decided to use a pretty simple approach with SSD root partition being mounted to /altroot, where kernel eventually is being instructed to chroot to it. The approach is similar – to root on ZFS or CGD functionality, however I didn’t configure a separate ramdisk for that, at least now.
In order to achieve that, I needed to prepare a bootable USB flash drive. One can use a lengthy instructions with the UEFI in mind, or install a minimal system using installation media, however I took a lazy approach by dissecting provided installation media itself. I just mounted it on my main NetBSD system and deleted all unnecessary folders and files, updated netbsd kernel (I am building a custom one, but GENERIC can be used) and updated /etc/rc script by mounting required partitions, including SSD root to /altroot and finally setting init.root kernel option to /altroot, so that it would switch to it during boot process:
PATH=/sbin:/bin
export PATH
mount -u /
mount -t tmpfs tmpfs /tmp
mount /altroot
sysctl -w init.root=/altroot
# done, move on to multiuser mode
exit 0
To complete a setup, I added required fields to /etc/fstab by setting correct /altroot mount point to the SSD’s root partition.
NAME=<usbpartionid> / ffs rw 1 1
tmpfs /tmp tmpfs rw 0 0
NAME=<ssdpartitionid> /altroot ffs ro,log 1 1
The important part was to mount /altroot as read-only (ro), otherwise automatic filesystem check kicked-in and disrupted the boot process (it can’t check rw mounted partitions), requiring for the manual interaction. It is not an issue, since root partition will remount in rw mode by reading SSDs /etc/fstab. If there’s a need to change some files in /altroot before chroot (like rndseed for example), automount can be still rw but rc script should remount /altroot manually as read only shortly before sysctl command. Alternative approach may be to skip remounting root partition at all, but I haven’t tried it.
After reboot the system successfully booted and switched to SSD root folder!
Ideally I would like to avoid having USB flash drive being attached at all. I believe that integrated USB DISK module can be utilized somehow, but I haven’t explored that just yet, since i I don’t want to mess up the default boot configuration for the their own custom OS and it needs more time and skills to implement. For the time being, I would likely buy a very short USB flash driver, similar to Intenso Slim Line to make protrusion from the case as minimal as it can be.
The next step will be to setup my hard drives to using ZFS file system, setup NFS and samba as well as network with lagg(4) link aggregation. I am unsure at the moment, where I should load zfs modules, should it be before the chroot operation happens or it can be loaded after. Currently I am utilizing SSD root partition’s /etc/modules.conf file, which loads modules correctly, however I am not certain if it won’t be too late for mounting ZFS partitions automatically. I will definitely explore that in the next post.
Few useful resources on this topic:
HowTo: Making a bootable ISO w/ miniroot.kmod etc.
Building a NetBSD ramdisk kernel
Root On ZFS
NetBSD Full-Disk Encryption with CGD
Building NetBSD system components