Linux – Automount CIFS shares: errors at the start of system

linuxlinux-mintmountsamba

My OS is Linux Mint 18.1.
I have a NAS in my home net. I used to mount it's volumes via fstab file and everything was fine.
After some upgrading of my PC I added one more partition to mount (on the SSD). And when I added due automount line in my fstab, problems began.

I tried various options. The PC hanged at the start and I had to return default fstab file to continue… At last the system refused to start altogether and I had to reinstall my Linux Mint.

My problem with fstab: I cannot fix the error message. So I decided to use /etc/rc.local and view errors.
I added such commands in rc.local:

mount -t ext4 -L Data /mnt/data
mount -t cifs -o credentials=/home/user/my-sys/.user,iocharset=utf8,file_mode=0775,dir_mode=0775 //192.168.0.100/Volume_1 /mnt/vol1 2> /home/user/mounterr.log

The Data partition is being mounted OK.
The CIFS gives error:
mount error(101): Network is unreachable

Manual launch of this mount command gives OK.
What is the cause of the error during rc.local execution? I'd like to understand – instead of just to use one more way (crone or what else…).

Regards,
Yury

Best Answer

The error mount error(101): Network is unreachable means that you attempted the mount before the network came up.

To fix this, add the _netdev option to your /etc/fstab CIFS entry. _netdev means to delay the mount until your network is connected.

Your /etc/fstab line should look like this:

//192.168.0.100/Volume_1 /mnt/vol1 credentials=/home/user/my-sys/.user,iocharset=utf8,file_mode=0775,dir_mode=0775,_netdev 0 0

To continue using /etc/rc.local for your mount, you'll need to set up a new job (to prevent blocking) that loops until the network is up.

From this answer in Ask Ubuntu:

(
until ping -nq -c3 W.X.Y.Z; do
   # Waiting for network
   sleep 1
done
mount -t cifs -o credentials=/home/user/my-sys/.user,iocharset=utf8,file_mode=0775,dir_mode=0775 //192.168.0.100/Volume_1 /mnt/vol1
)&

Replace W.X.Y.Z with an IP address that responds to ICMP requests, like your router gateway.

Related Question