Automount CIFS shares: errors at the start of system
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 videos on Youtube
drvlas
Updated on September 18, 2022Comments
-
drvlas over 1 year
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
-
drvlas about 7 yearsThank you for your answer! Am I right to suppose that addinh _netdev option in a rc.local mount command should make the same? I tried it in rc.local and to no avail.
-
Deltik about 7 years@drvlas:
_netdev
is an option for/etc/fstab
. To run a network mount command in/etc/rc.local
, you'll have to add extra code to wait for the network. -
drvlas about 7 yearsThat is it! I wanted to wait the network (rather my PC) to be ready - but I couldn't imagine how to solve it. I changed Eric's code to 1 sec step and put a mount command instead of ssh one. Thank you very much! Would you mind to edit your answer to include mount command in a loop? I think about somebody looking here later :)
-
Deltik about 7 years@drvlas: Per your request, I have updated my answer with your preferred mounting method.
-
SharpC over 4 yearsAs per my comment in the AskUbuntu link already mentioned, I also had to ensure the file was executable (
sudo chmod 775 /etc/rc.local
) and place#!/bin/sh -e
at the top: askubuntu.com/questions/9853/…