Raspberry Pi4 + openSUSE + Samba

Sharing files within your LAN

Hello, in this article, I’ll explain how to install openSUSE Tumbleweed (however, these instructions would probably work in openSUSE Leap) in Raspberry Pi 4, plus install and configure a basic Samba server to share files from an external HDD.

The first thing to do is install the openSUSE Tumbleweed image on your Raspberry Pi 4. Go to the openSUSE Wiki page for Raspberry Pi 4 and download the image that you like to use.

There are six images available. Download the image you want (Leap is stable, Tumbleweed is rolling) from here. Choose your desktop type:

  • JeOS - Just enough Operating System - a very basic system, no graphical desktop
  • E20 - Enlightenment desktop
  • XFCE - XFCE desktop
  • KDE - KDE desktop
  • LXQT - LXQT desktop
  • X11 - basic X11 system

The direct links did not work for me, so I went to the general download directory and downloaded the latest JeOS image named openSUSE-Tumbleweed-ARM-JeOS-raspberrypi.aarch64.raw.xz

As root extract the image onto your SD card or USB device(replace sdX with the device name of your SD card).

If possible, it is better to use a decent USB 3 device as the read and write speeds are greater than SD cards. I’ll use the USB device as the media used to install the image from now on.

WARNING: this is a destructive operation. All previous data on the device will be lost. Check first if the device you have selected is really your target device!

xzcat openSUSE-Tumbleweed-ARM-JeOS-raspberrypi.aarch64.raw.xz | dd bs=4M of=/dev/sdX iflag=fullblock oflag=direct status=progress; sync

After the image is extracted to the USB device, you can insert it into your Raspberry Pi 4 and turn it on.

You will need to discover the IP address of your Raspberry Pi 4. This can be done in a hundred different ways. For example, you can look at your router DHCP table for a MAC address that belongs to “Raspberry Pi Trading Ltd”.

Wait 5 minutes before the first login as the OS will perform some tasks at the first boot, like resizing the ext4 filesystem to the entire disk.

SSH is enabled by default in openSUSE images so that you can log in as root with:

ssh root@raspberry_pi_ip_address

The default password is “linux”.

Find your keyboard layout and load it. To search your keyboard, type:

localectl list-keymaps

In my case, I use a Brazilian keyboard layout called “br-abnt2”. Load your keyboard layout with:

loadkeys br-abnt2

For security reasons, change the default root password.

passwd

Type once and then confirm your new password.

Check for available system updates.

zypper dup --details

Install vim and vim-data to have a better editing experience. You can use the editor that you prefer.

zypper in --details --no-recommends vim vim-data

Change the hostname as you like.

hostnamectl hostname your_hostname

Create your user account.

useradd -m -s $(which bash) your_username

Configure the sudo commands allowed for your account.

visudo -f /etc/sudoers.d/your_username

Add your_username ALL=(ALL) ALL to the file and save it.

As the server administrator, I’ll give my user account the right to run all commands as root.

Now configure sudo to ask for your password instead of the root password.

visudo

Comment the following lines:

1
2
Defaults targetpw   # ask for the password of the target user i.e. root
ALL   ALL=(ALL) ALL   # WARNING! Only use this together with 'Defaults targetpw'!

Check if is everything correct with your sudo related files.

visudo -c

If there is some problem, you can fix it by editing the file.

Set a password for your user account.

passwd your_username

Reboot the system to be able to SSH with your user account instead of the root account.

systemctl reboot

Log in with your user account.

ssh your_username@raspberry_pi_ip_address

Now we will mount the external HDD to /mnt/externalhdd/

First we discover the UUID for the external HDD.

lsblk --fs --output UUID,TYPE,FSTYPE,LABEL,MOUNTPOINT

1
2
3
4
5
6
7
8
9
UUID                                 TYPE FSTYPE LABEL            MOUNTPOINT
                                     disk                         
30e471a2-263e-48c2-9d57-d32445b7038a part ext4   externalhdd      
                                     disk                         
