0

I have a CIFS network share mounted on /etc/fstab at boot on a laptop connected to the wireless network. My fstab looks like this:

//192.168.0.100/MyShare  /mnt/MyShare  cifs  username=<username>,password=<password>,rw,uid=1000,gid=1000,nounix,iocharset=utf8,file_mode=0770,dir_mode=0770,vers=3.0  0  0

Now, that normally works fine, but being a laptop, i move a lot and reconnect to my home wireless network quite often. This means that, when i leave the network, the share mount also disconnects, but when i get back home, it won't reconnect automatically so i need to "mount -a" every time this happens.

I'm looking for an option to automatically mount it on network getting available, or at least mounting automatically upon access (that is, when Dolphin or other file manager accesses the mount point, it should get remounted as root).

Is there any easy way to do this? Any best practice, maybe? Thanks!

Later edit: In the meantime, I found something that i would call a workaround, not a solution, so i'll keep the question opened:

  • i created a script in /etc/network/if-up.d/<script> to be run upon connecting to my network:
#!/bin/bash
if iwconfig|grep -c <SSID>
then                                                         
        mount -a
fi

So now, when my connection becomes active, everything gets auto-mounted.

1

Your script seems like a viable option to me. I've seen far more convoluted workarounds to issues in Linux.

Another alternative is a systemd automount which fulfills the or at least mounting automatically upon access requirement. Simple enough to implement and revert back if it's not exactly what you want.

[1] Unmount the share if it is already mounted:

sudo umount /mnt/MyShare

[2] Add 3 more options to your fstab declaration: noauto,x-systemd.automount,x-systemd.idle-timeout=30

//192.168.0.100/MyShare  /mnt/MyShare  cifs  username=<username>,password=<password>,rw,uid=1000,gid=1000,nounix,iocharset=utf8,file_mode=0770,dir_mode=0770,vers=3.0,noauto,x-systemd.automount,x-systemd.idle-timeout=30  0  0

Then do some systemd stuff:

sudo systemctl daemon-reload
sudo systemctl restart remote-fs.target

The share will not mount at boot ( noauto ) but when the mount point is accessed ( noauto,x-systemd.automount ) and it will automatically unmount if share access is idle for more than 30 seconds - user adjustable ( x-systemd.idle-timeout=30 )

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.