Skip to content
Go back

Debian 13 + ZFS on a QNAP TS-451

By KingPin 16 min read
Debian 13 + ZFS on a QNAP TS-451
Contents

The Appliance You Bought Is Not the Computer You Own

A QNAP TS-451 is a good computer wrapped in an operating system you do not control. The hardware is four SATA bays, a Celeron J1800, 8 GB of RAM and a case that fits on a shelf. The software is QTS, a vendor appliance that updates on the vendor’s schedule and exposes whatever the vendor decided to expose.

QNAP boxes have also been a repeat ransomware target. The Qlocker campaign hit them in April 2021, and DeadBolt followed in January 2022. Both went after exposed appliances running vulnerable firmware, and your only defense was waiting for the vendor patch. I am not going to lecture you about it. I am going to say that I would rather patch my own OS with apt.

So here is the thesis. An old 4-bay QNAP is a fine Debian + ZFS box once you stop booting the vendor OS. You keep the hardware. You lose the lock-in. Nothing on the internal flash gets touched, so the rollback plan is “unplug one USB drive.”

Everything below comes from one real conversion. The box is called nas here, and it runs:

What You Are Working With (and What It Cannot Do)

The TS-451 has an Intel Celeron J1800 at 2.41 GHz with 2 cores, no GPU, and about 8 GB of RAM. That shapes every decision after this one.

ZFS on 8 GB works fine if you stop it from eating the box. The rules I followed:

  1. raidz1 across four disks. Usable space is about 24 TB (roughly 22 TiB) of 32 TB raw. The parity math is cheap, even on two slow cores.
  2. ARC capped at 3 GiB. On OpenZFS 2.3 the default ARC maximum is the larger of RAM minus 1 GiB and 5/8 of RAM, which is about 7 GiB on this box. That leaves almost nothing for Docker.
  3. lz4 compression on. It costs almost nothing in CPU and often saves space.
  4. No dedup. Dedup wants RAM the J1800 does not have. Skip it and never think about it again.
  5. No heavy services. Gitea, Syncthing and a small Prometheus stack are fine. A Plex transcode is not happening.

Two honest limits before you start. The J1800 does not support ECC memory, so ZFS checksums catch disk errors but cannot save you from a flipped bit in RAM. And raidz1 on 8 TB disks has a real resilver risk: rebuilding after a failed disk reads all the allocated data on the three survivors, and a second failure during that window loses the pool. I run it because the data has other copies, and I wrote it down as a risk instead of pretending it is not one. If you have no other copies, use raidz2 (about 16 TB usable on four disks) or two mirrored pairs.

Boot Debian From a USB SSD, Leave the DOM Alone

QNAP boxes boot QTS from a small internal flash module, usually called the DOM. On this box it shows up as /dev/sdf, 492 MiB, model “USB DISK MODULE”, with three partitions. I did not wipe it. QTS is still on it.

Instead, Debian lives on a 250 GB SATA SSD in a USB enclosure plugged into the back of the box. Set the boot order in the BIOS so the USB SSD goes first. To go back to QTS, unplug the SSD and reboot.

Build the image on another machine, not on the NAS. I used a roughly 95-line bash script that runs inside a Docker container and installs a headless Debian 13 straight onto the target disk. The outline looks like this:

Terminal window
# inside a throwaway Debian container with the SSD passed through
debootstrap --arch amd64 trixie /mnt/target http://deb.debian.org/debian
# then, chrooted into /mnt/target
apt install linux-image-amd64 grub-efi-amd64 openssh-server sudo
grub-install --target=x86_64-efi --efi-directory=/boot/efi --removable
update-grub

The script also does the hardening so the box is safe the first time it touches the network:

Terminal window
passwd -l root
cat > /etc/ssh/sshd_config.d/10-hardening.conf <<'EOF'
PasswordAuthentication no
PermitRootLogin no
EOF
# admin user, SSH key only, passwordless sudo
install -d -m 700 -o admin -g admin /home/admin/.ssh
echo "ssh-ed25519 AAAA... you@laptop" > /home/admin/.ssh/authorized_keys
echo "admin ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/admin
chmod 440 /etc/sudoers.d/admin

One gotcha from the build. My first run failed at the grub-pc package step. That is the BIOS GRUB package, and this box boots UEFI. The EFI GRUB package (grub-efi-amd64) was the right one. The --removable flag on grub-install writes the fallback boot path, which helps with a disk that moves between machines.

Root is ext4. /boot/efi is vfat. Nothing exotic.

Wipe the Old RAID5, Build raidz1 by Disk ID

