NAS
I am no longer use Ubuntu for my NAS therefore this document will likely not be updated anymore.
Packages
- 
Add Fish PPA
sudo apt-add-repository ppa:fish-shell/release-3 - 
Install Packages
sudo apt install -y apt-transport-https ca-certificates containernetworking-plugins curl ffmpeg figlet fish fzf gettext git htop ifenslave iputils-ping net-tools lolcat mailutils msmtp msmtp-mta nano neofetch ntpdate podman psmisc rclone software-properties-common tmux tree uidmap unzip zfs-zed zfsutils-linux dmraid gdisk hdparm lvm2 nfs-common nfs-kernel-server nvme-cli open-iscsi samba samba-vfs-modules smartmontools socat 
Networking
- 
Add or replace file
/etc/netplan/00-installer-config.yamlnetwork: version: 2 ethernets: enp6s0f0: dhcp4: yes mtu: 9000 enp6s0f1: dhcp4: yes mtu: 9000 
ZFS
Mirrored Zpool
- 
Create initial pool and set configuration
sudo zpool create -o ashift=12 -f eros mirror \ /dev/disk/by-id/scsi-SATA_WDC_WD120EDGZ-11_9LHWA5KG \ /dev/disk/by-id/scsi-SATA_WDC_WD120EMFZ-11_9MG0AHZA sudo zfs set atime=off eros sudo zfs set compression=lz4 eros - 
Attach more mirrors
sudo zpool add eros mirror \ /dev/disk/by-id/scsi-SATA_ST12000VN0007-2G_ZCH0F1CH \ /dev/disk/by-id/scsi-SATA_WDC_WD120EMFZ-11_X1G3B01L - 
Add spares
sudo zpool add -f eros spare \ /dev/disk/by-id/scsi-SATA_WDC_WD120EMFZ-11_QGGETR5T 
Datasets
- 
Create datasets
sudo zfs create eros/Media sudo zfs create eros/Minio - 
Share dataset over NFS
sudo zfs set \ sharenfs="no_subtree_check,all_squash,anonuid=568,anongid=100,rw=@192.168.42.0/24,rw=@192.168.1.0/24,ro=192.168.150.21,ro=192.168.150.28" \ eros/Media sudo zfs set \ sharenfs="no_subtree_check,all_squash,anonuid=568,anongid=100,rw=@192.168.42.0/24,rw=@192.168.1.0/24" \ eros/Minio - 
Dataset Permissions
sudo chmod 770 /eros/Media sudo chown -R devin:users /eros/Media 
Snapshots
- 
Install zrepl by following these instructions.
 - 
