Files
web-log/container/site/content/posts/nas-build-pt-i/index.md
T
2025-07-05 15:36:34 +00:00

157 lines
11 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
+++
categories = ["technology","build"]
date = 2021-09-09T14:53:39Z
description = ""
draft = false
slug = "server-build"
title = "💾 Server Build"
author = "nicholas"
+++
## Notes
I am in possession of an increasingly large heap of data and I need a place to put it. I need a server that will run services that help serve and organize the files. Cloud storage/server solutions are too expensive for my purposes.
{{< image
src="images/nas-internals.jpg"
caption="NAS internal components" >}}
## Additional considerations in ascending order of plausibility / no real order.
* You use a USB stick to move files around and this process rapidly accelerates the rate at which your body experiences senescence.
* Your favorite cloud storage service kicked you off for abusing their unlimited plan.
* You cannot look yourself in the mirror lest you see a man in it you do not recognize, one that contrasts to the otherwise cool, confident and competent human being of 20 minutes ago, after you find yourself in a pinch forced to send files over Bluetooth in a last ditch effort to move one tiny, absolutely infuriatingly tiny but necessary configuration file to a device just inches away a task so conceptually simple and obvious even your technologically mystified ancestors still laugh raucously at your impotence from the great beyond. You agonize over the tedium again and again casting all the right spells, clicking all the right buttons, trying to stay calm to lower your dangerously spiking blood pressure. You avert your eyes in furious rebellion from the digital clock in the corner of the screen that seems to mock your focused efforts you begin to regret the decision to allow the Windows task bar clock to display the seconds digits now the ticking away a ceaseless reminder of your mortality and of your hopeless battle against God's will to squeeze one moment of triumph one small victory from your precious time on this Earth. You are Sisyphus, the file transfer your impossible burden. But what of your crime? What did you do to deserve this? No one and no thing will tell you and no error message reveals the nature of your failure. Not Sisyphus or Josef of The Trial, but some secret third, more hated thing. Your vision closes in around you try and you try and you will this cursed thing to be done! But the incantation is not quite right. You inflected where you should have introflected. Permissions issue. Firewalled. Timeout. DNS error. The transfer fails to your stuttering bewilderment and dismay in dozens of ways in the span of 12 minutes. In your fits of now blinding rage you are given no clues as to why or rather you cannot see the error messages, only that you have failed. You are resigned to accept your destiny, to forever struggle to move the file you have come to resent until the miser within you capitulates, finally releasing the funds necessary to buy your very own
## Network Attached Storage
The solution to my data storage and retrieval woes is a `NAS`, which is a file storage server attached to my local network. As long as a device has access to the network, so too shall I have access to the data.
## Requirements
* 3.5" Drive Bay capacity of 6.
* Good things come in 3s and I will be mirroring each drive. Therefore 6.
* Multi-core processor
* Integrated GPU.
* Low cooling requirements.
* Low idle power consumption (>~10w).
* 2.5G Intel NIC.
* Enough RAM and room for expansion
* Inexpensive
* Parts widely available
## Build or Buy
The first consideration is buying versus building. The distinction will probably be difficult to pin down since arguably even the machines I refer to as "pre-built" require some hardware installation and software configuration. But for the purposes here, the distinction between these two will be found mostly in the form and features of the machine. Where a pre-built dedicated NAS is typically an elegant yet stout, low profile bank of hard drives equipped with hot-swappable bays (I speak only of the non-enterprise, consumer-focused products), a DIY build can be of any form my heart desires so long as the limitations of the form factor are compatible with the requirements. The performance to price ratio will almost certainly weigh heavily in favor of the build path, but at the cost of that sweet, sweet NAS aesthetic in all of its flashing activity lights and hot-swap bay glory. In the end, this build is just a collection of computer hardware. I will be building this computer myself rather than buying one COTS style.
## Hardware
The easiest part of a DIY NAS may be selecting the hardware. I use a PC hardware compatibility tool called PCPARTPICKER to ensure components that are compatible with all parts of the system.
| Type | Item |
| ------------- | ---------------------------------------------------------------------------- |
| CPU | Intel Pentium Gold G5400 3.7 GHz Dual-Core Processor |
| Memory | Crucial 16 GB (2 x 8 GB) DDR4-2400 CL17 Memory |
| Motherboard | ASRock H370M-ITX/ac Mini ITX LGA1151 Motherboard |
| Case | Fractal Design Node 304 Mini ITX Tower Case |
| Power Supply | Corsair CX (2017) 450 W 80+ Bronze Certified ATX Power Supply |
| OS Disc | WD Blue SA510 SSD |
| Miscellaneous | SATA Power Splitter Adapter Cable - M/F - 4x Serial ATA Power Cable Splitter |
| | Zip Ties |
## Data Drives
I can purchase my HDDs from my favorite retailer and received a big and fat juicy warranty and sleep well at night, reassured by the implications of my drives coming with something like a three year manufacturer warranty. OR I can consider the sneakier, riskier, more cost-effective play called "shucking".
## Shucking
Shucking is the practice of purchasing external storage devices such as Western Digital EasyStore, or Seagate Expansion and removing the raw 3.5" hdd inside. The external drives are meant to function as portable, high capacity external storage devices that interface with computers over USB (as opposed to an internal drive via e.g. SATA), but this does not need to be the case. Huge discounts can and were achieved with certain models of HDDs/external storage devices, but in the face of (small) risks such as accidentally damaging the drive during shucking, potentially voiding certain warranties, and dealing with the general uncertainty of the specifications of the drive inside the device.
I have chosen to source my drives this way, and successfully shucked a total of 6 HDDs.
| Type | Purpose | Capacity | Device |
| ---- | ---------------- | -------- | --------- |
| hdd | data | 12 TB | /dev/sda |
| hdd | data | 12 TB | /dev/sdb |
| hdd | data | 12 TB | /dev/sdc |
| hdd | data | 12 TB | /dev/sdd |
| hdd | data | 8 TB | /dev/sde |
| hdd | data | 8 TB | /dev/sdf |
| ssd | operating system | 512 GB | /dev/nvme |
After installing all the hardware, the next step is to install an operating system on the OS drive. I prefer a Debian-based distribution, so I install the latest version. It makes more sense to install the OS before any of the disks, since I may be frequently cycling the power for troubleshooting purposes, and spinning up and down the discs this way will, however slightly, unnecessarily add wear-and-tear to the discs. My concern is probably on the verge of unhealthy paranoia.
## Disk Testing
The process is variable depending on how rigorous the tests are designed to be. It is a matter of personal preference and risk tolerance. The purpose is to run the disks in such a way as to reveal their flaws should they have any in other words, to check for bad blocks, sectors, and evaluate the general health through other means that are yet mysterious to me. Ideally I will run the tests before the drives are removed from their enclosures. There are methods that take anywhere from a few hours to days and even weeks. Two tools that will be useful to me in disk testing are badblocks and smartctl. I do not say much about my disk testing here. I use both to determine that all of my drives are free of bad blocks and are healthy.
```shell
sudo apt install e2fsprogs -y && apt install smartmontools
badblocks -b 4096 -wsv /dev/sda > badblocks_output.log
```
### Filesystem - ZFS
The next step is to decide on the filesystem. There are several options but ZFS makes the most sense to me. It is a purpose-built file system and volume manager designed for long-term data storage. Using ZFS allows data to be "mirrored" across different drives so that in the event of single drive failure, no data is lost and there is no downtime. The process of repairing the NAS is basically as simple as installing a new disk in place of the failed drive and use the ZFS replace command to re-silver the new disk. The system is configured as a single pool, which acts as a single file storage device it can be mounted as a single directory. The pool consists of one zpool which consists of three vdevs , each of which are two-drive mirrors.
```
sudo zpool status
NAME STATE READ WRITE CKSUM
hdd1 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
sda ONLINE 0 0 0
sdb ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
sdd ONLINE 0 0 0
sdc ONLINE 0 0 0
mirror-2 ONLINE 0 0 0
sde ONLINE 0 0 0
sdf ONLINE 0 0 0
```
## Maintenance
During the install process, ZFS may automatically create two cron jobs at /etc/cron.d/zfsutils-linux This is sort of self explanatory but these cron jobs will run once a month to perform TRIM and Scrub operations on the filesystem.
```shell
cat /etc/cron.d/zfsutils-linux
# TRIM the first Sunday of every month.
24 0 1-7 * * root if [ $(date +\%w) -eq 0 ] && [ -x /usr/lib/zfs-linux/trim ]; then /usr/lib/zfs-linux/trim; fi
# Scrub the second Sunday of every month.
24 0 8-14 * * root if [ $(date +\%w) -eq 0 ] && [ -x /usr/lib/zfs-linux/scrub ]; then /usr/lib/zfs-linux/scrub; fi
```
## Network Share - Samba
This is where the computer turns into a NAS where I will expose the mount point of the filesystem to the network, allowing authorized users to read and write to the filesystem. I use samba to do this. Here I install and configure the service.
```shell
sudo apt update && sudo apt install samba -y
sudo nano /etc/samba/smb.conf
```
Appended the following lines to `smb.conf`
```
[hdd1]
comment = Some useful files
read only = no
guest ok = no
path = /hdd1
valid users = nicholas
```
This configuration enables one network share: `hdd1`. The path variables refer to the directory of the ZFS pool.
Samba requires its own password for each user to authenticate. Even if user nicholas already has password, he needs a separate Samba password.
```shell
sudo smbpasswd -a nicholas
```
The user also needs permissions
Now I restart Samba.
```shell
sudo service smbd restart
```
I should be able to access this share using the credentials of valid user which was defined in `/etc/samba/smb.conf`.
Done.