# [SOLVED] Samba, error(101): Network is unreachable

## lekto

Hi, I have issue with auto mounting samba shares. Shares aren't mounted on boot, but I can mount them manually by run "mount -a". It's possible that openrc try to mount shares before connecting to network?

/etc/fstab

```
//dedyk/transmission   /media/lekto/transmission   cifs   vers=3.0,credentials=/root/.credentials   0 0

//dedyk/backup      /media/lekto/backup      cifs   vers=3.0,credentials=/root/.credentials   0 0
```

/var/log/rc.log

```
 * Mounting network filesystems ...

mount error(101): Network is unreachable

Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

mount error(101): Network is unreachable

Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

 * Could not mount all network filesystems
```

dmesg

```
[   30.887392] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready

[   30.986346] CIFS VFS: Error connecting to socket. Aborting operation.

[   30.986349] CIFS VFS: cifs_mount failed w/return code = -101

[   30.988093] CIFS VFS: Error connecting to socket. Aborting operation.

[   30.988095] CIFS VFS: cifs_mount failed w/return code = -101

(…)

[   33.854946] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
```

Last edited by lekto on Mon Jan 08, 2018 8:25 pm; edited 1 time in total

----------

## Ant P.

See the comments in /etc/conf.d/netmount and configure it appropriately.

----------

## Hu

Those shares are (attempted to) mount on boot, which is your problem.  You did not mark them as _netdev, so localmount attempts to mount them, which fails because localmount runs before the network is started.  You should mark them as _netdev to prevent mounting them before the network starts.  You may also need to follow Ant P.'s instructions to get them to mount once network is available.

----------

## lekto

I edited netmount and added _netdev, but it sometimes worked and sometimes not. Then I haved realized I forgot to run net.eth0 and after fix it samba shares work well.

----------

## lekto

I'm writing here because this doesn't work anymore for me after switching network management to dhcpcd [1]. I had problem with dhcpcd that it was taking too long to get network configuration, which was delaying start of xdm. Now there is no delay during boot, but network starts working few seconds after start of xfce and samba shares are not mounted.

I got this in dmesg:

```
[   22.517890] CIFS: Attempting to mount //dedyk/transmission

[   22.517920] CIFS: VFS: Error connecting to socket. Aborting operation.

[   22.517922] CIFS: VFS: cifs_mount failed w/return code = -101

[   22.518849] CIFS: Attempting to mount //dedyk/backup

[   22.518879] CIFS: VFS: Error connecting to socket. Aborting operation.

[   22.518880] CIFS: VFS: cifs_mount failed w/return code = -101

[   25.517359] igb 0000:05:00.0 eth0: igb: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX/TX
```

/etc/conf.d/netmount:

```
rc_need="dhcpcd"
```

/etc/fstab:

```
//dedyk/transmission                            /media/lekto/transmission       cifs            vers=3.0,_netdev,credentials=/root/.credentials 0 0

//dedyk/backup                                  /media/lekto/backup             cifs            vers=3.0,_netdev,credentials=/root/.credentials 0 0
```

[1] https://wiki.gentoo.org/wiki/Network_management_using_DHCPCD

----------

## lekto

Ok, I kludged it, in /etc/init.d/netmount I added in depend():

```
after xdm
```

and in start():

```
        ebegin "Waiting for network connection"

        for i in `seq 30`; do

                echo -n "."

                sleep 1

                ping -c1 192.168.0.1 &>> /dev/null

                if [ "$?" == "0" ]; then

                        ebegin "Network seems to work"

                        break

                fi

        done
```

----------

## lekto

Well, sometime after my last post that method stopped working. Recently I came up with this:

```
#!/bin/sh

function loop {

   local program_name="delayed-mounter"

   for i in $(awk '/cifs/ {print $2}' /etc/fstab); do

      echo $program_name: trying to mount $i > /dev/kmsg

      while [ -z "$(mount | grep $i)" ]; do

         mount $i

         sleep 5

      done

      echo $program_name: $i is mounted, continue > /dev/kmsg

   done

   echo $program_name: everything was mounted, exiting > /dev/kmsg

}

loop& 

```

To use it put it in /etc/local.d/delayed-mounter.start, give it execute permission and add local to default runlevel. This script is looking for line with cifs in /etc/fstab in second column and trying to mount it one by one until it was successfully mounted. There are some improvements that can be added:

- Ignoring lines that are comments (starts with "#"),

- It trying to mount share until it's mounted, so it can stuck. It could be fixed by creating separate thread for every mount,

- Checking it share was mounted properly could be better.

----------

## Hu

That script will mount any line that has cifs anywhere in it:

```
$ printf 'The scifs are here.\n' | awk '/cifs/ {print $2}'

scifs

$ printf 'Open the door; the scifs are here.\n' | awk '/cifs/ {print $2}'

the
```

Polling like that is generally bad.  Why not use a dhcpcd hook to mount the filesystems after the network is up?  Add noauto to the mount options.  Create a dhcpcd hook in /lib/dhcpcd/dhcpcd-hooks.  The example in /usr/share/dhcpcd/hooks/29-lookup-hostname looks like a good starting point.  When the interface is brought up, bring up all the cifs filesystems, which you can more cleanly list using findmnt:

```
findmnt --fstab -t cifs --output TARGET --noheadings
```

----------

