Home Network NAS Construction Site: Level 2

Fresh fruit: The Raspberry Pi as a mini-NAS with extra freedom

After we found a quick introduction to the topic of network storage at Level 1 with a simple USB stick or an external hard drive at the FritzBox, we now take the next step: More freedom, more control, but still compact and energy-saving. Welcome to Level 2 – the Raspberry Pi as mini-NAS!

What's behind it?
A Raspberry Pi is a tiny, inexpensive single-board computer that is perfect as a power-saving home server. Especially models such as the Raspberry Pi 4 (or 5) with 2-8 GB RAM and Gigabit Ethernet are well suited for simple NAS tasks. If you connect a USB hard drive or SSD to it, you will have your own network storage in no time – similar to the FritzBox USB NAS, but with far more possibilities.

What is needed?
Raspberry Pi – in principle already possible from V1 – but it really only gets more powerful with V4 or V5 (preferably with 4 or better equal to 8 GB RAM)
USB hard drive or SSD (NTFS or ext4 formatted)
microSD card (16-32 GB) for the operating system (at least for V1 and V2) newer ones can also start directly from USB stick or USB SSD
Power supply for the Pi (at least 3A) – Attention, especially important, if the Raspi goes to his knees again and again, the cause is often the power supply!
Ethernet cable or Wi-Fi (Ethernet recommended)

In addition, it is helpful if you are not afraid to touch the command line, because some elements of the configuration require input of lines of code or commands, especially if you are planning a light installation without a graphical user interface. If you don't want to get involved here, just go straight to Level3.

Installation & Setup

Once the hardware is assembled – Raspberry Pi with microSD card, power supply and ideally SSD USB hard drive – we start with the software. The goal is for the Pi to act as a network storage that all devices in the home network can conveniently access. In addition, we interpret it in such a way that services such as Nextcloud, Pi-hole (also a great craft project in itself, e.g. in a Docker container) or a media server can be installed later without any problems.

First, you need an operating system for the Pi. The easiest way to do this is with the Raspberry Pi imager, which you can use free of charge for Windows, macOS and Linux You can download.

Launch the imager and select ‘Choose OS’ → ‘Raspberry Pi OS (32-bit)’ → ‘Raspberry Pi OS Lite’ or ‘Raspberry Pi OS with Desktop’ (if you want the graphical interface – the first choice for beginners). Now select your microSD card (or USB stick for newer ones) under ‘Choose Storage’. Optional: With ‘Settings’ (small gear), you can preset Wi-Fi access data, hostname and SSH directly. Now click on "Write" and wait until the imager is ready.
Newer Raspberries also start directly from connected USB sticks instead of the MicroSD cards or even directly from connected USB SSD or NvME.

Which Raspi What Exactly Can You Do at DrKlipper here Check it out.

We start here from the simplest case at the oldest Raspi V1 and work our way up from there. (There is still a normal SD card needed, the newer ones then set to microSD) The next step is to insert the newly created (micro)SD card, turn on Raspberry Pi, and then boot your Pi into the newly installed system! The SD card (or the USB stick) is basically so ready and the Raspi can be used, but from a connected SSD the whole system would run much more efficiently. So in the next step, we connect the SSD to the Raspberry Pi via a USB SATA cable or a HAT+ (for M.2 SSDs). If we want to clone an image from the SD card to the SSD, please make sure that the SSD is empty or important data is backed up. ⁇

There are now two ways. Very old systems can start V1 / V2 from the newly copied or directly cloned USB stick by imager, if you only use the file bootcode.bin copied to the SD card. Both MicroSD card and USB stick are then used permanently in the device.
Newer systems are different. (DrKlipper white notice)

Configuration and Services

Connect the Pi to a monitor and keyboard via HDMI or connect via SSH (standard user: pi, Password: Raspberry). Then run the configuration menu:

sudo raspi-config

Here you can set the following:

  • Change hostname (e.g. ‘MeinHeim, Beerchen, spassbremse’) Be creative! No? Then look here A few suggestions to.
  • Local settings such as language, keyboard and time zone
  • Activate SSH, if not already done in advance via the imager
  • Change user password (Important for system security!)
  • extensions Like I2C or SPI, you can ignore if you just want to run a NAS.

After completing the configuration, please restart:

sudo reboot

First set-up? Great, then we'll do next...
Exactly, updates!

Before setting up network storage, all packets should be updated. Thus, security gaps are closed and the latest improvements are installed.

sudo apt update
sudo apt full-upgrade -y

The first command searches for packages to be updated and creates a list internally, the second executes the updates directly and the -y option ensures that there is no extra demand whether you really want it.

Option: Cloning the SD card / USB sticks to the SSD.

We start the SD Card Copier (in the accessories menu of our Raspi). There we select the SD card as the source and the SSD as the destination and wait a while... the copy process can take some time, depending on the size and speed of the two media. After cloning, we still have to change the boot order for the Raspberry Pi to start from the SSD. 

Change boot order:

To do this, we execute the following command:

sudo raspi-config