8511-418f                            part vfat   EFI              /boot/efi
d1ed4b63-3e1a-4aa6-9e26-1e19fe9a77b0 part swap   SWAP             
fd388969-253a-4709-8e23-5243f0eeb33d part ext4   ROOT             /
                                     disk                         [SWAP]
                                     

Create the mount point.

mkdir -p /mnt/externalhdd

Edit the /etc/fstab file and add the line for the external HDD. Observe that in this case, the external HDD is formatted as ext4. Adjust according to your needs.

1
2
3
4
5
6
# System mount point
UUID=fd388969-253a-4709-8e23-5243f0eeb33d / ext4 noatime,nobarrier 0 1
# EFI partition mount point
UUID=1845-7210 /boot/efi vfat defaults 0 0
# External HDD mount point
UUID=30e471a2-263e-48c2-9d57-d32445b7038a /mnt/externalhdd ext4 noatime,nobarrier 0 2

Test the mount point.

mount -a

If everything worked correctly, you should see no output.

Now you can install the Samba server.

sudo zypper in --details --no-recommends samba samba-doc

Backup the original Samba configuration file.

sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.bkp

To better understand the options, copy a fully commented example file from the Samba documentation.

sudo cp /usr/share/doc/packages/samba/examples/smb.conf.default /etc/samba/smb.conf

In this article, other than users, I 'll use a group to control the access to the shared folders.

Add a group called smbusers or whatever you like.

sudo groupadd smbusers

Create a Samba password for the user that will have access to the shares. This password can be different from the user account password.

sudo smbpasswd -a your_username

Edit the Samba configuration file. For simplicity, I’ll omit some comments, but I strongly recommend reading the Samba documentation to properly understand the options.

sudo vim /etc/samba/smb.conf

Some considerations:

  • All shares will require the Samba password.
  • I’ll use your_username to illustrate a real user replace with a proper user name.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Global Settings
[global]

# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
    workgroup = YOUR_WORKGROUP_NAME 

# server string is the equivalent of the NT Description field
    server string = Some string to identify your server

# Server role. 
    server role = standalone server

# Restrict access to your LAN network, and the "loopback" interface
    hosts allow = 192.168.0. 127.

# Use a separate log file for each machine that connects
    log file = /var/log/samba/log.%m

# Put a capping on the size of the log files (in Kb).
    max log size = 50

# Backend to store user information.
   passdb backend = tdbsam

# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names via DNS nslookups. The default is NO.
   dns proxy = no 

# This one is useful for people to share files
[tmp]
    comment = Temporary file space
    path = /mnt/externalhdd/tmp
    read only = no
    public = yes
    browsable = yes
    writable = yes

# A private directory, usable only by your_username. Note that your_username requires write access to the directory.
[username]
    comment = Private stuff for your_username
    path = /mnt/externalhdd/your_username
    valid users = your_username
    public = no
    writable = yes
    printable = no
    create mask = 0700
    directory mask = 0700

# Custom shares

# A share for pictures, accessible only by members of the group "smbusers"
[pictures]
    comment = Pictures
    path = /mnt/externalhdd/pictures
    public = no
    browsable = yes
    writable = yes
    valid users = @smbusers

Test the Samba configuration file.

testparm

This final part enables the Firewall and allows the Samba ports through it.

sudo systemctl enable --now firewalld.service

In this case, we are using the “home” firewall zone and the interface “eth0”.

sudo firewall-cmd --set-default-zone=home
sudo firewall-cmd --zone=home --change-interface=eth0

Allow the Samba service through the Firewall.

sudo firewall-cmd --zone=home --permanent --add-service=samba

Reload the firewall configuration.

sudo firewall-cmd --reload

Enable and start the smb and nmb services.

sudo systemctl enable --now smb.service sudo systemctl enable --now nmb.service

Reboot your Raspberry Pi, and you should have a working Samba server sharing your external HDD.

sudo systemctl reboot

updatedupdated04-03-202204-03-2022
Load Comments?