QTS had the four disks in an md RAID5 array on partition 3 of each disk. It also builds small md arrays on the other partitions (system config, swap), and Debian may auto-assemble all of them at boot. ZFS will refuse to touch disks that still carry md signatures, so clear every one. Run lsblk and cat /proc/mdstat before you start.

Terminal window
cat /proc/mdstat
vgchange -an # only if lsblk shows LVM volumes on the array
mdadm --stop --scan
# repeat for every data disk, double-checking the device letters first
for p in /dev/sda?*; do mdadm --zero-superblock "$p" 2>/dev/null; done
wipefs -a /dev/sda?* /dev/sda

Install ZFS from Debian’s contrib component. A debootstrapped image writes a one-line /etc/apt/sources.list, so append contrib to that line (deb http://deb.debian.org/debian trixie main contrib non-free-firmware). A stock trixie install uses /etc/apt/sources.list.d/debian.sources instead, where contrib goes on the Components: line. Then:

Terminal window
apt update
apt install linux-headers-amd64 zfs-dkms zfsutils-linux

Now create the pool using /dev/disk/by-id names. Drive letters like sda can swap after a reboot. Serial-based IDs do not. The serials below are placeholders.

Terminal window
zpool create -o ashift=12 \
-O compression=lz4 -O atime=off \
tank raidz1 \
/dev/disk/by-id/ata-WDC_WD80EFAX-68LHPN0_SERIAL1 \
/dev/disk/by-id/ata-WDC_WD80EFAX-68LHPN0_SERIAL2 \
/dev/disk/by-id/ata-WDC_WD80EFAX-68LHPN0_SERIAL3 \
/dev/disk/by-id/ata-WDC_WD80EFAX-68LHPN0_SERIAL4

What each flag does:

Check it:

Terminal window
zpool status tank
zfs get compression,atime,recordsize tank

After that, create one dataset per kind of data so you can snapshot, tune and clean them up independently:

Terminal window
zfs create tank/assets
zfs create tank/code
zfs create tank/gitea
zfs create tank/sync

The pool shows about 20.9 TiB available.

Cap the ARC, Snapshot With sanoid, Scrub Monthly

Three small config jobs keep a ZFS box healthy.

ARC cap. The value is in bytes, and 3 GiB is 3221225472:

/etc/modprobe.d/zfs.conf
options zfs zfs_arc_max=3221225472

That applies at the next module load. To apply it right now without rebooting:

Terminal window
echo 3221225472 > /sys/module/zfs/parameters/zfs_arc_max

Snapshots with sanoid. I replaced a hand-written daily snapshot script with sanoid, which Debian packages with a timer that fires every 15 minutes. The policy lives in one file:

/etc/sanoid/sanoid.conf
[tank/assets]
use_template = data
[tank/code]
use_template = data
[tank/gitea]
use_template = data
[tank/sync]
use_template = data
[template_data]
hourly = 24
daily = 30
weekly = 8
monthly = 6
autosnap = yes
autoprune = yes

Hourly for 24 hours, daily for 30 days, weekly for 8 weeks, monthly for 6 months. The autoprune line is what keeps snapshots from piling up forever.

Monthly scrub. OpenZFS ships a templated systemd timer. Turn it on for the pool:

Terminal window
systemctl enable --now [email protected]
systemctl list-timers 'zfs-scrub*' sanoid.timer

Debian also ships a cron job in /etc/cron.d/zfsutils-linux that scrubs on the second Sunday of each month. Keep one scheduler, not both. I commented out the scrub line in that file. The cleaner option is a property the Debian scrub script reads:

Terminal window
zfs set org.debian:periodic-scrub=disable tank

A scrub reads every block and checks it against its checksum. On a raidz1 pool, that is how you find bit rot while you still have parity to repair it.

SMB3 Only, Bound to the LAN and Tailscale

Samba is the reason most people have a NAS, so it deserves a locked-down config. This one binds to loopback, the LAN address and the Tailscale CGNAT range, and refuses anything older than SMB3:

/etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = nas
server role = standalone server
interfaces = 127.0.0.1 192.168.1.50/24 100.64.0.0/10
bind interfaces only = yes
hosts allow = 127.0.0.1 192.168.1.0/24 100.64.0.0/10
hosts deny = ALL
server min protocol = SMB3
map to guest = never
disable netbios = yes
smb ports = 445
load printers = no
printing = bsd
printcap name = /dev/null
disable spoolss = yes
[assets]
path = /tank/assets
valid users = admin
read only = no

The line doing the most work is server min protocol = SMB3. SMB1 is the protocol you do not want listening on a home network, and plenty of old scanners still ask for it. They can find another share. In Samba, SMB3 here resolves to SMB 3.1.1 (Windows 10 and newer); use SMB3_00 if you still have Windows 8-era clients. disable netbios and smb ports = 445 shut the legacy discovery ports.

Check the file before restarting, then add the Samba password for your user:

Terminal window
testparm -s
smbpasswd -a admin
systemctl restart smbd
smbclient -L //192.168.1.50 -U admin -m SMB3

That proves SMB3 works. To prove SMB1 is refused, force the client down to it. This one should fail to connect:

Terminal window
smbclient -L //192.168.1.50 -U admin --option='client min protocol=NT1' -m NT1

The smartd Trap: Four Disks, Zero Monitoring

I planned to write this section as its own post. Here it is instead.

After the build, I checked systemctl status smartmontools and saw it running. It was not. The service was stuck “activating,” and hours later systemd killed it. The four data disks had never been monitored.

The cause was the stock /etc/smartd.conf, which ships with DEVICESCAN. That line probes every block device it finds. It found the USB boot SSD at /dev/sde and decided it was a USB NVMe disk behind a JMicron bridge, which uses the sntjmicron passthrough in smartmontools. The drive behind that bridge is a SATA SSD. The probe hung.

The journal tells the story:

smartd: Device: /dev/sda, type changed from 'scsi' to 'sat'
smartd: Device: /dev/sde [USB NVMe JMicron], opened
...
(nothing for hours)
systemd[1]: smartmontools.service: start operation timed out. Terminating.
systemd[1]: smartmontools.service: Failed with result 'timeout'.

The first line is normal. smartd probes WD disks as SCSI, then switches to SAT. The [USB NVMe JMicron] line at 16:10:11 is the last sign of life. The timeout arrived at 21:08, nearly five hours later. Because smartd never finished starting, it never began monitoring /dev/sda through /dev/sdd either.

The fix is to drop DEVICESCAN and list the data disks explicitly:

/dev/sda -d sat -a -o on -S on -s (S/../.././02|L/../../7/03) -n standby,q -m root -M exec /usr/local/sbin/nas-notify
/dev/sdb -d sat -a -o on -S on -s (S/../.././02|L/../../7/03) -n standby,q -m root -M exec /usr/local/sbin/nas-notify
/dev/sdc -d sat -a -o on -S on -s (S/../.././02|L/../../7/03) -n standby,q -m root -M exec /usr/local/sbin/nas-notify
/dev/sdd -d sat -a -o on -S on -s (S/../.././02|L/../../7/03) -n standby,q -m root -M exec /usr/local/sbin/nas-notify

Reading the options left to right:

Test before you trust it. Run these by hand:

Terminal window
timeout 60 smartctl --scan-open
smartctl -d sat -a /dev/sda
smartd -q onecheck

smartctl --scan-open opens each device and shows the type smartd would autodetect. A SATA SSD listed as -d sntjmicron is your warning. Plain --scan does not open the devices, so it will not show the bad guess. The timeout is there because opening the device is the step that hung. smartd -q onecheck registers the devices, checks them once and exits, which proves the config parses without leaving a daemon hung.

You could try forcing -d sat on the USB SSD. Some bridges accept it. I chose to exclude the boot disk instead, since a dead boot SSD announces itself by not booting. If you keep your device paths, prefer /dev/disk/by-id names over sdX letters, since the letters can move. smartd accepts them: a smartd -q onecheck run against a by-id path on this box checked the disk and exited with status 0.

One Notify Script for ZED and smartd

ZFS has the ZFS Event Daemon (ZED). smartd has its own alerting. I wanted both to land in the same place, so both call one tiny script. It posts to an ntfy-style URL and always writes a line to syslog, so an alert survives even if the push service is down.

The ZED side:

/etc/zfs/zed.d/zed.rc
ZED_EMAIL_ADDR="root"
ZED_NOTIFY_INTERVAL_SECS=3600
ZED_NOTIFY_VERBOSE=1
ZED_EMAIL_PROG="/usr/local/sbin/nas-notify"
ZED_EMAIL_OPTS="-s '@SUBJECT@' @ADDRESS@"

Keep the quotes around @SUBJECT@. The zed.rc comments call for them, and without them the subject gets split on spaces and the script keeps only its first word. ZED thinks it is calling a mail program, so the script accepts mail-style arguments with the body on stdin. smartd sets SMARTD_MESSAGE in the environment, and the script handles that too:

#!/bin/sh
# Notify helper. Accepts mail-style args (zed: -s SUBJECT ADDR, body on stdin)
# or smartd env (SMARTD_MESSAGE). Sends to NOTIFY_URL (set in /etc/nas-notify.env), always logs to syslog.
[ -r /etc/nas-notify.env ] && . /etc/nas-notify.env
subject="nas alert"
while [ $# -gt 0 ]; do
case "$1" in -s) subject="$2"; shift 2;; *) shift;; esac
done
if [ -n "$SMARTD_MESSAGE" ]; then body="$SMARTD_MESSAGE"; subject="nas SMART: $SMARTD_FAILTYPE"; else body="$(cat)"; fi
logger -t nas-notify "$subject: $body"
[ -n "$NOTIFY_URL" ] && curl -fsS -m 15 -H "Title: $subject" -d "$body" "$NOTIFY_URL" >/dev/null || true

