To Home Page
NAS device using a thin client and a USB hard drive
Last modifications: 29 August 2017
Network attached storage (NAS) is data storage connected to a network, providing data access to a all the computers in this network. A NAS device actually is a computer as well but without monitor, keyboard and mouse. It operates as a file server and normally runs 24/7. The image below shows how a NAS device and multiple computers are connected to a home network (LAN).
With NAS there is no need to have copies of the same files on different computers. At home for example, everybody can view the same holiday pictures stored on the NAS device, using their own computer. Most NAS devices can do more, for example function as a music player or a print server. With a print server, every computer at home can print to the printer connected to the NAS device.
Many NAS home consumer devices run a customized version of GNU/Linux. That may sound great if you are a GNU/Linux fan (like me) but...
- Controlling the device is often limited to some configurable preferences.
- Usually it is not possible to run programs other than the preinstalled ones.
- Connecting to a NAS device using SSH or Telnet is not always possible.
- If it is, chances are you can not use all the shell commands you are used to.
It made me think: why not install the GNU/Linux flavour I want, install the software I want and configure the NAS device the way I want?
Unfortunately most NAS devices do not allow the installation of other operating systems or can not run my favorite GNU/Linux distribution (Debian) because of performance issues.
So I decided to make my own NAS. Just to be in control. Just for fun. And during this project I learned some more about GNU/Linux as well.
To make your own NAS, you need a computer with a network adapter and some free disk space. Of course you also need an operating system and programs to run on it. But first let's focus on the hardware.
Why using a thin client?
I could have used that old Pentium PC that was only collecting dust. But the energy consumption of a PC is quite high (70 W in my case) and I found that undesirable for a device that would be running day and night. Two other things I did not like about the PC option where noise and size.
Computers that do not have these disadvantages are thin clients. They are small, do not make any noise (no fans) and energy consumption is low. Yet they can be very powerfull. Thin clients do not have an internal hard drive but USB hard drives can easily be connected.
My hardware requirements
So I needed a thin client and a USB hard drive. First I made a small list of requirements for this hardware:
- CPU speed: 1 GHz or more
- RAM size: 128 MB or more
- USB speed: 480 Mb/s (USB 2.0)
- Ethernet speed: 100 Mb/s
- Hard drive size: enough for all of my data...
These requirements are based on the system requirements for the GNU/Linux distribution of my choice (Debian) and some of my own ideas about performance.
The hardware I use
I found the following hardware for my NAS device:
- Thin client: VXL Itona TC4331
- USB hard drive: Packard Bell Go
To save money I bought the thin client second hand. The Itona TC4331 met my requirements well. Here some specifications:
- VIA C7 1 GHz processor (x86 architecture)
- 32 MB flash
- 256 MB DDR 2 RAM
- 4 USB 2.0 ports
- Ethernet 10/100 Mb/s (RJ-45)
The hard drive I chose is a power saving 2.5-inch drive, the Packard Bell Go. This hard drive gets its power via USB, so no external power supply is needed. Nowadays many affordable USB hard drives are available.
Before I could install Debian on my thin client, I had to do some preparations first.
Hooking up the thin client
The installation of a (new) operating system on a headless server like a NAS device - no monitor, keyboard and mouse - can be stricky. To make things easier, I connected a monitor and a keyboard to my thin client for use during installation.
I wanted to do a Debian network installation: a minimum base system is installed from a minimal installer and the rest is installed via Internet. Therefore the thin client had to be connected to the Internet.
Preparing install from USB stick
Normally Debian is installed from one or more installation CDs or DVDs. But the Itona thin client does not have a CD-ROM drive and I did not have an external one. So I had to install Debian from a USB memory stick.
Fortunately putting the Debian installer on a USB stick is very easy if you have a GNU/Linux computer.
How to put the Debian network installer on a USB stick
Note: be sure to use the right drive letter X, otherwise you may lose data or lose your complete operating system!
Booting from USB stick
In order to run the installer, the thin client had to boot from the USB stick. This can be set in the BIOS.
The Itona thin client has a standard Phoenix Award BIOS. To enter the BIOS setup you hit the DEL key on power-up. The BIOS of my Itona thin client appeared to be password protected. On the internet I found out that the standard password is "drupad".
The idea was to install Debian GNU/Linux (version Wheezy) on the USB hard drive connected to the thin client. Installation on the internal flash drive of the thin client was not an option because of its small size (32 MB).
On a NAS device you do not need a graphical desktop environment, so I only installed the standard system utilities.
Installation went well, except for the very last part. At the end of a Debian installation, the GRUB boot loader is installed. I chose to install GRUB on the first hard drive (the default). This went wrong because the first hard drive of the Itona thin client is the internal flash drive and the drive turned out to be read-only.
I ended up with a thin client that did not boot because of a missing boot loader. So I had to install GRUB "manually".
How to install GRUB manually with Debian
- Boot from the medium containing the Debian installer
- Choose Advanced options from the installer menu
- Choose Rescue mode
- Enter the information needed by the installer
(this info is only needed to run in rescue mode - nothing will be installed)
- Choose the partition to be used as the root file system - this should be the partition where you installed Debian
- Choose Reinstall GRUB boot loader
- Follow the instructions of the installer
The USB hard drive I use, has a built in time out feature that spins down the disk when there has been no disk access for about 3 minutes. But my disk kept spinning continously.
I found out that some processes are writing to disk quite often:
How to monitor disk activity
- Install the Debian package iotop
- Open a terminal and log in as root
- Start iotop by typing:
# iotop -o -qqq -t
With the options above, iotop will show the names of processes at the moment they write to disk, including a timestamp.
Using laptop mode
From the Debian website: laptop mode is a Linux kernel feature that allows your laptop to save considerable power, by allowing the hard drive to spin down for longer periods of time. This feature is also suitable for spinning down the hard disks of a server (read the note below). If you want to use laptop mode, you need to install the package Laptop Mode Tools.
How to spin down your disk using laptop mode
Edit the configuration file and set the values of the parameters below. In Debian the location and name of this file is /etc/laptop-mode/laptop-mode.conf.
MAX_LOST_WORK is the maximum time, in seconds, of work that you are prepared to lose when your system crashes or power runs out. This is the maximum time that Laptop Mode will keep unsaved data waiting in memory before spinning up your hard drive.
Note: Spinning down too many times may kill hard drives! Read more on the Laptop Mode Tools website.
The HD_IDLE_TIMEOUT parameter is ignored by my Packard Bell hard drive. The drive uses its own built in time out feature, which is fine for me.
Solving the problem with nmbd
For some reason nmbd (a part of Samba) kept writing to disk to often, even in laptop mode. After a long search on the internet I found a solution for this problem: mount the directories nmbd writes to, as RAM disk. Then nmbd wil write to RAM in stead of the hard disk. Note that the information in RAM will be lost after a reboot but this seems to be no problem.
How to prevent nmbd from writing to disk
Add the blue lines below to the Samba startup script. In Debian the location and name of this script is /etc/init.d/samba.
case "$1" in
log_daemon_msg "Starting Samba daemons"
# Prevent frequent writes to disk
# Use tmpfs (ram disk)
mount -t tmpfs tmpfs /var/run/samba
mount -t tmpfs tmpfs /var/cache/samba
# Unmount tmpfs (ram disk)
In laptop mode (see previous section) readahead is enabled by default. Reading ahead means that whenever some data is read from disk, the data which is most likely to be accessed next is read as well, ahead of time.
In my case readahead caused two problems:
- Video played from my NAS was distorted for a short while at certain moments (I think at the moments a new readahead was done).
- My NAS responded slowly to simple terminal commands like "ls" (I think readahead reads more than only the command executable you need).
Disabling readahead solved these problems.
How to disable readahead
Edit the configuration file of Laptop Mode Tools and set the value of the CONTROL_READAHEAD parameter to 0. In Debian the location and name of this file is /etc/laptop-mode/laptop-mode.conf.
Some of the software I run on my NAS device:
My printer is connected to my NAS, so I can print from any computer in my home network. To install and manage printers I use the CUPS web interface. By default you can use this web interface only on the computer where CUPS is installed (via: http://localhost:631). But it is possible to enable remote access to CUPS.
How to enable remote printer administration
On your NAS/server edit the CUPS configuration file: change the red line, add the blue lines. In Debian the location and name of this file is /etc/cups/cupsd.conf.
# Only listen for connections from the local machine.
Port 631 # was: Listen localhost:631
# Web interface setting...
# Restrict access to the server...
# Restrict access to the admin pages...
# Restrict access to configuration files...
Require user @SYSTEM
After restarting CUPS (on Debian: /etc/init.d/cups restart) you can open the web interface from any computer. Open a web browser and go to: http://server:631 (replace server with the name of your NAS/server).
Transmission is a nice BitTorrent client for downloading and sharing large files, like software, movies and music. But it took me some time to find out which parts to use on my NAS device.
How to use Transmission on a server
On your NAS/server you need transmission-daemon and possibly transmission-remote. In Debian Wheezy the packages to install are transmission-daemon and transmission-cli (which contains transmission-remote).
BitTorrent client designed for headless servers (servers without monitor, keyboard and mouse).
Command line tool for controlling the daemon (handy for scripting and scheduling).
To control the daemon from another computer you can use the web interface. Open a web browser and go to: http://server:9091 (replace server with the name of your NAS/server). Via the web interface you can for example add torrents and monitor your downloads.
When Transmission is up/downloading, this will slow down other internet traffic. Therefore on my NAS device Transmission is only active at night. I use transmission-remote and cron to schedule this.
Sometimes it is practical to have world wide access to your data. Here some ideas.
World wide access using Apache (read only)
Normally Apache is used to serve web pages over the Internet. I use Apache to serve the data on my NAS, so I can easily access my data world wide using a web browser (see the image below).
How to serve your data world wide using Apache
Before you decide to serve your data world wide, think about security. Normally you do not want others to have access to your data. So I configured Apache to use authentication and SSL. There are many websites that explain how you can do this.
After configuring Apache with the desired security (the hardest part) the rest is relatively simple:
To access your data start a web browser and go to: http(s)://router-ip-address/data. The router IP address is assigned by your Internet Service Provider. If your ISP provides a host name, you can use that instead (see the image above).
Write access to my NAS from the Internet is restricted to two specific directories (this restriction gives me some feeling of safety). One directory is accessible using FTP (on my NAS ProFTPD does the job). The other directory is accessible using the WebDAV protocol (supported by Apache and other web servers).
An FTP client and a WebDAV client are needed to access the directory shares. You may use a special client application or a file manager with built in support for FTP and WebDAV.
My complete music collection is stored on my NAS. So I can listen to my music on every computer connected to the home network.
Another possibility is playing the music on the NAS itself. To do this I run Music Player Daemon on my NAS. A client on another computer or a smart phone is used to control the daemon. Of course the audio output of the NAS must be connected to some kind of music installation, in order to hear the music playing!
Music Player Daemon (server)
All information about the Music Player Daemon (MPD) can be found on the MPD website. You can download the daemon from there or install it using your package manager.
How to configure MPD
On your NAS/server edit the MPD configuration file. In Debian the location and name of this file is /etc/mpd.conf. Only change the information below.
# Files and directories
# Audio Output
name "My ALSA Device"
After saving, restart MPD (on Debian: /etc/init.d/mpd restart) and you are ready to play your music. On the client side you need to configure the host (IP-address or name of your NAS/server), the port (default: 6600) and the audio output(s) you want to use (in the setup above there is only one).
To control MPD on my NAS from my PC or laptop, I use Gnome Music Player Client (GMPC). Below you can see a screen shot (click to enlarge). GMPC runs on Windows, Mac OsX and GNU/Linux (GMPC does not depend on Gnome anymore, although the name may suggest this).
On my Android phone I use MPDroid to play the music on my NAS. See the screen shots below (click to enlarge). You can install it from Google Play but as a free software lover I prefer to install it from F-Droid.
More MPD clients
More clients you can find on the MPD website.
When I started my NAS project I had no idea what the result would be...
But after my NAS device was up and running, it really worked well! Data transfer speed from and to my other computers is about 50 Mb/s (not superb but not bad either over a 100 Mb/s network). Watching video from my NAS device works without hickups.
Since December 2011 my NAS is running day and night without any problems.