{"id":559,"date":"2024-04-03T23:27:38","date_gmt":"2024-04-03T20:27:38","guid":{"rendered":"https:\/\/netbsd.name\/?p=559"},"modified":"2024-04-08T22:41:23","modified_gmt":"2024-04-08T19:41:23","slug":"boot-into-ssd-in-qnap-tvs-675","status":"publish","type":"post","link":"https:\/\/netbsd.name\/?p=559","title":{"rendered":"Boot into SSD in QNAP TVS-675"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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 <a href=\"http:\/\/debian.org\/\">Debian<\/a> Linux due to hardware support issues at that time. Since then I have used few different distributions for over a decade (mainly <a href=\"https:\/\/archlinux.org\/\">Arch<\/a> and <a href=\"https:\/\/artixlinux.org\/\">Artix<\/a>).  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 <a href=\"https:\/\/www.biostar.com.tw\/app\/en\/mb\/introduction.php?S_ID=976\">FX9830M<\/a> motherboard. My goal in doing so is to make setup as cheap as possible by scrapping various parts from my closet. Unfortunately, it didn&#8217;t workout as planned, mainly due to uncomfortably noisy operation of aforementioned motherboad&#8217;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&#8217;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 <a href=\"https:\/\/www.qnap.com\/en\/product\/tvs-675\">QNAP TVS-675<\/a> NAS system for this purpose.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 &#8220;fancy&#8221; 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).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The installation of the NetBSD 10.0 didn&#8217;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&#8217;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 &#8211; to root on ZFS or CGD functionality, however I didn&#8217;t configure a separate ramdisk for that, at least now.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to achieve that, I needed to prepare a bootable USB flash drive. One can use a lengthy <a href=\"https:\/\/wiki.netbsd.org\/tutorials\/how_to_create_bootable_netbsd_image\/\">instructions<\/a> with the <a href=\"https:\/\/wiki.netbsd.org\/Installation_on_UEFI_systems\/\">UEFI<\/a> 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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PATH=\/sbin:\/bin\nexport PATH\n\nmount -u \/\nmount -t tmpfs tmpfs \/tmp\nmount \/altroot\nsysctl -w init.root=\/altroot\n\n# done, move on to multiuser mode\nexit 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To complete a setup, I added required fields to \/etc\/fstab by setting correct \/altroot mount point to the SSD&#8217;s root partition.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME=&lt;usbpartionid&gt;\t\t\/\t\tffs\trw\t\t1 1\ntmpfs\t\t\t\/tmp\t\ttmpfs\trw\t\t0 0\nNAME=&lt;ssdpartitionid&gt;\t\t\t\/altroot\tffs\tro,log\t1 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The important part was to mount \/altroot as read-only (ro), otherwise automatic filesystem check kicked-in and disrupted the boot process (it can&#8217;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&#8217;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&#8217;t tried it. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After reboot the system successfully booted and switched to SSD root folder!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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&#8217;t explored that just yet, since i I don&#8217;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 <a href=\"https:\/\/www.intenso.de\/en\/products\/usb-sticks\/slim-line\">Intenso Slim Line<\/a> to make protrusion from the case as minimal as it can be.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next step will be to setup my hard drives to using <a href=\"https:\/\/man.netbsd.org\/zfs.8\">ZFS<\/a> file system, setup <a href=\"https:\/\/man.netbsd.org\/nfsd.8\">NFS<\/a> and <a href=\"https:\/\/www.samba.org\/\">samba<\/a> as well as network with <a href=\"https:\/\/man.netbsd.org\/lagg.4\">lagg(4)<\/a> 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&#8217;s \/etc\/modules.conf file, which loads modules correctly, however I am not certain if it won&#8217;t be too late for mounting ZFS partitions automatically. I will definitely explore that in the next post.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Few useful resources on this topic:<br><a href=\"https:\/\/mail-index.netbsd.org\/tech-install\/2008\/11\/22\/msg000086.html\" data-type=\"link\" data-id=\"https:\/\/mail-index.netbsd.org\/tech-install\/2008\/11\/22\/msg000086.html\">HowTo: Making a bootable ISO w\/ miniroot.kmod etc.<\/a><br><a href=\"https:\/\/bentsukun.ch\/posts\/ramdisk-kernel\/\">Building a NetBSD ramdisk kernel<\/a><br><a href=\"https:\/\/wiki.netbsd.org\/root_on_zfs\/\">Root On ZFS<\/a><br><a href=\"https:\/\/www.unitedbsd.com\/d\/461-netbsd-full-disk-encryption-with-cgd\">NetBSD Full-Disk Encryption with CGD<\/a><br><a href=\"http:\/\/www.jsevy.com\/netbsd\/porting\/building.html\">Building NetBSD system components<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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). &hellip; <a href=\"https:\/\/netbsd.name\/?p=559\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Boot into SSD in QNAP TVS-675<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,3],"tags":[],"class_list":["post-559","post","type-post","status-publish","format-standard","hentry","category-nas","category-netbsd"],"_links":{"self":[{"href":"https:\/\/netbsd.name\/index.php?rest_route=\/wp\/v2\/posts\/559","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netbsd.name\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netbsd.name\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netbsd.name\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netbsd.name\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=559"}],"version-history":[{"count":4,"href":"https:\/\/netbsd.name\/index.php?rest_route=\/wp\/v2\/posts\/559\/revisions"}],"predecessor-version":[{"id":565,"href":"https:\/\/netbsd.name\/index.php?rest_route=\/wp\/v2\/posts\/559\/revisions\/565"}],"wp:attachment":[{"href":"https:\/\/netbsd.name\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netbsd.name\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netbsd.name\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}