# Automatically mount some network devices



## zwei (Oct 24, 2011)

Hi,

today I'm trying to automatically mount some network devices. But it doesn't work.


```
/etc/fstab:

//fausten@kali-files/transfer /usr/home/michael/mount/transfer smbfs rw,-N,-I=192.168.23.225 0 0
```


```
/root/.nsmbrc

[KALI-FILES:FAUSTEN]
password=mypassword
addr=192.168.23.225
```

Typing *mount -a* works on the command line, but when I reboot my machine the following error appears:


```
mount_smbfs can't set locale

mount_smbfs: smb_lib_init: can't initialise locale
```

I fixed this by adding following line to /root/.profile:


```
export LC_ALL="C"
```

Now after reboot I get this:


```
Mounting late file systems: smb_co_lock: recursive lock for object 1

mount_smbfs: unable to open cennection: syserror = Network is unreachable
```

Can anyone help?

Regards,

zwei


----------



## fluca1978 (Oct 24, 2011)

I think the problem is that your system is trying to mount the filesystem together with the other local filesystems, and therefore before the system is started services and, hence, the networking.
I guess the solution is to put your filesystem mounting in a rc script.


----------



## zwei (Oct 26, 2011)

Hi,

I don't think so at all. Who is responsible for mounting network devices if not the /etc/fstab.
Anyway I tried your suggestion, but it still doesn't work. Error is the same.

Regards, 

zwei


----------



## aragon (Oct 26, 2011)

It must be as fluca said.  The error "Network is unreachable" is a bit of a giveaway. Enabling RC debugging might help you troubleshoot.  Add to /etc/rc.conf:


```
rc_debug=YES
```

However, have you considered using amd(8) instead of fstab?


----------



## geodni (Oct 26, 2011)

You can also use the noauto options in /etc/fstab for the smbfs line and then use a simple rc script to mount it after all system is up or go further with automount.
Take a look at the [thread=23105]Excellent Aragon's job around auto mounting[/thread]


----------



## aragon (Oct 26, 2011)

geodni said:
			
		

> Take a look at the [thread=23105]Excellent Aragon's job around auto mounting[/thread]


Appreciate the plug, but I don't see the relevance?  My work is oriented at hot plugged devices...


----------



## adamk (Oct 26, 2011)

I'm not sure I can offer much assistance here, but I can say that the smbfs entries in my /etc/fstab do mount properly, without any intervention, once the network is up.  Here's one of the shares:


```
//adamk@thorn/workarea	/home/adamk/workarea	smbfs rw 0 0
```

My system does not try to mount /home/adamk/workarea until after networking is available.

EDIT:  You haven't changed the netfs_types or extra_netfs_types settings in /etc/defaults/rc.conf or /etc/rc.conf, have you?


----------



## wblock@ (Oct 27, 2011)

If it works after startup but not from startup, then maybe the network isn't up yet.  We haven't yet seen how the network is configured in /etc/rc.conf.  Changing DHCP to SYNCDHCP might be enough.


----------



## shitson (Oct 27, 2011)

Would it be plausible to create an RC script for this, that requires networking before trying to run the script. I believe that part of the Handbook describes how to do this.


----------



## wblock@ (Oct 27, 2011)

Yes, but the rc.d "networking" script can complete before the interface is up and actually connected.  SYNCDHCP and the new netwait script are ways to deal with that.


----------



## zwei (Oct 27, 2011)

Hi guys,

first: thanks a lot for your great and numerous feedback.

@aragon:

I set in /etc/rc.conf


```
rc_debug=YES
```

But that doesn't helped me troubleshooting.

No, i didn't try using amd(8), but i will try this later.

@geodni:

Yes, I tried the noauto option in /etc/fstab but when I do this, mount -a is not working anymore.

@adamk:

I tried, I think for like the 10th time, what you said in #7. Anyway, he can't then find the adress, so I added the -I option in /etc/fstab again, now mount -a works again and while booting the machine he asks for the password. Configured like this I always need to type the password. Good step in the right direction. If i also add the -N option, that he doesn't ask for the password, the error from the beginning appears again 

No, I havn't set netfs_types or extra_netfs_types in /etc/rc.conf or elsewhere.

@wblock:

my /etc/rc.conf


```
hostname="natalie.freeBSD"
ifconfig_re0="DHCP"
keymap="german.iso"
sshd_enable="YES"
mountd_enable="YES"
hald_enable="YES"
dbus_enable="YES"
postgresql_enable="YES"
cupsd_enable="YES"
devfs_system_ruleset="system"
startx_enable="YES"
rc_debug="YES"
```

You mean this 


```
ifconfig_re0="DHCP"
```

to


```
ifconfig_re0="SYNCDHCP"
```

? If yes, doesn't make any difference.

Regards,

zwei


----------



## T-Daemon (Oct 27, 2011)

Hi,

Try this script to mount samba shares during boot. Source

PS: Samba related  static variables, like locale, should be set in /etc/nsmb.conf, ~/nsmb.conf nsmb.conf()(5) or ~/.nsmbrc, rather than in /root/.profile.


----------



## T-Daemon (Oct 27, 2011)

By the way, please remove "=" from the smbfs fstab line changing -I=192.168.23.225 into -I192.168.23.225


----------



## wblock@ (Oct 27, 2011)

Actually, that looks like the correct way to say "-I 192.168.23.225" in an /etc/fstab options entry:
`% man mount | less -p'Options that take a value'`


----------



## zwei (Jan 19, 2012)

Hi,

I know, long time ago I was last looking in this thread. But it was just so frustrating for me  Anyway, because of a new year resolution today i tried again to fix the problem. And fortunately I fixed it. I'm not quiet sure if this is a neat solution, but it works for me:

~/mount.sh


```
mount_smbfs -N -I 192.168.23.225 -E utf-8:cp1252 //fausten@[B]KALI-FILES[/B]/transfer /usr/home/michael/mount/transfer
```

~/.nsmbrc


```
[KALI-FILES:FAUSTEN]
password=******
addr=192.168.23.225
```

I replaced the IP: 192.168.23.225 with "KALI-FILES" and now it works.

Now, if I need the shares, I'm able to mount them by executing the ~/mount.sh as root. This is approximately the solution, I had in mind.

Best regards and thanks for your time.

zwei


----------

