Post

My NAS - Part 3

USB Support, Samba, NFS, HD-Idle, RAID and CryptSetup

My NAS - Part 3

This page was updated to reflect that I’m running OpenWRT 25.12.5, not 24.10.8.


USB device support

OpenWRT doesn’t come with all the USB device support built-in, so let’s go ahead and install it on our router!

1
apk add kmod-usb-storage kmod-usb-ohci kmod-usb-uhci kmod-usb2 kmod-usb3 usb-modeswitch kmod-usb-storage-uas

Let’s install filesystem kernel modules and tools to support EXT4, NTFS, EXFAT, and VFAT filesystems. This also enables the System -> Mount Points options within LUCI. We’ll also install some useful utilities to deal with USB storage devices, as well.

1
apk add block-mount kmod-fs-vfat kmod-fs-ext4 kmod-fs-exfat kmod-fs-ntfs3 ntfs-3g ntfs-3g-utils blkid e2fsprogs fdisk usbutils mount-utils

Samba Support

Let’s install SAMBA support. Samba is free, open-source software program that lets non-Windows computers (like Linux or Mac) share files and printers with Windows systems. Doing this enables the System -> Network Shares menu within LUCI.

1
apk add luci-app-samba4

I’m altering the SAMBA configuration so that it binds to all addresses instead of interfaces.

1
sed -i "s|bind interfaces only = yes|bind interfaces only = no|" /etc/samba/smb.conf.template

Next, let’s configure the SAMBA server. We’ve mounted our partition in the /mnt/hdd directory, so we will share that directory via SAMBA.

1
2
3
4
5
6
7
8
9
10
mkdir -p /mnt/hdd
uci -q delete samba4.hdd
uci set samba4.hdd='sambashare'
uci set samba4.hdd.name='hdd'
uci set samba4.hdd.path='/mnt/hdd'
uci set samba4.hdd.read_only='no'
uci set samba4.hdd.force_root='1'
uci set samba4.hdd.guest_ok='yes'
uci set samba4.hdd.create_mask='0666'
uci set samba4.hdd.dir_mask='0777'

Lastly, let’s commit the changes and restart our SAMBA server.

1
2
uci commit
service samba4 restart

Network File System (NFS)

Let’s install NFS support on our router. NFS is my protocol of choice to share files over an internal Local Area Network. It shows soft links better and/or more accurately than SAMBA, so for some purposes, it is more desirable to use NFS instead of SAMBA shares.

1
apk add nfs-kernel-server nfs-kernel-server-utils

I’m going to define a NFS share. These are restricted to the main LAN network (all devices on the 192.168.20.0/24 subnet). Devices outside this subnet cannot access these shares!

1
echo '/mnt/hdd 192.168.20.0/24(rw,all_squash,insecure,no_subtree_check,fsid=0)' >> /etc/exports

Finally, we’ll restart the service:

1
service nfsd restart

Hard Drive Idle

We don’t want our drives constantly spinning when they aren’t in use for a while. They need to be spun down when not in use to minimize wear and tear on the drive. So let’s install the packages:

1
apk add luci-app-hd-idle

We need to rename the first section of the configuration file:

1
uci rename hd-idle.@hd-idle[0]=sda

We also need to add another section to the configuration file, enabling both sections:

1
2
3
4
5
6
7
uci set hd-idle.sda.enabled='1'

uci set hd-idle.sdb=hd-idle
uci set hd-idle.sdb.disk='sdb'
uci set hd-idle.sdb.enabled='1'
uci set hd-idle.sdb.idle_time_unit='minutes'
uci set hd-idle.sdb.idle_time_interval='10'

We need to commit the changes and restart the service:

1
2
uci commit
service hd-idle restart

Setting up RAID 1 (Mirrored)

If you’re not going to set up a RAID array, then skip this part. We are going to set up RAID 1 and LUKS encryption on this NAS. Let’s start by installing RAID utilities:

1
apk add mdadm

This step will WIPE EXISTING DRIVES IN YOUR RAID if not done correctly! You must change the RAID devices/partitions if they differ! I am not responsible for data loss!

Let’s set up our RAID 1 (Mirror) from two connected drives, then save the RAID details to the local software configuration file so OpenWrt remembers the array across reboots:

1
2
3
4
5
6
mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1

uci set mdadm.@array[0].uuid="$(mdadm --detail --scan | grep -oe UUID=.*)"
uci add_list mdadm.@array[0].devices="/dev/sda1"
uci add_list mdadm.@array[0].devices="/dev/sdb1"
uci commit

LUKS Encryption Packages

Let’s install LUKS encryption packages now:

1
apk add cryptsetup kmod-crypto-ecb kmod-crypto-xts kmod-crypto-seqiv kmod-crypto-misc kmod-crypto-user

Let’s install Clevis, plus a LuCI app to handle it:

1
apk add luci-app-clevis

This gives us a UI for configuring clevis, as well as viewing the status of our LUKS partitions. The current version as of this writing is 21-r8, but more features are being looked into… /assets/img/nas/clevis.webp


Summary

Our NAS now has USB support for external hard drives, SAMBA support to enables file and printer sharing between different operating systems, and NFS support for allowing users to access files over a network as if they were on their local machines. Our NAS also will spin down the hard drives after a specified period of time.

Additional Information

This post is licensed under CC BY 4.0 by the author.

Trending Tags