The NOTIFY_URL lives in /etc/nas-notify.env, so the script itself has no secrets in it. The Title header plus a POST body is the format ntfy expects. The trailing || true means a failed push never makes ZED or smartd think the script crashed.

Then test the whole chain without waiting for a disk to die:

Terminal window
echo "test body" | /usr/local/sbin/nas-notify -s "test subject"
journalctl -t nas-notify -n 5

If the line is in the journal and on your phone, the alert path works. Given the smartd story above, I would test it right now.

The Rest of the Box: Docker on ZFS

The NAS also runs a few Docker services. Compose files live in /opt/docker/<name> and each service keeps its data on a ZFS dataset under /tank/<name>. That way sanoid snapshots cover the data without any per-container backup logic.

The current set is Gitea (rootless image, SQLite, registration disabled), Syncthing with its GUI reachable only over Tailscale, and Prometheus plus Grafana. Docker waits for the Tailscale IP at boot so the tailnet-only ports bind correctly.

I also set a static IP during the switch with a rollback timer, so a typo could not strand me outside the box. That one is worth stealing. Schedule a revert before you change the network config, and cancel it once you can still reach the machine.

A separate post covers using this box as a Borg backup target, with per-host datasets and append-only keys. This one stops at the base system.

What I Would Do Differently

