40

Under Linux (Ubuntu 12.04) I want to mount a windows share / windows partition named //winshared on the network. I do not know the IP or anything else.

On one Ubuntu system, I am able to mount a directory with

mount  //winshared/mypath /mnt/win

while on one other Ubuntu system the exact same command just gives

mount error: could not resolve address for winshared: Unknown error

Network settings seem to be same on both systems, and I installed smbfs and samba (the latter with errors). Do I need to instal something else? Do I need to configure something? How to find out the crucial differences between both systems to get the same mount work on both systems?

Additional information:

  1. When I use smbclient to connect to the windows partition/share/whatever, it works on the first system but not on the other system. The error is:

    Connection to winshared failed (Error NT_STATUS_BAD_NETWORK_NAME)
    
  2. Following this tutorial I installed smbfs and cifs-utils, but the mount command from above still gives the same error, which is NOT described in the tutorial.

  3. I also have an entry in /etc/fstab reading

    //winshared/mypath /mnt/win cifs uid=alexander,credentials=/etc/samba/wincred 0 0
    

    with the file /etc/samba/wincred identical to a same file on the system the mount works. The md5sum of both files are identical. Therefore, an error regarding credentials can be excluded.

Alex
  • 5,614
  • 19
  • 65
  • 86
  • See the tutorial on the Ubuntu Wiki: https://wiki.ubuntu.com/MountWindowsSharesPermanently – slm Nov 06 '13 at 13:03
  • I installed the two packages, but still get the same error! – Alex Nov 06 '13 at 13:16
  • I have updated the question; I posted the line of fstab, and I have verified the credential file is correct. – Alex Nov 06 '13 at 13:28
  • 4
    I would get this working from the command line 1st, putting the line in /etc/fstab is just making it more complicated to debug it to start. If you can't mount from the command line then it's something else. I use this everyday: `mount -t cifs -o rw,netbiosname=serv1,credentials=/etc/creds.txt //192.168.1.1/somedir /mnt` – slm Nov 06 '13 at 13:33
  • Nope, changing permission to 600 does not fix the problem. – Alex Nov 06 '13 at 13:37
  • Are both systems on the same network? Does it work if you use winshared's IP instead of the name? – terdon Nov 06 '13 at 13:53
  • Does this directory exist? `/mnt/win`. Also check it's permissions too. Most users can't do anything under `/mnt`. – slm Nov 06 '13 at 13:53
  • It does exist, and I have `root` rights. – Alex Nov 06 '13 at 13:58
  • You mean you're root when you run this command? – slm Nov 06 '13 at 13:59
  • No, I mean I am able to run all those commands with `sudo`. – Alex Nov 06 '13 at 14:00
  • Become root and do these commands. `sudo -i`. Also add the switch `--verbose` to the mount command. – slm Nov 06 '13 at 14:01
  • I tried: `sudo -i mount -t cifs -o uid=alexander,credentials=/etc/samba/wincred //winshared/mypath /mnt/win` but get the same error again. – Alex Nov 06 '13 at 14:03
  • Please add your `mount` command you're using to your Q. – slm Nov 06 '13 at 14:04
  • What exactly do you mean by that? I do not understand. Do you mean to add it to `/etc/fstab`? – Alex Nov 06 '13 at 14:05
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/11378/discussion-between-alex-and-slm) – Alex Nov 06 '13 at 14:18
  • No please post the actual mount command that you're running from the terminal. Similar to the one that I posted. You are trying to mount it that way now, correct? – slm Nov 06 '13 at 14:21
  • `mount -t cifs -o rw,netbiosname=serv1,credentials=/etc/creds.txt //192.168.1.1/somedir /mnt` – slm Nov 06 '13 at 14:21
  • To just get it to work I try it on the command line. When the mount works, I plan to add it to `/etc/fstab`. Here is the command again: `sudo -i mount -t cifs -o rw,netbiosname=serv1,uid=alexander,credentials=/etc/samba/wincred //winshared/mypath /mnt/win' although I do not unerstand what `netbiosname=serv1` stands for. Anyway, error again. – Alex Nov 06 '13 at 14:25
  • There MUST be a very easy solution, as this works fine on a different machine with SAME operating system in the SAME network. Some package is missing or I need to reboot or start a service or something. it HAS to be something easy. But I do not see it – Alex Nov 06 '13 at 14:27
  • Agreed, but don't let perceptions fool you. There are a multitude of ways that things that look identical can be different. We'll figure it you, and it will be something silly no doubt, but you have to debug things this way to get to the root cause 8-) – slm Nov 06 '13 at 14:37
  • netbiosname=serv1 is what name you want to present yourself as to the server when mounting. It shouldn't matter. – slm Nov 06 '13 at 14:38
  • I just rebooted the machine, but the error persists. – Alex Nov 06 '13 at 14:43
  • I am able to mount the windows share with its IP addres. This finally works!! Thanks for you help so far, but I think I will give up to solve the mystery of why the name cannot be resolved. – Alex Nov 06 '13 at 14:56
  • Is the host's name in DNS? `nslookup `. That is likely why. – slm Nov 06 '13 at 15:19
  • No its not. For the system the mount is working, it is. On both systems, `route` gives identical results. And both systems are in the same network. – Alex Nov 06 '13 at 15:22

5 Answers5

23

Either you have name resolver issue (which you can check by e.g. pinging the host winshared from your Ubuntu host) or smbfs module is not loaded.

You might have to install smbfs first with apt-get -y install smbfs and then insert the module with modprobe smbfs, but after that you should be good to go with mount -t smbs.

What you're looking for is mount -t smbfs -o username=<your_username>,password=<your_password> //server/share /mountpoint.

  • 1
    `smbfs` is installed, but a `modprobe smbfs` returns `FATAL: Module smbfs not found.` Do I need to start `smbfs` first? If so, how? How to make it start automatically after a reboot? – Alex Nov 06 '13 at 12:58
  • @Alex - There is nothing to start. You're missing packages most likely. – slm Nov 06 '13 at 13:00
  • @Alex - see this Ubuntu tutorial, it has everything you need: https://wiki.ubuntu.com/MountWindowsSharesPermanently – slm Nov 06 '13 at 13:02
  • I followed this tutorial, but still get the same error! – Alex Nov 06 '13 at 13:16
  • 3
    Necro or future travelers. smbfs is missing on new systems. Use sudo apt-get install cifs-utils instead. And if that's so, then the 'modprobe smbfs' also wont work. So this answer doesn't work on new systems. – Beeeaaar Sep 24 '18 at 18:08
  • FWIW: On Ubuntu 16 client, the suggested answer did work for me if I simply omitted the "-t smbfs" flag. – Dan H Jan 28 '19 at 22:48
  • 6
    On Ubunut 18.04, I skipped installing smbfs and just used `-t cifs`. Also, you can omit the password argument if you're running interactively as mount will ask you for your password. – MrMas Mar 25 '19 at 15:44
  • Actually you can't even use `smbfs` on Ubuntu 18.04, since there's no such package anymore. So `-t cifs` is the way to go. You just have to install `cifs-utils`. – Ruslan Sep 10 '19 at 15:00
10

I'm using a BeagleBone Black running Debian 4.9 and, due to it's limited storage capacity, I needed to mount a remote folder hosted on a Windows 10 desktop. (I know this is probably not the best from a system design standpoint, but business needs often leave little room for that.) So, having to improvise, a mounted remote folder is what I came up with.

After running into many, many problems attempting to mount a Windows 10 shared folder, here's my solution, so that others can hopefully benefit from my experience.

Windows 10 "Remote" Host

  1. Enable SMB1.0/CIFS File Sharing Support in Windows Features (details).
  2. Start the Windows NetLogon service.
  3. Enable Sharing on the folder you want to share.

Debian Linux Client

  1. Install support packages: smbclient and cif-utils:

    sudo apt-get install smbclient
    sudo apt-get install cifs-utils
    
  2. Create target directory to mount remote share:

    sudo mkdir -p /mnt/my_mount_dir
    
  3. Mount remote folder:

    sudo mount -t cifs -o "domain=MYDOMAIN,username=MyUserName,password=myPas$werd,sec=ntlm" //(your windows host ip)/(your remote share name) /mnt/my_mount_dir
    

    UPDATE: After updating my local install of Debian to version 6.3, my mount command broke requiring me to add the vers option to specify SMB1:

    sudo mount -t cifs -o "domain=MYDOMAIN,username=MyUserName,password=myPas$werd,sec=ntlm,vers=1.0" //(your windows host ip)/(your remote share name) /mnt/my_mount_dir
    
Jim Fell
  • 265
  • 2
  • 10
  • 3
    SMB1 is outdated, and you really should try to avoid using it where possible. If you include `vers=2.1` in the `mount` options you'll get SMB 2. You'd also be better off using `credentials` instead of `username` and `password`. And you may not need the `sec=ntml` after all that. – roaima Feb 12 '19 at 20:52
  • @roaima Thanks for the tips, but I'm stuck using the old stuff. Thanks for fixing the code formatting as well. It wasn't letting me put the code between the list items. – Jim Fell Feb 12 '19 at 21:54
  • `mount` didn't break; it moved to using SMB2 or possibly 3. SMB1 has been deprecated for well over ten years and you shouldn't still be using it. – roaima Feb 13 '19 at 19:40
  • @roaima That's good to know, but unfortunately Windows 10 appears to only support "SMB1.0/CIFS". Plus this is for a private network, so I'm not overly concerned about security. – Jim Fell Feb 13 '19 at 20:15
  • 1
    Windows 10 supports SMB2 and SMB3. You had to install a support package to allow it to fall back to SMB1. – roaima Feb 13 '19 at 20:34
  • @roaima I'm getting `error 2 (No such file or directory) opening credential file` when using `credentials=` but the file exists and has `rw` permissions for user, group and owner. Do you know what could be wrong? – m4l490n Apr 27 '20 at 16:18
  • @m4l490n you'd be better asking your own question but to start you off, _do not_ have the file as read/write for anyone other than the owner – roaima Apr 27 '20 at 16:24
  • Extra marks for coming back to your answer a time later to update with new, and now working again, mount command options. – John Dunne Jan 24 '21 at 02:19
1

Check that winbind is installed; then, in your /etc/nsswitch.conf file, there must be wins listed in the hosts line.

Something like:

hosts: files wins dns

There may be other modules listed, depending on what packages are installed on your system.

Juliano
  • 2,468
  • 18
  • 20
1

I right clicked on the samba share which was mounted via the GUI, from the filesystems other location, after the right click, have to open with the terminal, from the terminal you have the location of shown in the terminal box, similar to:

/run/user/1/gvfs/smb-share:server=192.168.18.1,share=xyz/foldername/

So from this location you can access the smbshared file in your command prompt.

αғsнιη
  • 40,939
  • 15
  • 71
  • 114
  • This is a wonderful answer. The underlying operating system does the heavy lifting and takes care of credentials (as you choose). That is just what I was looking for. One more step; make a directory, say `SRV1`: `sudo mkdir /mnt/SRV1; sudo chown will:staff /mnt/SRV1`. The `D:` drive is _available_ as: `/mnt/SRV1/D/`. Use a link: `ln -svn "/run/user/1000/gvfs/smb-share:server=SRV1,share=d$" /mnt/SRV1/D`. `/mnt/SRV1/D/` is _ready_ everytime the file manager bookmark connects. – will Nov 28 '21 at 02:25
0

You could try the mountSMB script from the link below.

It should handle most of what you are trying to achieve

It will scan subnets and maintain a list of servers not available on your local subnet or through nmblookup

https://github.com/huwpowell

  • It’s obvious from the link and your username, but you should clarify that you are the author of the script, and perhaps explain *how* it goes about mounting (and how it addresses the question). – Stephen Kitt Oct 06 '22 at 12:45