0

I can successfully mount an SMB share if I do this:

sudo mount -v -t cifs -o username=neubert,password=whatever //192.168.1.128/shared /media/shared

Like if I do that and go to /media/shared in the File Explorer I can view the contents of the mount point.

Putting this into my /etc/fstab, however, does not result in /media/shared being auto-mounted when I start the computer up:

//192.168.1.128/shared /media/shared cifs username=neubert,password=whatever,rw,uid=1000,gid=1000

No problem, I thought, I'll just put the mount command into my ~/.bashrc. If I just put it in my ~/.bashrc file without some sort of if statement, however, it'll give me errors whenever that location is already mounted so I tried this:

if mount -l | grep -q 192.168.1.128
then
   sudo mount -v -t cifs -o username=neubert,password=whatever //192.168.1.128/shared /media/shared
fi

Unfortunately, that doesn't work. Like even if I put that in a standalone test.sh file nothing is mounted, which just seems strange to me given that this reliably tells me if 192.168.1.128 is mounted or not:

if mount -l | grep -q 192.168.1.128
then
   echo "OK";
else
   echo "NOT OK";
fi

Any ideas?

neubert
  • 229

2 Answers2

2

Read man mount and add the "_netdev" option to your /etc/fstab entry.

waltinator
  • 37,856
1

//192.168.1.128/shared /media/shared cifs username=neubert,password=whatever,rw,uid=1000,gid=1000

The reason an explicit mount works and an fstab does not is likely a timing problem. The network stack isn't fully operational at the time fstab is read by the system so the fstab declaration does nothing.

The suggestion by @codlord to run "sudo mount -a" after you login was a way to verify if that was happening. You added a "-a" option instead of running the command as is.

One way around this issue is to use a systemd automount: x-systemd.automount

//192.168.1.128/shared /media/shared cifs username=neubert,password=whatever,rw,uid=1000,gid=1000,x-systemd.automount

Note: I recommend changing your mount point to something under /mnt for best results and a better chance of success using this method:

//192.168.1.128/shared /mnt/shared cifs username=neubert,password=whatever,rw,uid=1000,gid=1000,x-systemd.automount

ALTERNATE METHOD

** Unmount the share:

sudo umount /media/shared

** Change the line in fstab to this:

//192.168.1.128/shared /media/shared cifs username=neubert,password=whatever,rw,uid=1000,gid=1000,noauto,user 0 0

** Make systemd happy:

sudo systemctl daemon-reload

** Mount with this command:

mount /media/shared

No sudo required.

You can use "mount /media/shared" in your script -- OR -- you can open a file manager and click on the mount icon on the left side panel to mount.

Morbius1
  • 8,437