The J1800 has no ECC support, so a flipped bit in RAM can be written to disk with a valid checksum. For a home lab with off-box backups I accept that. For irreplaceable data with no second copy, I would not.

The box has gigabit Ethernet only, with no 10GbE and no upgrade path. And two cores cap what Samba can do under load, especially with several clients plus Docker. I did not benchmark it, because the numbers from a short synthetic write on a cached pool would mislead more than inform.

If I did it again, I would set dataset quotas on day one. I did not, and an unbounded dataset will eventually fill the pool. I would also write the smartd.conf before the first boot instead of after it.

Everything else survived the move well. The hardware is paid for, the OS is patched with apt, and the old QTS is still sitting on the flash module if I ever want it.

Common Questions

Can I install Debian on a QNAP TS-451?

Yes. The TS-451 boots from USB, so Debian can live on a USB SSD picked in the BIOS boot order. The internal flash stays untouched, so unplugging the SSD boots QTS again.

Does ZFS need ECC RAM?

No. ZFS runs on non-ECC RAM and checksums every block on disk. ECC protects against memory bit flips that happen before data is written, which ZFS cannot detect. The Celeron J1800 in the TS-451 does not support ECC, so the box has to rely on external backups for important data.

Is raidz1 safe with 8 TB drives?

It is a calculated risk, not a safe default. Rebuilding a failed 8 TB disk in raidz1 reads all the stored data on the surviving disks, and a second failure during that rebuild loses the pool. Run raidz1 only if the data exists elsewhere, and use raidz2 if you can give up a disk of capacity. A monthly scrub reads every stored block and checks it against its checksum, so a failing sector shows up while all four disks still hold parity.

Why did smartd stop monitoring my disks after boot?

The default DEVICESCAN line probes every device, including USB boot drives. On this setup it detected a SATA SSD behind a JMicron bridge as a USB NVMe device, hung, and was killed by a systemd start timeout. Replace DEVICESCAN in /etc/smartd.conf with explicit lines for the data disks only, each with -d sat.

How much RAM does ZFS need on a home NAS?

Plan for 8 GB as a workable floor for a four-disk pool without dedup. Cap the ARC with zfs_arc_max so it cannot starve other services. This box caps it at 3 GiB of 8 GB, which leaves room for Docker and Samba. Dedup is the setting that breaks small-RAM boxes, so leave it off.


Share this post on:

Send a Webmention

Written about this post on your own site? Send a webmention and it'll show up above once verified.


Next Post
LLMs on Intel Arc: SYCL vs Vulkan

Discussion

Powered by Garrul . Sign in with GitHub or Google, or post anonymously.

Related Posts