To Home Page
NAS - using a thin client and a USB hard drive
Last modifications: 24 May 2021
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 customised 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 a "standard" GNU/Linux distribution.
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 enough disk space for all your data. 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?
You could use a normal PC as a NAS. But the energy consumption of a PC is quite high and I find that undesirable for a device that is running day and night. Two other things I do not like about the PC option are 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 powerful. Thin clients do not have an internal hard drive but USB hard drives can easily be connected.
The hardware I use
So I needed a thin client and a USB hard drive. I found the following hardware for my NAS device:
- Thin client: HP t610 (second hand)
- USB hard drive: Samsung T5 SSD (500 GB)
Here some specifications of the HP t610:
- AMD Dual-Core 1.65 GHz processor
- 1.4 GB RAM
- 13 GB flash
- 4x USB 2.0 and 2x USB 3.0 ports
- Ethernet 10/100/1000 Mb/s (RJ-45)
These specifications are more than sufficient for the things I want to do with my NAS.
The hard drive I chose is a Solid State Drive, the Samsung T5. This SSD gets its power via USB, so no external power supply is needed. It is energy efficient and fast (USB 3.1). Nowadays many affordable USB hard drives are available.
Before you can install GNU/Linux on your thin client, you have to do some preparations first.
Hooking up the thin client
Connect a monitor and keyboard to your thin client. Monitor and keyboard will only be used during installation. Furthermore you need to connect your thin client to the internet and of course to a power supply...
Iso images of GNU/Linux installers can be found online. I chose to use the Debian network installation.
Making a bootable USB stick
The most convenient way to install GNU/Linux is from a USB stick (if you want to install from disc, you need to connect an external CD/DVD player to your thin client). To make a bootable USB stick, you can not just copy an iso image to it. You need a special tool to do it.
How to put an iso image on a USB stick (GUI)
If you use GNU/Linux you may already have a tool that can write an iso image to a USB stick. For example:
- Startup Disk Creator (Ubuntu)
- USB Image Writer (Linux Mint)
Or you can use UNetbootin or Etcher (both run on Windows, macOS en GNU/Linux).
How to put an iso image on a USB stick (command line)
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 has to boot from the USB stick. You can set this in the boot menu. If a boot menu is not available, you have to change the boot order in the BIOS.
I installed Debian GNU/Linux on the internal flash drive of the thin client. On a NAS device you do not need a graphical desktop environment, so I only installed the standard system utilities. In my setup, the complete system (OS and applications) uses about 4 GB hard disk space.
If the flash drive of your thin client is not big enough, you can install the operating system on the external USB hard drive. Or you can install it on a second USB hard drive or USB stick (if you prefer to have a separate system disk).
In a desktop environment you can easily mount and access an external hard drive with a mouse click. On a server it is convenient to mount the external hard drive automatically.
Note: If you installed GNU/Linux on the external hard drive, the drive will already be mounted automatically. So in this case you can skip the how-to below.
How to auto mount an external hard drive
First find out the UUID of the partition (or partitions) on your external hard drive. You need this UUID to mount the hard drive via fstab.
Open a terminal, log in as root and type:
This command will show the UUIDs of all the partitions on all the hard drives. Identify the UUID of the partition you need to mount an add the following line to the file /etc/fstab:
UUID=uuid-of-drive-partition /mount/directory ext4 noauto,x-systemd.automount 0 2
The option x-systemd.automount ensures that the hard disk will be automatically mounted when it is accessed. You could use the option auto (instead of noauto,x-systemd.automount), but then your NAS will not boot when mounting goes wrong, for example if the hard drive is not connected.
After saving the file fstab, reboot your NAS.
Now that your NAS is up and running, it is time to enable remote access from another computer.
Access with SSH
The first thing to install is the OpenSSH server. After installation, check if you can log on to your NAS from a remote terminal using SSH. If this works fine, you can remove the monitor and the keyboard. From now on, you will have to control your headless NAS via a terminal on another computer.
Access with a file manager
To access your NAS using a file manager on a remote GNU/Linux computer, install the OpenSSH SFTP server. If you want to access your NAS with a Windows computer using the Windows file manager, install Samba.
My complete music collection is stored on my NAS. The music can be streamed to other computers, all playing in sync. A multi-room audio system makes this possible.
Read more about my other project: Multi-room audio player.
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 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).
Transmission is a nice torrent 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 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.
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). 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.
It can be very practical to have world wide access to your data. So put your NAS in the cloud! Here three ideas using the Apache web server.
World wide access (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 a specific directory. This directory is accessible using the WebDAV protocol (supported by Apache and other web servers).
A WebDAV client is needed to access the directory share. You may use a special WebDAV client application or a file manager with built in support for WebDAV.
A public accessible directory in your web server setup can serve as a place to share large files with others. Just like with WeTransfer, you only send a link to the recipient, not the data itself. I call it MeTransfer. Very handy!
Spinning down a hard drive may improve its lifetime. Although my internal flash drive and external SDD can not be spun down, the number of writes can be reduced. The term "spinning down" will be used here to indicate the reduction of disk writes, in general.
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.
Problems with readahead
In laptop mode 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.
When I started my NAS project I had no idea what the result would be...
In December 2011 I started with my NAS project, using a single core thin client and an external "old fashion" hard drive. Although this set up only had USB 2.0 and a 100 Mb/s network connection, it worked very well.
Speed was not sublime, but is was enough. For example, watching video from my first NAS worked smoothly, without hick-ups. It has been running day and night for about 8 years without any problem.
In January 2020 I decided to speed up things, implementing the set up as described on this page. With a dual core processor, an SSD via USB 3.0 and a 1 Gb/s network connection, this new set up is really fast and ready for the future!