Single board computer projects

Pi data server

last updated: 2025-01-07

Quick links

Intro

It'time to replace my old udoo server with a new Raspberry Pi 5 with NVMe SSD. The new Raspi 5 is faster especially with an SSD.

My data server runs several Python programs to acquire data from different devices (e.g. from the homepage of my heating pump) and convert them to MQTT. Other Python programs get MQTT data, store them in files and create graphs that are send on a daily base by mail and are shown on the servers homepage.

The data server also runs openHAB to create other graphs with persistent data.

BOM

The following material is used:

Setting up the Raspi

We are in 2025 and things changed since the first Raspis, so older Tips and Tricks are not valid any more.

Naturally we use now the Raspberry Pi Imager in it's latest version (for now 1.8.5). The device is a Raspi 5. We choose Raspi OS 64 bit Desktop and the SD card. I use the desktop version. so access with VNC is possible.

Next in the OS customisation settings (edit settings, GENERAL) we give a meaningful hostname, set a username and a password. Best is here the same username that you use for your PC, so the SSH connection is easier. Add the SSID and WiFi password. Best use Ethernet but a WiFi access can be useful in case of moving the Raspi, so we configure also a WiFi access. Choose also the time zone and the keyboard layout.

As we want to access the Raspi with SSH. Better than to use a password is to use public-key authentication. All the work is done by the imager. Switch the the SERVICES tab, choose the public-key option and click on "RUN SSH-KEYGEN". The private key is saved on your PC (Linux: .ssh folder in the home directory). The public key in the same folder on the Raspi.

Now we can burn the SD card and stick it into the Raspi if ready. After a reboot we are able to enter access the Raspi with SSH:

    ssh username@hostname.local # or
    ssh hostname.local          # if the username is the same than on the PC

The first commands after this update the software:

    sudo apt upgrade && sudo apt full-upgrade -y
    sudo reboot
    sudo apt install mc # if you love the midnight commander :)

VNC

As I want to use VNC this is a good time to activate VNC with raspi-config (3 Interface Options, I3 VNC):

    sudo raspi-config

Now we can also use the GUI.

Static IP

Next we will give the Raspi a static IP address (I love static IP addresses :)). The new OS uses the Network manager. in the GUI it is quite easy to to so. Left click on the Network Icon (top right 2 arrows), choose Advanced options and then Edit connections.... Now you can set a manual IP address for Ethernet and WiFi. I choose normally the same IP for both.

If you need to do it over SSH (headless), there is a tool named nmtui to do so. The data is saved in 2 files in the folder /etc/Networkmanager/system-connections.

Using the NVMe SSD

The manual with the Argon Case explains how to install the NVMe card and the Raspi. To be able to see the NVMe we need to edit the Raspi config.txt file now residing in /boot/firmware.

    sudo nano /boot/firmware/config.txt

Add the following two lines at the end of the file:

    dtparam=nvme
    dtparam=pciex1_gen=3

Save (Ctrl+s), exit (Ctrl+x) and reboot (sudo reboot).

Now we should be able to see the NVMe with the lsblk command.

For fun let's check the speed difference between SSD and NVMe:

    sudo apt install hdparm
    sudo hdparm -t --direct /dev/nvme0n1
    sudo hdparm -t --direct /dev/mmcblk0    

I get 87MBit/s for the SD card and 853Mbit/s for the NVMe. So the NVMe is 10 times faster :).

Copy everything to the NVMe and reboot

To copy the SD card to the SSD is very easy with a tool that we find on the Desktop under Accessories. It is called SD Card Copier and is self explaining.

After this we use sudo raspi-config to change the boot order to NVMe (6 Advanced Options, A4 Boot Order). Now we can recycle the SD card :).

Install ssmtp for mailing

For mailing you have to install ssmtp (needed), mpack (for attachments) and perhaps mailutils (not mandatory):

    sudo apt install ssmtp mailutils mpack

