<----- Back to Index

Simple NAS with Slackware Linux

Slackware Linux can be used for a simple Network Attached Storage - NAS (a.k.a. File Server), making something useful from a old machine that would've been dismissed for everyday use. The reasons to specifically use Slackware are:

  1. It's lightweight
  2. Still has support for 32bit machines
  3. Already comes with the necessary packages to set up Samba (no Internet required during the installation process)
  4. You might be able to learn more about Linux in the process

Index

  1. Hardware Required
    1. Networking
    2. Processors
    3. Drives
  2. Getting some Slack
    1. Installing
    2. First configurations
  3. Setting up a file share with Samba
  4. Conclusion

1. Hardware Required

When it comes to hardware, almost any machine can be used to host files in a local network, but there are some considerations to be taken before starting.

1.1. Networking

For instance, before talking about the machine itself, we need some other hardware to be able to connect the server in a offline LAN.

Firstly, we will need:

The hub/switch/router will be the device responsible for managing communication between the machines in a LAN. The hubs and switches are the cheapest to buy, and if you router does not belong to your ISP you can use the "yellow ports" to their switch functionality. The prices will differ dependind on the megabytes-per-second rate, most cheaper ones are around 100Mbps wich will be fine for most uses.

1.2. Processors

The computer used for hosting the server is up to you. In this guide I will show only the bare minimum to set up a simple server, so I will not get into things like R.A.I.D. (sorry!). Regarding the machine, here is the bare minimum to run Slackware:

Unfortunately Linux is slowly but surely dropping support for 32-bit in general, but at the time being it's still viable.

While this guide is focused on x86/x64, Slack is also avaliable on ARM, however some instructions might be different, please check the Slackware website for further info in this regard.

Power consumption wise you might want a machine with low power draw since it will be running 24/7. Some known recommendations are:

In my server I run a single-core Atom N270, in fact most Atoms are only useful for things like this...

1.3. Drives

You might have some old drive hanging around that might be useful for storage. Please keep in mind that one day your drive will fail, so learn to manage your files and avoid data loss, usually the best pratice is to make the 1-2-3 method; keep at least 3 copies of a file in separated drives in order that if one fail, you still have two other copies.

One recommendation is to install the system in one small drive and keep the bigger disks only with files, this way if the system or machine breaks you can more easily move your data to somewhere else.

Test your disks with tools like CrystalDiskInfo to see if your drive has bad sectors; one bad sector is already a indicator that the drive is prone to fail at anytime.

2. Getting some Slack

Slackware can be downloaded from the project's website. The 32-bit and 64-bit versions have a small difference in the installing process, but are very similar.

2.1 Installing Slackware

Going from the start. Slack boots into a CLI, the first thing to do is to partition the disk; I usually install the system first in a small disk, then add other drives to the server after the installation process.

Since this process is already well documented, check this page for the install instructions

When you get to the part of selecting the package sets to install, remember that for a server we will need:

Continue following the other instructions and always go for the option labeled as "recommended" or "safest".

Now for the Networking; in this guide I will be using the NetworkManager way to set up a wireless network, this can be useful to update the system from time to time, we can set up a static IP adress later, but you can also set a static IP address here if you don't plan to connect the machine to the Internet.

Read the guide linked above, and go back here when you can boot into the system itself.

2.2. First configurations

