Post

My NAS - Part 3

USB Support, Samba, NFS, and HD-Idle

My NAS - Part 3

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
opkg install 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
opkg install 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
opkg install 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
opkg install 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!

The first command DESTROYS the existing contents of the file! You’ve been warned!

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
opkg install luci-app-hdidle

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

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