I have a shared directory from my windows server that I’d like to read and write from my Raspberry Pi. I want the share to be automatically available on my Raspberry Pi whenever both the Raspberry and the Windows server are running, but I don’t want the system to spend too much time hung up if the windows server is not available. My easy solution is below.
My Windows servername is Acid. The share I want to connect to is Web. The IP address of the server is 192.168.0.12.
sudo echo 192.168.0.12 Acid>>/etc/hosts sudo mkdir --parents /media/acid/web sudo echo username=WindowsUsername >/etc/wimsworld.smb.credentials sudo echo password=WindowsPassword >>/etc/wimsworld.smb.credentials sudo echo domain=OptionalDomainName >>/etc/wimsworld.smb.credentials sudo chmod 0600 /etc/wimsworld.smb.credentials sudo echo //acid/web /media/acid/web/ cifs credentials=/etc/wimsworld.smb.credentials,noauto,x-systemd.automount,x-systemd.idle-timeout=1min,_netdev 0 0>>/etc/fstab
That series of commands, with the correct details in the credentials, and the system automounter will automatically attempt to connect whenever there’s an access under /media/acid/web and then disconnect again after it’s been idle for over a minute.
I needed to add Acid to my local hosts file because the name doesn’t resolve from the DNS server the raspberry pi is using.
I put the windows Username/Password and Domain in a file with only read/write permissions to root so that it wasn’t clear text in the fstab file for anyone on the machine to read.
I did all of this on a machine that had been built from the Raspian Buster Lite image from 2019-07-10. I didn’t explicitly install the cifs-utils package. It might be needed on other distributions.