Skip to content

Instantly share code, notes, and snippets.

@axelquack
Last active May 11, 2026 21:37
Show Gist options
  • Select an option

  • Save axelquack/76fe24f0f82273d99b0b834bbc2c5271 to your computer and use it in GitHub Desktop.

Select an option

Save axelquack/76fe24f0f82273d99b0b834bbc2c5271 to your computer and use it in GitHub Desktop.
Automount SMB under Bazzite by using systemd

Automount SMB under Bazzite

Make sure that you replace whatever is in "<>" with your own data.

Setup authentication configuration file

Generate a file that defines the login data to mount the volume. The file will be called credentials located at /var/home/<username>/.smb/credentials. Make sure you first generate the folder mkdir /var/home/<username>/.smb.

username=<username>
password=<password>
  • Ensure the credentials file is readable only by the owner: chmod u=rw,go= /var/home/<username>/.smb/credentials
  • Create a mount folder on your local machine: mkdir /var/home/<username>/retrodeck
  • Create a file called var-home-<username>-retrodeck.mount located at /etc/systemd/system. sudo touch /etc/systemd/system/var-home-<username>-retrodeck.mount.

Create mount unit

[Unit]
Description=Mount SMB Retrodeck Share
# A human-readable description of this mount unit.

# Ensures the network is available before trying to mount.
Requires=network-online.target
# This unit will only start if 'network-online.target' is available.
After=network-online.target systemd-resolved.service
# Waits until network and DNS resolution are ready.
Wants=network-online.target systemd-resolved.service
# Suggests that these services should be running, but does not fail if they aren't.

[Mount]
# Defines what to mount and where.

# The network share (SMB/CIFS) that will be mounted.
What=//<yourRemoteServerIP>/<yourRemoteFolder>
# Replace with actual IP and share name, e.g., //192.168.1.100/retrodeck.

# Local mount point where the share will be attached.
Where=/var/home/<username>/retrodeck
# Replace <username> and <retrodeck> with actual values. Make sure that it matches with the folder you create as mount folder.

# Specifies the filesystem type.
Type=cifs
# This is necessary for mounting a Windows SMB/CIFS share.

# Mount options:
Options=rw,uid=1000,gid=1000,nofail,credentials=/var/home/<username>/.smb/credentials,vers=3.0
# `rw`          → Read/write access.
# `uid=1000`    → Ensures that the mounted files are owned by user ID 1000 (your main user).
# `gid=1000`    → Ensures group ownership by group ID 1000.
# `nofail`      → Prevents boot failure if the SMB share is unavailable.
# `credentials=/var/home/<username>/.smb/credentials` → Specifies the file storing the SMB username & password.
# `vers=3.0`    → Forces SMB version 3.0 for security and performance.

# Sets a timeout to stop trying if the mount hangs.
TimeoutSec=30
# If the mount attempt takes longer than 30 seconds, it will give up.

[Install]
# Ensures this mount is activated at boot.
WantedBy=multi-user.target
# Mounts the share when the system reaches multi-user mode (normal operation).

Set mount unit file permissions

  • Make sure you have set the correct permissions and ownership for systemd mount files.
  • Correct Owner and Group: sudo chown root:root /etc/systemd/system/var-home-<username>-retrodeck.mount
  • Correct File Permissions: sudo chmod u=rw,g=r,o=r /etc/systemd/system/var-home-<username>-retrodeck.mount (u=rw → User (root) gets read & write; g=r → Group (root) gets read-only.; o=r → Others get read-only)

Fixing SELinux Denial (under Bazzite)

By default Systemd is being denied access to the mount unit file due to SELinux policies.

Check Current SELinux Mode

Run:

getenforce
  • If it returns Enforcing, SELinux is actively blocking access.
  • If it returns Permissive, it logs issues but doesn’t enforce them.

Relabel the Mount Unit File

Since the file is in /etc/systemd/system/, it should have the correct SELinux label. To fix it:

sudo restorecon -v /etc/systemd/system/var-home-<username>-retrodeck.mount

