How to unmount a drive in samba and mount in home

Yes - it is very simple - it is simpler than taking rounds with fstab (File System Table) or mount units

All your questions is answered in How To I linked you to.

Yes

GVFS has a command gio-mount - which for samba mounts is

gio-mount smb://my-server/my-share

Assuming the UID is 1000 - the mountpoint for above command can be accessed at the following endpoint

/run/user/1000/gvfs/'smb-share:server=my-server,share=my-share'

Yes

The script doesn’t mount the share, but calls gio-mount

gio-mount location is predictable

This predicatablity is utilized to create a symlink

But you are making it complicated by mixing in your other experiments and thinking you need understand everything inside the script - you don’t.

If you do then great - but if you don’t it doesn’t matter.

The script has been up for a long time - it is - so to speak - vetted by the community to do precisely what it claims to do.

The script mount a samba share - as user - without any need for elevated permissions aka sudo or to run as root.

I’d advise you to remove all remnants of your previous experiments and just use the script when you need to mount the share.

If you later think - it would be nice the share is available automagically - you can create the systemd user unit - but this is not a requirement for the script to be functional.

Create the local bin folder

The topic explains you place the script in your home folder ~/.local/bin - if it does not exist - create it

mkdir ~/.local/bin

Create the script

Open mousepad and paste the content of the script - then save the file - and when prompted for a name - navigate to folder .local/bin - it is hidden so if you cannot see the folder in the dialog - press ctrlh - navigate into .local → bin → provide the name you e.g. my-share.sh - the .sh extension is just a human helper to identify a shell script - the system doesn’t care

Make the script executable

chmod +x ~/.local/bin/my-share.sh

Amend a few script variables

The variable are there because not two usecases are alike.

# your samba server's hostname or IP address
HOST="my-server"

# the share name on the server
SHARENAME="my-share"

# optional credentials
USERNAME=
WORKGROUP=
PASSWD=

Then save the file

Open a terminal and type in the name of the file you just created.

my-share.sh

If required - authenticate …

Navigate into the new SMBLinks folder in home → navigate into the share → do your thing.

If you have more than one samba share - it is easy to duplicate the script (and service if applicable)

Using the service brings in the benefit that symlinks are removed upon shutdown which otherwise may leave you with dead symlinks if the share is not mounted.