Add or replace the file
/etc/zrepl/zrepl.ymlglobal: logging: - type: syslog format: human level: warn monitoring: - type: prometheus listen: :9811 listen_freebind: true jobs: - name: daily type: snap filesystems: "eros<": true snapshotting: type: cron cron: "0 3 * * *" prefix: zrepl_daily_ timestamp_format: dense pruning: keep: - type: last_n count: 7 regex: "^zrepl_daily_.*$" - 
Start and enable zrepl
sudo systemctl enable --now zrepl.service - 
Give a local user access to a specific datasets snapshots
sudo zfs allow -u jeff send,snapshot,hold eros/Media 
NFS
Force NFS 4 and update threads
- 
Add or replace file
/etc/nfs.conf.d/local.conf[nfsd] vers2 = n vers3 = n threads = 16 [mountd] manage-gids = 1 
Non ZFS NFS Shares
- 
Add or replace file
/etc/exports.d/local.exports/share/PVCs 192.168.1.0/24(sec=sys,rw,no_subtree_check,all_squash,anonuid=568,anongid=100) /share/PVCs 192.168.42.0/24(sec=sys,rw,no_subtree_check,all_squash,anonuid=568,anongid=100) - 
Dataset Permissions
sudo chmod 770 /share/PVCs sudo chown -R devin:users /share/PVCs - 
Reload exports
sudo exportfs -arv 
Time Machine
- 
Install required tools
sudo apt install samba samba-vfs-modules - 
Create ZFS datasets and update permissions
sudo zfs create eros/TimeMachine sudo zfs create eros/TimeMachine/devin sudo zfs create eros/TimeMachine/louie sudo chown -R devin:users /eros/TimeMachine sudo chmod -R 770 /eros/TimeMachine - 
Set a smb password for user
sudo smbpasswd -a devin - 
Add or replace file
/etc/samba/smb.conf[global] min protocol = SMB2 ea support = yes vfs objects = fruit streams_xattr fruit:aapl = yes fruit:metadata = stream fruit:model = MacSamba fruit:posix_rename = yes fruit:veto_appledouble = no fruit:nfs_aces = no fruit:wipe_intentionally_left_blank_rfork = yes fruit:delete_empty_adfiles = yes spotlight = no [devin] comment = Devin's Time Machine fruit:time machine = yes fruit:time machine max size = 1050G path = /eros/TimeMachine/devin browseable = yes write list = devin create mask = 0600 directory mask = 0700 case sensitive = true default case = lower preserve case = no short preserve case = no [louie] comment = Louie's Time Machine fruit:time machine = yes fruit:time machine max size = 1050G path = /eros/TimeMachine/louie browseable = yes write list = devin create mask = 0600 directory mask = 0700 case sensitive = true default case = lower preserve case = no short preserve case = no - 
Restart samba
sudo systemctl restart smbd.service - 
Set up Time Machine on MacOS
sudo tmutil setdestination -a smb://devin:${smbpasswd}@expanse.internal/devin 
System
- 
Disable apparmor
sudo systemctl stop apparmor sudo systemctl mask apparmor - 
Disable mitigations and apparmor in grub
sudo nano /etc/default/grub # GRUB_CMDLINE_LINUX="apparmor=0 mitigations=off" sudo update-grub sudo reboot - 
Disable swap
sudo swapoff -a sudo sed -i '/ swap / s/^/#/' /etc/fstab 
Notifications
- 
Add or replace file
/etc/aliasesmailer-daemon: postmaster@ postmaster: root@ nobody: root@ hostmaster: root@ usenet: root@ news: root@ webmaster: root@ www: root@ ftp: root@ abuse: root@ noc: root@ security: root@ root: devin@buhl.casa 
- 
Add or replace file
/etc/msmtprcdefaults auth off tls off tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile /var/log/msmtp account maddy host smtp-relay.turbo.ac port 25 from devin@buhl.casa tls_starttls off account default: maddy aliases /etc/aliases 
- 
Add or replace file
/etc/smartd.confDEVICESCAN -a -o on -S on -n standby,q -s (S/../.././02|L/../../6/03) -W 4,35,40 -m devin+alerts@buhl.casa 
- 
Add or replace file
/etc/zfs/zed.d/zed.rcZED_DEBUG_LOG="/var/log/zed.debug.log" ZED_EMAIL_ADDR="devin@buhl.casa" ZED_EMAIL_PROG="mail" ZED_EMAIL_OPTS="-s '@SUBJECT@' @ADDRESS@ -r devin+alerts@buhl.casa" ZED_NOTIFY_VERBOSE=1 ZED_NOTIFY_DATA=1 ZED_USE_ENCLOSURE_LEDS=1 
Misc
Replace a Drive
sudo zpool offline eros /dev/disk/by-id/scsi-SATA_ST12000VN0007-2G_ZCH0F1CH
sudo zpool replace eros /dev/disk/by-id/scsi-SATA_ST12000VN0007-2G_ZCH0F1CH /dev/disk/by-id/scsi-SATA_ST22000NM001E-3H_ZX201HJC
When resilvering is complete detach the drive...
sudo zpool detach eros /dev/disk/by-id/scsi-SATA_ST12000VN0007-2G_ZCH0F1CH
Badblocks
This command is very destructive and should only be used to check for bad sectors, this also take ashile so be sure to start it in a screen
sudo badblocks -b 4096 -wsv /dev/disk/by-id/scsi-SATA_ST12000VN0007-2G_ZJV01MC5
Shred
This command is very destructive and should only be used to completely wipe the drive, this also take ashile so be sure to start it in a screen
sudo shred -vfz -n 4 /dev/disk/by-id/scsi-SATA_ST12000VN0007-2G_ZJV01MC5
Lenovo SA120
Due to the loudness of the fans, they can be adjusted by using AndrewX192/lenovo-sa120-fanspeed-utility.