We select "Advanced Options" > "Boot Order" and select "USB Boot" (or "NVMe Boot" for M.2 SSDs). Now we just have to restart the Raspberry Pi once and the system is already running from our fast disk. 

Insert USB hard drive

Connect your hard drive or SSD to a USB port on the Pi. Check with the command

lsblk

whether the hard disk is recognized, usually your new disk should be recognized as /dev/sda1 to be found. You can compare connected devices, for example, by the specified size. Then we create a mountpoint, i.e. a new directory in which we want to have the contents of the connected hard drive displayed.

sudo mkdir /mnt/data coffin

Now you can mount the hard disk manually (for ext4 as an example). This is called then mountpoint mapping Or to mount the mounts.

sudo mount /dev/sda1 /mnt/data coffin

In order for the mount to happen automatically when rebooting, you must include it in the file /etc/fstab enter. Otherwise, the hard drive is only integrated until the computer is restarted.

First, please find out the UUID number of the hard disk that goes like this:

blkid

Then open the fstab:

sudo nano /etc/fstab

And add a line, e.g.: (please provide the appropriate information, i.e. your UUID, which you have from your hard drive above, your mountpunt and also your file system)
Learn more about how fstab and mount work There is also here.

UUID=your-UUID /mnt/data coffin ext4 defaults,noatime 0 2

Now please save this change (either with key combination Ctrl+O and then key Y or with Ctrl+X and then key Y – With option O nano asks if you want to save and you still have to close the editor, with X you close the editor and he asks you if you still want to save).

With the command

sudo mount -a

You can then test whether everything is integrated correctly.

Disk shares for home network access are then usually done via SAMBA – for Windows or macOS devices to access the storage, you need the Samba application as a server for SMB/CIFS shares. Install it with:

sudo apt install samba -y

Then edit the Samba configuration file directly after the installation with our editor nano:

sudo nano /etc/samba/smb.conf

At the end of the file, add your share, such as: (as set up above)

[My home]
path = /mnt/data coffin
writeable = yes
create mask = 0777
directory mask = 0777
browseable = yes
guest ok = yes

This allows anyone on the local network to access without a password. If you prefer user access, you can guest ok = no Set and Samba users e.g. with

sudo smbpasswd -a pi

Create a new one. Then simply restart the Samba service:

sudo systemctl restart smbd

And a step further, it wasn't that hard, was it? Now a disk is permanently integrated on the Raspi, which is waiting for your data in the home network.
On Windows, you would now either integrate this release as a network drive, then the disk is always automatically available with every PC start or, if necessary, access the Raspi and the new release via the Windows Explorer under Network.

You can permanently integrate the network drive by right-clicking on ‘This PC’ → ‘Connect network drive’ and entering the address there. The address of the Raspberry can be entered in the following formats:
\\raspberrypi\data coffin (Name of Raspi + name of your release) or
\\192.168.1.100\data coffin (if the IP address is where it was set up – and the name of your release)

On macOS, open Finder and select "Go to" → "Connect to Server" and carry smb://raspberrypi/datensarg one.

On Linux, by the way, the release can also be entered into the fstab on the client system, so that the drive is always available immediately after startup.

However, a simple mount command is also sufficient for manually attaching the release. Use the following command to first CIFS Utilities to be installed:

sudo apt install cifs-utils

You can then mount the release:

sudo mount -t cifs -o username=<Samba username>,password=<Samba password> //192.168.1.100/data coffin /mnt/raspidata coffin

In the fstab, the permanent integration would look like this:

//192.168.1.100/data sarg /mnt/raspidata sarg cifs username=<Samba username>,password=<Samba password>,uid=<Linux user ID>,gid=<Linux group ID>,vers=1.0 0 0

Replace the placeholders as described above. uid and gid are the user and group IDs of the user who is to access the share. 
We can do this with id <Linux username> investigate.

Important notes:

  • Use secure passwords for the Samba users.
  • Look for the correct path information and file permissions.
  • An incorporation into /etc/fstab is always recommended if the release is regularly used again.
  • Problems with access are often rights, services, and security options. Check the firewall settings on both devices and make sure that Samba is properly started on the Raspi and that cifs-utils installed on the client.

TL:DR

You now have your own home server based on Raspberry Pi, which can do much more than a USB stick on the FritzBox. Thanks to Linux and the strong Raspberry community You can upgrade new software functions at any time and adapt the mini server to your growing needs. And all this on a device that draws less power than a light bulb! Tadaa!

:mrgreen: Benefits in Level 2 (Raspberry Pi)

  • Little hardware needed, even only SD card + USB stick goes
  • Lowest power consumption for full-fledged system
  • hardly any space required (can lie almost everywhere)
  • many additional functions can be retrofitted (Linux/Debian)

Disadvantages in Level 2 (Raspberry Pi)

  • requires at least rudimentary Linux / cli knowledge
  • slow transmission rates, especially for multiple users
  • not quite trivial setup (1-2 hours)
  • limited hardware resources, no upgrade possible
  • limited connection options for later extensions