How to set up a debian based NAS
A few days ago I decided to replace my old XMBC based media and file-server with a file-server only solution. Because of various video on demand platforms like Netflix and so on, I haven’t used my XBMC for like a year. Also the underlying Xubuntu installation didn’t get updates anymore. So let’s try something new, I thought. Unfortunately my attempt to use FreeNAS without erasing all my disks wasn’t successful. So I will use my previous solution based on a regular linux installation again and install all services by myself. But this time I will use Debian instead of Xubuntu, because I don’t need a GUI. This blogpost should be some kind of how-to in case I have to do the whole setup process again;)
Let’s start.
Hardware
- AMD E350 CPU
- 4GB DDR3 Ram
- 64GB SSD Drive
- 2x 1TB Western Digital HDD
- 1x 250 GB Toshiba HDD from my old Macbook Pro
Goals
- Access files via SMB from OSX and Windows (Every Disk should be a separate SMB share)
- Use an external USB harddrive connected to the Server for TimeMachine purposes. Last time I had a Apple Filing Protocol (AFP) share for this. But since OSX supports SMB shares for TimeMachine I will try SMB this time
- Spindown of HDDs after a while, because the server is located in my living room
- Boot up the server via wake-on lan
The Setup
Download and Install Debian
First of all I download a fresh version of Debian from and install it on the 64GB Flash drive. I use the minimal version of Debian 8. The installation process is not that hard, so I won’t describe it here.
- During the installation I make sure that the SSH Server gets installed, so I can access my server via SSH later
Disk Setup
Set mountpoints for disks
I will mount my disks by their UUID. In order to get the UUID I use the command blkid -o list
which gives me a nice output of all my disks, their filsystem and their UUID.
device fs_type label mount point UUID
--------------------------------------------------------
/dev/sdc1 ext4 (not mounted) 9ebc10d7-261a-4a73-88d3-eab4d4ac05f1
/dev/sdd1 ext4 (not mounted) 52fbbff2-3e27-4e24-8fed-cc9ea652c8c5
After that I have to define the mountpoints in the /etc/fstab
file. If it does not exist I create it with sudo touch /etc/fstab
A mount should look like this:
<file system> <mount point> <type> <option> <dump> <pass>
You can get more information about this schema and possible options at https://wiki.debian.org/fstab.
As <file system>
I will use the UUID I got from the blkid
output. For the <type>
parameter I will use the value of the fs_type
parameter. <dump>
and <pass>
are both set to 0.
There are some entries in the fstab file generated by the system for mounting the system disk. Don’t remove them! Every additional disk is defined in a separate row. So the fstab file should look like this:
# First storage disk
UUID=9ebc10d7-261a-4a73-88d3-eab4d4ac05f1 /media/STORAGE1 ext4 defaults 0 0
# Second storage disk
UUID=52fbbff2-3e27-4e24-8fed-cc9ea652c8c5 /media/STORAGE2 ext4 defaults 0 0
The first disk will be mounted to /media/STORAGE1
and the second disk to /media/STORAGE2
. For other disks it is the same procedure.
Automatically mount USB Drives
For backup purposes I have a USB HDD that I only turn on, when I want to perform a backup. So I’ll need a way to automatically mount this drive when it becomes available. After testing several approaches to achieve this I came across the usbmount
package.
You can install it via apt-get
sudo apt-get install usbmount
After that it should work. I struggled a little bit with the fact that I wanted the USB drive to be mounted at /media/TM. So I changed the MOUNTPOINTS parameter.
MOUNTPOINTS="/media/TM"
Unfortunately you can only automatically mount one drive at the same time and I will be mounted at /media/TM
. Since my backup HDD is the only USB drive I plan to attach to my NAS it’s okay for me.
For more information about automatically mount USB drives, see http://mein.homelinux.com/wiki/linux/mounten.
Setup SMB Share
First of all I have to install the samba
service from the package manager.
sudo apt-get install samba
After that I open the samba configuration file. You will need root privileges to make changes.
sudo vim /etc/samba/smb.conf
Every share is defined in the same way:
[Name]
path=/path/to/my/folder
public=yes|no
browseable=yes|no
writable=yes|no
So the setup to share my STORAGE1 disk looks like:
[STORAGE2]
path = /media/STORAGE2
public = no
browseable = yes
writeable = yes
I want only system users to be able to access the samba shares. So I uncomment or add the line security=user
to the smb.conf
To apply the latest changes to the smb.conf I restart the samba service.
sudo service smbd restart
Now I need to add my system-user to the samba user database.
sudo smbpasswd -a <myusername>
This will prompt me to add a new password for this user to access the samba shares. After setting the password the user is added successfully and should be able to access the samba shares I set up earlier.
Setup AFP Share
In order to use a disk for Time Machine backups it need to be shared via the AFP Protocol. For the support of AFP I will use the netatalk
package. Since this package is not available in apt-get, I have to download and compile it myself. I will use the instructions from: daniel-lange.com
Speed Up Server Boot
When the server starts a menu is shown where I can select the operating system to boot. Also there is a timeout of 5 seconds. In order to boot to the OS immediately, I set this timeout to 0.
To to so, I open the /etc/default/grub
file and change the property GRUB_TIMEOUT=5
to GRUB_TIMEOUT=0
.
Then, update the grub config with
sudo update-grub
HDD Spindown
In order to decrease the noise of my server I will use hdparm
to let the disks spin down after a few minutes of inactivity
Install hdparm
sudo apt-get install hdparm
After that there is a file named hdparm.conf
in the /etc
directory.
In this file I can set spindown times for every disk. To specify the disk I will use the UUID (see above). An entry for one disk will look like:
# STORAGE1
/dev/disk/by-uuid/9ebc10d7-261a-4a73-88d3-eab4d4ac05f1 {
spindown_time = 24
}
The numeric value is the time in seconds multiplied by 5 after the disk will spin down. So 24 means 120s -> 2min. I’ve noticed a strange behaviour of my WD Blue HDD, which didn’t spin down at all. After some hours of research I found a post where someone had luck with a value of 3, which spun the disk down after about 10 minutes. That’s okay for me.
Wake-On LAN
I don’t need the NAS to run all the time.
So my goal using Wake-On LAN is to start the NAS via an AppleScript that also mounts all shares.
In order to be able to wake the NAS I had to enable the wake-on option for my eth0 interface. I did this with adding one line to my /etc/network/interfaces
configuration.
iface eth0 inet dhcp
ethernet-wol g
Then reboot and check if the value is set correctly by using:
sudo ethtool eth0
It should show Wake-on g
. Now the NAS is ready to be woken up via LAN.
On the OSX side I downloaded a little command line tool called wolcmd. And wrote a little AppleScript that pings the NAS on a specific IP and wakes it up, if it isn’t already. The small application I have written is available at: https://github.com/EggiJan/shell-scripts/blob/master/wolmount.scpt
Note: This blog post was originally published on my old blog, which I unfortunately lost