After creating a regular user, boot into Fluxbox by using the command startx if you already configured it as your main interface via xwmconfig, the first thing to do after a fresh install is to update the system and set the static IP adress to the server, the last will be done via the Ethernet port (most likely to be eth0 in your machine. Here you have two options regarding updates:

  1. Using a separate Wireless device (USB Wireless adapter, Wireless Card, etc.) that only will be active during the update process
  2. Creating two configurations for your Wired Connection - one as a static IP and another to be used with DHCP for internet access

For example, in my case I use the built-in Wireless adapter for updates, but I only keep it active during the update process, turning Wi-fi access off again after the process is done. This is easier to do via a GUI, so that's why we installed X11, the simplest solution is using Fluxbox and nm-applet to enable and disable the network via the tray icon.

Since this guide is aimed at less experienced users, we will commit the horrible sin of setting this up via GUI.

When first starting Fluxbox, open a terminal with the right-click and type nm-applet &, this will make a icon appear in the system tray on the bottom left corner, there you can connect via Wi-fi or Wired connection, doing the update process:

  1. Select a mirror from /etc/slackpkg/mirrors
  2. Uncomment one mirror from the list
#~ slackpkg update gpg
#~ slackpkg update
#~ slackpkg upgrade-all

After that, it is important to set up a simple firewall to limit the access from both SSH and Samba. The following configuration is taken and edited from here.

Create a text file containing the follow script named rc.firewall:

#!/bin/bash

# Place the IP adresses that are allowed to access the device at the start of the script.
iptables -A INPUT -s [IP_ADDRESS] -j ACCEPT

# These two rules set the default policies, i.e. what to do if a
# packet doesn't match any other rule, to drop any packet coming
# into (INPUT) or routing through (FORWARD) the box.

iptables -P INPUT DROP

iptables -P FORWARD DROP

# These rules are added (-A) to the INPUT chain. They allow packets
# from any previously established connections and accept anything
# from the loopback interface.

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -i lo -j ACCEPT
# Below rule is needed ONLY if you want to have ssh connections.
# Comment this line if you do NOT want to use ssh connections.
# This rule added to the INPUT chain accepts any ssh connections.
# Change ethx to reflect your network setup, i.e. use the name
# of the device that connects to the Internet (e.g. eth0).

iptables -A INPUT -p tcp --dport 22 -i eth0 -j ACCEPT
  1. Make this file into a script. -> script rc.firewall
  2. Grant this file the necessary execution permissions. -> chmod 755 rc.firewall
  3. Move the script into the /etc/rc.d directory (this will make is start every boot). -> mv rc.firewall /etc/rc.d

Now for the static IP address: right-click on the network icon on the tray and go to Edit Connections... -> Wired -> IPv4. There you can set two parameters:

This need to be done also to the machines that will be connecting to the server (as we setted in the firewall configuration), for example, you can use the built-in network port for usual connection to the Internet and a separated network card to access the server, or using Wi-fi for Internet and the Ethernet port to access the server.

3. Setting up a file share with Samba

Now it is the time to install the disks to be used in the server. In short, the process is to:

  1. Identify the disk name in /dev/
  2. Mount the drive in a folder
  3. Set the folder as a shared folder in the Samba config file
  4. Make the mount permanent using fstab

By default any connected device will be located in /dev/, you can see the devices connected using lsblk in the terminal, usually the main disk is labeled sda, and the following are labeled with the following letters (sdb, sdc, etc.).

We can mount a drive in a folder on the /home/ directory to access it more easily, first create a directory there:

mkdir [DIRECTORY_NAME]

And then mount the device in the new directory:

mount -t [FILESYSTEM TYPE] [DEVICE] [DIRECTORY]

Now we can configure Samba. The location for the configuration file is in /etc/samba/smb.conf, if the file does not exist, create it before editing via the touch command. A simple Samba configuration looks like this:

[global]
workgroup = WORKGROUP
server string = Samba server
server role = standalone server
valid users = [USERNAME]

[Public]
comment = Public folder
browseable = yes
valid users = [USERNAME]
path = /home/[USERNAME]/Public
writable = yes

[readonlyshare]
path = /home/[USERNAME]/Public
valid users = [USERNAME]
read only = yes
browsable = yes

If you want the main user to have read-write access and others read-only, you can use the options above to specify the same shared folder with different options per user.

Before enabling the Samba service, we need to add a user to access the share, use the same names for the smb.conf: file.

~# adduser [USERNAME]
~# smbpasswd -a [USERNAME]

Now as root we can change the permissions in order to the service to start:

~# chmod +x /etc/rc.d/rc.samba
~# /etc/rc.d/rc.samba

With SSH and Samba set on the server and a static IP address set on another machine, both connected via Ethernet and a network switch, we can finally set connection to the shared folder. This process can differ regarding Windows, Unix-likes and ChromeOS but in resume you need to make a connection to a address structured as: smb://[IP_ADDRESS]/[FOLDER_NAME] using the File Manager.

This, in short, is the process to turn Slackware Linux into a simple file server.

4. Conclusion

[insert a cool and relatable call-to-action text about self-hosting here] (°-°)


^ Back to top