With your editor you have to set up the defaults for SSMTP in /etc/ssmtp/ssmtp.conf. Edit the fields:

    root=my@mail.adr
    mailhub=smtp.xxx.xx:587
    hostname=localhost
    rewriteDomain=www.xxx.com
    FromLineOverride=YES
    AuthUser=youruserid
    AuthPass=xxxxxxxxxxxx
    UseSTARTTLS=YES

Test your mail with:

    echo "Hello world email body" | mail -s "Test Subject" my@mail.adr

Install ssmtp for mailing

Cooling

In the net you find a script called measurepi.sh (James A Chambers, tmuka 2021) to check if the cooling of your Pi is enough

Backup the Raspi with PiShrink

Setting up Syncthing

Setting up Duplicati 2

A good article about Duplicati is in the German Computer mag c't 19/2024 p 18.

We download Duplicati from : https://duplicati.com/download and install it.

After this we start Duplicati. This gives us a tray icon in the panel. We find Duplicati (browser based) with http://localhost:8200 (needs javascript).

In the "First run setup" we see that for security a passphrase for the server is needed and we provide one. It is only needed if you plan to open Duplicati from another computer.

We add a backup by providing a Name and a passphrase. You must not forget this passphrase because you need it to restore the backups!

To access the Raspi we use ssh (sftp). We need to provide the IP address and the port (22). Then the path to a folder where we like to store the backup (nvme). We need to create this folder before creating the backup.

Changing from SSH password to SSH keys

We generate an SSH Key pair by running the ssh-keygen command (Linux). The private key is saved by default in a file (e.g. id_ed12345) in the folder .ssh in our home directory. Next we can increase security with a passphrase. If we don't want a passphrase we type 2x Enter. Then the public key is generated in the same folder with an ending .pub (e.g. id_ed12345.pub)

Next we must copy the public key to the Raspi. Simplest is to use the SSH tool ssh-copy_id.

    ssh-copy-id -i ~/.ssh/id_ed12345.pub 192.168.1.xxx>

To connect to the Raspi we use the ssh command with an IP address or the local host:

    ssh 192.168.1.xxx> # or 
    ssh hostname.local

Changing the port for ssh

In the file /etc/ssh/sshd_config we change the line with Port from 22 to e.g. 2222.

Changing the username

I did not pay attention and now my user name is pi on the SSD and I want to change it to weigu. This is only possible to change if I'm not logged in as pi! So the first step is to set a root password after login with ssh and change the locked root access via ssh by editing the sshd_config file:

    sudo ssh pi@192.168.1.xxx
    sudo passwd root
    sudo nano /etc/ssh/sshd_config

Under #Authentication you find a line eith #PermitRootLogin. Replace prohibit-password with yes and uncomment the line:

    PermitRootLogin yes

Then save and exit (Ctrl+s, Ctrl+x). Next we use sudo raspi-config, S5 Boot/Auto login and set the login to B1 Console. After a reboot we can now enter as root and use usermod -l newuser olduser to change the user:

    reboot
    sudo ssh root@192.168.1.xxx    
    usermod -l weigu pi

Next, we change the pi home directory to the new user home with usermod -m -d /home/newuser newuser:

    usermod -m -d /home/weigu weigu

Last we undo things that were necessary:

With raspi-config we allow the Desktop login for the new user and in the sshd_config file we comment the PermitRootLogin line (or we use sudo passwd -l root to lock the root password.

Backup/Copy with rsync

Here a reminder how to do a backup on my PC. First I use a persistent live USB of Kubuntu (https://itsfoss.com/ubuntu-persistent-live-usb/) to boot my PC (F8).

Next I disable suspend and hibernation with the following command:

    sudo systemctl mask sleep.target suspend. target hibernate.target hybrid-sleep.target

You can later undo this with unmask.

Check with:

    sudo systemctl status sleep.target suspend. target hibernate.target hybrid-sleep.target

Then I mount both partitions (filemanager) and use the following command to copy/sync everything:

    sudo rsync -av --progress /mnt/source/ /mnt/dest/

Don't forget the end /!

Interesting links