Now reload Systemd, enable Auto-Start, and start the SMB mount immediately

  • Reload Systemd to recognize New or modified units: sudo systemctl daemon-reload
    • Forces systemd to reload all unit files (services, mounts, timers, etc.).
    • Necessary when adding, modifying, or deleting .mount files, since systemd does not automatically detect changes.
    • Without this, systemd might not recognize new or modified units, leading to errors when enabling or starting them.
  • Enable the mount to Auto-Start at boot: sudo systemctl enable var-home-<username>-retrodeck.mount
    • Creates a symbolic link in /etc/systemd/system/multi-user.target.wants/ pointing to your mount file.
    • Ensures that systemd automatically mounts the SMB share every time the system boots.
    • This does not immediately mount it—it just sets it up for future boots.
  • Start (mount) the SMB share immediately: sudo systemctl start var-home-<username>-retrodeck.mount
    • Manually triggers the mounting of the SMB share right now, without waiting for a reboot.
    • If successful, the mount point (/var/home/<username>/retrodeck) should now show the contents of the SMB share.
    • If there are errors (e.g., wrong credentials, network issues), it will fail, but logs can be checked using journalctl -xe.
@DancingGeek

Copy link
Copy Markdown

Thanks for this guide. I had an extra issue that I thought others might also get, so wanted to write up my alternative version for the record.

I had an issue where copying and pasting my intended mounted folder into a music player as a library location caused it to be replaced with a different path. The new path worked, but was temporary - after a reboot the mount path changed, which meant the library had to be edited and rebuilt each time.

I searched several different ways of doing this and played around with fstab settings and manual systemd mount/automount files. I finally succeeded with the following configuration: use fstab to create the systemd files AND use a directory in /mnt as the target. Also, I got rid of lots of the various options for the entry in fstab.

I haven't tested exactly what causes it to get swapped out, it may just be one of the changes I ended up making, but the following worked for me.

INSTRUCTIONS

Code replacements to make:
<server IP> = IP address of SMB server you want to mount
<share folder> = path to the folder on the server you want to mount
<mount folder> = name of folder you want the server contents to show up in
<username> = your username on your PC
<server username> = your username on the server
<server password> = your password on the server

Follow OP's instructions to create and configure the credentials file under 'Setup authentication configuration file'. Do NOT do the last two bullet points.

In a terminal, create a folder in the /mnt directory with root permissions:
sudo mkdir /var/mnt/<mount folder>

open /etc/fstab in a text editor, add the following as a line at the end:
//<server IP>/<share folder> /var/mnt/<mount folder> cifs credentials=/var/home/<username>/.smb/credentials,x-systemd.automount 0 0

What this line does:
//<server IP>/<share folder> = says what you want to mount
/var/mnt/<mount folder> = says where to mount it
cifs = the option for SMB connections
credentials=/var/home/<username>/.smb/credentials = safer than just putting your username and password in fstab directly
x-systemd.automount = tells fstab to make configuration files for systemd to then handle the mounting (not sure if this is necessary, but it is what worked for me)
0 0 = I dunno tbh, it's just what everyone says you need at the end

@EssGeeEich

Copy link
Copy Markdown

This never worked reliably for me with a hostname in the What field, lamenting unknown errors while attempting to resolve the hostname.

I got it to work however by creating a .automount file alongside the .mount file.
Note I reduced the timeout to 15 seconds, as it'll usually be a LAN mount it shouldn't take too long to connect and login...

.mount file:

[Unit]
Description=Mount SMB Share
Requires=network-online.target
After=network-online.target
Wants=network-online.target

[Mount]
What=//my-hostname/share
Where=/var/home/bazzite/share
Type=cifs
Options=rw,uid=1000,gid=1000,nofail,credentials=/var/home/bazzite/.smb/credentials,vers=3.0,_netdev
TimeoutSec=15

[Install]
WantedBy=multi-user.target

At this point, it's not a bad idea to also add ,x-gvfs-name=<pretty_name> in order to show a pretty name in Dolphin.

.automount file:

Description=Automount SMB Share

[Automount]
Where=/var/home/bazzite/share

[Install]
WantedBy=multi-user.target

Then enable the automount unit: systemctl enable var-home-bazzite-share.automount

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment