3.2 KiB
tags
| tags | ||
|---|---|---|
|
Important Notes
- Make sure you can connect to the share using hostname.local. see Local Host Names
- If changing location of the scripts you need to update the script name to match the path exactly
- Replace
<server-name>everywhere below with the name of your server - If running Bazzite, becuase of how fedora immutable distros are setup you need to use
/var/mnt. the actual path is/var/mntand/mntis just linked to it.
Create systemd mount file
Create a file called .<server-name>-creds in your home dir and set it so it's only readable by you like before.
Put
username=<username>
password=<password>
in the file
create the file /etc/systemd/system/mnt-<servername>.mount
(this will be mounted to /mnt/<server-name>)
In the file put the below:
[Unit]
Description=Mount SMB share Tardis
# We require network connection before proceeding.
Requires=network-online.target
After=network-online.target systemd-resolved.service
Wants=network-online.target systemd-resolved.service
Mount] #
"What" is what will be mounted. ie our NAS SMB share
What=//<server-name>.local/<shared-folder>
# "Where" is where it will be mounted in the filesystem
Where=/var/mnt/<server-name>
Type=cifs
# Let the mounted filesystem be read/write-able
# Let the mounted filesystem be owned by the 'tess' user/group
# Use the specified credential file for the connection
Options=rw,uid=<uid>,gid=<gid>,nofail,credentials=/home/**username**/.<server-name>-creds
# Lets quit trying after 30 seconds
TimeoutSec=30
[Install]
WantedBy=multi-user.target
Also replace uid=<uid>,gid=<gid> with your user and group id respectively.
They will probably both be 1000 (so uid=1000,gid=1000), but you can check with id or id **username**
This is telling systemd how to mount your drive.
Create systemd automount file
Now create the automount file /etc/systemd/system/mnt-<server-name>.automount
In that file put:
[Unit]
Description=Automount SMB share <server-name>
[Automount]
# Adjust mount location to match yours.
Where=/mnt/<server-name>
[Install]
WantedBy=multi-user.target`
Test and Apply configuration
Now we want to make the directory it will be mounting to
sudo mkdir /mnt/<server-name>
Then we reload systemd
sudo systemctl daemon-reload
First we start the .mount, and check for errors
sudo systemctl start mnt-<server-name>.mount
systemctl status var-mnt-<server-name>.mount
Then if there's no issues we can stop the normal mount and enable automount
sudo systemctl stop mnt-<server-name>.mount
sudo systemctl enable --now var-mnt-<server-name>.automount
(enable means we are telling it to run on boot, and --now it telling it to also start it now)
We could just enable the normal mount and have it mount on boot, but automount will mean it will only connect to the samba drive when we try to access it.
Now we should see it show up under /mnt/<server-name>
And if we reboot it should show up still.
Additional Notes
For reference Aiden based it off of This this post, just modified to this situation and me