--- tags: - Arch - Bazzite - Void --- ## Important Notes 1. Make sure you can connect to the share using hostname.local. see [Local Host Names](LocalHostNames.md) 2. **If changing location of the scripts** you need to update the script name to match the path exactly 3. Replace `` everywhere below with the name of your server 4. If running [Bazzite](Bazzite.md),  becuase of how fedora immutable distros are setup you need to use `/var/mnt`. the actual path is `/var/mnt` and `/mnt` is just linked to it. ## Create systemd mount file Create a file called `.-creds` in your home dir and set it so it's only readable by you like before. Put ``` username= password= ``` in the file create the file `/etc/systemd/system/mnt-.mount` (this will be mounted to `/mnt/`) In the file put the below: ``` [Unit] Description=Mount SMB share # 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=//.local/ # "Where" is where it will be mounted in the filesystem Where=/mnt/ 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=,gid=,nofail,credentials=/home/**username**/.-creds # Lets quit trying after 30 seconds TimeoutSec=30 [Install] WantedBy=multi-user.target ``` Also replace `uid=,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-.automount` In that file put: ``` [Unit] Description=Automount SMB share [Automount] # Adjust mount location to match yours. Where=/mnt/ [Install] WantedBy=multi-user.target` ``` ## Test and Apply configuration Now we want to make the directory it will be mounting to `sudo mkdir /mnt/` Then we reload systemd `sudo systemctl daemon-reload` First we start the .mount, and check for errors ``` sudo systemctl start mnt-.mount systemctl status mnt-.mount ``` Then if there's no issues we can stop the normal mount and enable automount ``` sudo systemctl stop mnt-.mount sudo systemctl enable --now mnt-.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/` And if we reboot it should show up still. ## Additional Notes For reference Aiden based it off of  [This](https://www.reddit.com/r/SteamDeck/comments/ymjnjy/mounting_smb_shares_with_systemd/) this post, just modified to this situation and me # Automounting using AutoFS and CIFS You will need the `autofs` and `cifs` packages, and the autofs service will need to be enabled but not running Make a credentials file using previous steps. For this example, my credentials are in `/home//.servercreds/-creds` In Void, AutoFS uses the file `/etc/autofs/auto.master` as its directory master. We can avoid editing this file by putting our directory map files in `/etc/autofs/auto.master.d/`. This files may be in a seperate location in a different distros You will need 2 files: a directory map and a file map. Create the directory map `/etc/autofs/auto.master.d/.autofs` and the key file `/etc/autofs/auto.` The directory map can contain multiple maps, however we are going to make one file per map. ## Indirect Mapping Indirect mapping allows the user to specify the mount point in the directory map and the subfolder in the key file In the directory map we want to list the mount point for thee smb share and it's key file `/mnt /etc/autofs/auto.` This tells autofs to mount the share in a subdirectory of /mnt In the key file we need to specify the name of the subdirectory, our config options, and thee smb server location ` -fstype=cfs,credentials=/home/**username**/.servercreds/-creds,uid=,gid= :` As with systemd, replace `uid=,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**` If using an IP address, it needs to be put before `::` ## Direct Mapping Direct mapping requires the user to specify the entire mounting path in the key file In the directory map we want to specify we replace the mount point with `/-` to indicate that we are using direct mounting `/- /etc/autofs/auto.` This tells autofs to mount the share using the path found in the key file In the key file we now need to the entire mounting path rather than just the subdirectoory `/mnt/ - :` ## Testing configuration To test the configuration, without the `autofs` service running, launch `automount` using `# automount -f -v` If you configured everytning properly, you will see `mounted /mnt/` Exit `automount` and restart the `autofs` service ## Additional Notes Tess based this guide on https://man.voidlinux.org/auto.master https://man.voidlinux.org/autofs /etc/autofs/auto.master https://computingforgeeks.com/how-to-automatically-mount-nfs-file-system-with-autofs/