Skip to content

Setting up a rudimentary homelab

My high-end homelab
My high-end homelab

This post contains all information regarding my homelab’s configuration – currently a single RPi 4 running DietPi, Pi-hole, Unbound, File Browser, Uptime Kuma and Beszel.

Raspberry Pi setup

OS installation

The RPi runs DietPi.

Some of the boards supported by DietPi
Some of the boards supported by DietPi

What is Dietpi ?

DietPi is a fleshed-out Debian distro, optimized for all types of RPi’s and providing plenty of utility software to install/manage common softwares.

Attach external drive

I find it useful to extend my RPi’s storage by plugging-in an external HDD. To enable it to mount on boot:

  1. Plug your HDD (or any drive) into the RPi, and modify /etc/fstab to add the following entry at the file’s end, automounting the drive on boot.

    fstab entry to automount the drive
    UUID=<UUID> /mnt/hdd ext4 noatime,lazytime,rw,noauto,x-systemd.automount 
    # noatime:             Disable access time logging, to reduce unnecessary write operations
    # lazytime:            Delay updating a file's modify/change times,
    #                      updating them in batch after a wait period
    # rw:                  Read & Write access
    # noauto:              Tell the RPi NOT to mount at boot time, 
    #                      to avoid a "cannot-boot-because-drive-is-missing" situation
    # x-systemd.automount: Automount ONLY the first time someone tries to access the drive
    

    Figure out your drive’s UUID

    Run sudo blkid to list all block devices’ IDs, and figure out your newly-plugged-in drive’s UUID.

    Test the newly-added fstab entry

    Check that all is right with the newly-added fstab entry by running

    # Reload the systemctl daemon to find the newly-added entry
    sudo systemctl daemon-reload
    # Mount all filesystems mentioned in fstab; This should return nothing
    sudo mount --all 
    
  2. Tell DietPi to spin down the HDD after 5min without use, to save power, reduce wear, and lower noise. This is done by running dietpi-drive_manager, and then Idle Spindown > 5 minutes.

DietPi's custom software to manager drives
DietPi's custom software to manager drives

Services

Pi-hole

Pi-hole is a DNS sinkhole protecting my devices from unwanted content by refusing to resolve (some) DNS queries, typically of ad-serving domain names.

How Pi-hole works
How Pi-hole works

Why would I use a DNS sinkhole?

This is useful because it acts as a network-wide ad-blocker, and prevents all hosts to query known-bad domains (e.g. hidden.chinese.tracking.com).

It also gives me a nice dashboard of what client is pinging what.

Installation

Follow this DietPi installation guide.

Unbound

Unbound is a validating, recursive, caching DNS resolver.

Unbound
Unbound
  • Validating: Relying on DNSSEC, it checks that the received IP (for a queried domain name) hasn’t been tampered with, protecting against DNS cache poisoning.
  • Recursive: Perform the series of queries (Root server -> TLD server -> Authoritative) on the client’s behalf.
  • Caching: Caching the domain name -> IP mapping for faster resolve time (acting as a local DNS)

Why would I self-host my recursive DNS resolver?

This is useful because the alternative is to directly ask a public recursive DNS resolver (e.g. Google’s 8.8.8.8), which means telling some external entity your fully-qualified domain name (FQDN) (e.g. some.website.i.want.private)

Tell your DNS sinkhole to use your self-hosted recursive DNS resolver!

Do not forget to tell Pi-hole to use the locally-running unbound service as recursive DNS server.

Installation

Follow this DietPi installation guide.

File Browser

File Browser provides a file managing interface, serving locally-stored files (in any specified folder) over the network. I use it to serve my USB3.0-hooked HDD.

Login page of File Browser
File Browser's login page

How to only share a subfolder of my RPi’s filesystem?

Via File Browser’s GUI (accessible through http://<RPI-IP>:8084), create one user (SOMEUSER) seeing only /mnt/hdd/SOMEUSER. Then, on the RPi, the filebrowser user needs to own /mnt/hdd/SOMEUSER.

You can then login with your newly-created File Browser credentials, and try to create a file.

If it works, you’re good to go !

Installation

Install File Browser by following this DietPi installation guide.

Backup via SFTP

Secure File Transfer Protocol (SFTP) is an SSH-enabled way to transfer files from/to my RPi.

How SFTP works
How SFTP works

With port 22 open, I can backup my /home/MYUSERNAME folder with restic by running

restic --repo sftp:dietpi:/mnt/hdd/SOMEFOLDER/restic-repo backup /home/MYUSERNAME

Important

The above command assumes that

  • you have a dietpi entry in your .ssh/config, e.g.
    .ssh/config entry
    Host dietpi
       HostName <RPi-IP>
       User dietpi
       IdentityFile ~/.ssh/dietpi-access
    
  • the /mnt/hdd/SOMEFOLDER/restic-repo path exists on the RPi, and contains a restic repository
  • the dietpi user (or whichever user the .ssh/config’s dietpi entry points to) needs to own the restic-repo folder

Tip

For convenience, I can also setup my main computer to automount a folder (e.g. /mnt/hdd/SOMEFOLDER) via SFTP. I do this via two systemd units: mnt-SOMEFOLDER.mount and mnt-SOMEFOLDER.automount.

mnt-SOMEFOLDER.mount: How to mount RPi's mnt/hdd/SOMEFOLDER folder
[Unit]
Description=Mount unit for SFTP
After=network-online.target

[Mount]
What=dietpi@<RPi-IP>:/mnt/hdd/SOMEFOLDER
Where=/mnt/SOMEFOLDER
Type=fuse.sshfs
# - allow_other: lets non-root users access the mount
# - uid,gid: pretend the folder is owned by this uid:gid, allowing write
# - reconnect: handles network drops
Options=allow_other,IdentityFile=/home/SOMEUSERNAME/.ssh/dietpi-access,UserKnownHostsFile=/home/SOMEUSERNAME/.ssh/known_hosts,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,default_permissions,uid=1000,gid=1000

[Install]
WantedBy=multi-user.target
mnt-SOMEFOLDER.automount: How to automount RPi's mnt/hdd/SOMEFOLDER folder when my computer tries to access it
[Unit]
Description=Automount unit for SOMEFOLDER SFTP
After=network-online.target

[Automount]
Where=/mnt/SOMEFOLDER
# Unmount if idle for 5 minutes
TimeoutIdleSec=300

[Install]
WantedBy=multi-user.target
  1. Copy both .mount and .automount files to your main computer’s /etc/systemd/system/ folder
  2. Enable the newly-created systemd automount unit
    systemd commands to setup drive automount
    # Make systemd aware of the newly-created units
    sudo systemctl daemon-reload
    # Enable the automount unit, which takes care of the mount unit
    sudo systemctl enable --now mnt-SOMEFOLDER.automount
    # To ensure this worked
    sudo systemctl status mnt-SOMEFOLDER.mount 
    
  3. You should now be able to access /mnt/SOMEFOLDER on your main computer

Uptime Kuma

To get an overview of all my services, and know what’s currently up/down, Uptime Kuma gives me a dashboard with the ability to set periodic uptime-checks.

Uptime Kuma's dashboard
Uptime Kuma's dashboard

Beszel

To get an overview of my RPi’s health (CPU/RAM usage, disk accesses, …) Beszel – although overkill – gives me a dashboard centralizing system heath.

Beszel's dashboard
Beszel's dashboard