Raspberry Pi Adventures

Join me on my fun ride

Mounting and AutoMounting Windows Shares on Raspberry Pi

43 Comments

Using OS : 2012-08-16-wheezy-raspbian

Create Windows Shared Folders using this guide : Windows 7 Network Sharing

Lets say the Windows PC has a host Name as : WindowsPC
And share folder is : share1
So the network share path is : //WindowsPC/share1

Now to Access those on your Rpi
1. Create folder in the /mnt/ folder so that you can mount your network share in that folder
$sudo mkdir mountfoldername

2. Two Ways to access

2.1 Guest Share
sudo mount -t cifs -o guest //WindowsPC/share1 /mnt/mountfoldername

Tip: If your share has space then run the following command, notice the quotes
sudo mount -t cifs -o guest "//WindowsPC/Share 1" /mnt/mountfoldername

2.2 Password Protected Share
sudo mount -t cifs -o username=yourusername,password=yourpassword //WindowsPC/share1 /mnt/mountfoldername

3. Now to check that its mounted , run the following command
$ df -h

Returns something like
Filesystem Size Used Avail Use% Mounted on
rootfs 7.3G 2.0G 5.0G 29% /
/dev/root 7.3G 2.0G 5.0G 29% /
tmpfs 19M 228K 19M 2% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 37M 0 37M 0% /tmp
tmpfs 10M 0 10M 0% /dev
tmpfs 37M 0 37M 0% /run/shm
/dev/mmcblk0p1 56M 36M 21M 64% /boot
//WindowsPC/share1 1.9T 1.5T 390G 80% /mnt/mountfoldername

Notice the last line

4. Now you can access the contents by traversing the following path
$ cd /mnt/mountfoldername

Now if we reboot we need to again mount this network share.

To Automount the network shares everytime on boot follow on

1. We need to edit the /etc/fstab file, Run the following command to edit the /etc/fstab file

$sudo nano /etc/fstab

2. Append the following to the /etc/fstab file

For Guest Login
//WindowsPC/Share1 /mnt/mountfoldername cifs guest 0 0

For Password Protected Login
//WindowsPC/Share1 /mnt/mountfoldername cifs username=yourusername,password=yourpassword 0 0

For Share names with a space

Check the References link

3. Save the File and run the more command to check if the file is updates
$more /etc/fstab

Returns something like
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 0
/dev/mmcblk0p2 / ext4 defaults,noatime 0 0
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
//WindowsPC/Share1 /mnt/mountfoldername cifs guest 0 0

4. Now Reboot and check that your network share is auto mounted with the following command
$ df -h

Returns

Filesystem Size Used Avail Use% Mounted on
rootfs 7.3G 2.0G 5.0G 29% /
/dev/root 7.3G 2.0G 5.0G 29% /
tmpfs 19M 228K 19M 2% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 37M 0 37M 0% /tmp
tmpfs 10M 0 10M 0% /dev
tmpfs 37M 0 37M 0% /run/shm
/dev/mmcblk0p1 56M 36M 21M 64% /boot
//WindowsPC/Share1 1.9T 1.5T 390G 80% /mnt/mountfoldername

Notice the last line here

To UnMount

$sudo umount //WindowsPC/Share1

Done πŸ™‚

References
Samba: HowTo Mount a CIFS Network Share [AKA Map Network Drive] in openSUSE 11 plus FAQs
Linux Mount CIFS shares that contain spaces in their share name
samba – Mounting a share with spaces in FreeBSD fstab – Server Fault

Advertisements

Author: Sanket Sonavane

Sanket Sonavane Software Developer, IoT Enthusiast, Photographer, Bike Rider, Chef, AndroidUser, MacOSXNewbie & 3x3x3 Cuber ;) Loves computers, programming, web developement, micro-controllers, gadgets, automation and many more such tech innovations that defines the way we live in the modern age and likes to explore what more can be done to help the human race :)

43 thoughts on “Mounting and AutoMounting Windows Shares on Raspberry Pi

  1. hi all, i had real problems with error 112 host is down and after some fumbling around discovered that its because i had disabled smb1, adding the option vers=2.0 got me connected πŸ˜‰

  2. For others who are struggling to get the share to mount automatically using fstab, enable the option in raspi-config for ‘wait for network on boot’ or otherwise it wont be able to find the share when it tries to mount it.

  3. Pingback: Raspberry Pi - Time Lapse Camera - Latenitetech

  4. If you can mount the windows share and read the files from it, but get “Permission denied” trying to write files to the windows share, use sudo. E.g. sudo cp pifile windowshare/windowfile

  5. Pingback: Raspberry Pi -Media Sharing | A Story of XY

  6. Many thanks for a great tutorial. I have struggled with mounts to windows shared and this tutorial did the trick.

  7. I am using readyshare and this doesnt seem to work, I was convincing myself it would…grr.. πŸ™‚
    using volumio or command line I cant seem to get my ready share to mount…
    I keep getting
    bad UNC errors, I have tried using slashes in all directions and seemingly all formats.

    so should this work with readyshare?

    the readyshare a 1tb usb drive in my router with no pw/un

    what im seeing/entering
    :
    root@ScottShop:~# sudo mount -t cifs -o guest //readyshare /mnt/readyshare
    mount error: could not resolve address for readyshare: Unknown error
    root@ScottShop:~# sudo mount -t cifs -o guest \\readyshare /mnt/readyshare
    mount.cifs: bad UNC (\readyshare)
    root@ScottShop:~# sudo mount -t cifs -o guest readyshare /mnt/readyshare
    mount.cifs: bad UNC (readyshare)
    root@ScottShop:~# sudo mount -t cifs -o guest //readyshare /mnt/readyshare
    mount error: could not resolve address for readyshare: Unknown error
    root@ScottShop:~# sudo mount -t cifs -o guest //readyshare /mnt/readyshare
    mount error: could not resolve address for readyshare: Unknown error

  8. Comment system stripped out useful characters from my previous answer. ’40’ should read [backslash][zero]40

  9. If you’re editing /etc/fstab and you have drive names, username, passwords, etc. which contain spaces and having trouble, you may want to try replacing the spaces with ’40’ as escaping backslashes and quotes doesn’t seem to be permitted in the fstab file

  10. I found this very helpful and have it working pretty well for the most part… the only problem I have is if I need to reboot my windows pc, after it is again up and running, the raspberry pi can no longer access the shared folder. I need to reboot the raspberry pi and then everything is good again. is there a command I can give to raspberry pi to re-do the shares? or better yet.. a way to make it auto re-connect if the windows pc is rebooted?

  11. sudo mount -t cifs -o username=yourusername,password=yourpassword //WindowsPC/share1 /mnt/mountfoldername

    This command does not work in my case, it does not give any error but does not give intended result either (I have not installed samba on pi may be thats why) . However if i replace “mnt” with “home/pi” it works like a charm.

    The same thing i experienced while setting up automount by editing fstab file, ans same solution worked for me here too.

    Also, i must use my windows machine’s local IP address instead of the “windowspc” as the commands fails to work if i use my system’s name. I dont know why is this happening but i would really appreciate if someone puts some light on this.

    Thanks to the author and all the creative minds here πŸ™‚

    Cheers!

  12. I am new to Raspberry Pi and wish to write an application using data from a Windows server. After a few abortive attempts at searching on Google eventually when I used Map Drives I got a hit. It took a few attempts to get through your notes mainly due to my poor typing but I am there and the perseverance was worth it. Thank you an excellent tutorial, keep them coming.

  13. Pingback: NRK2000

  14. Thanks for this! Helps a ton

    Mounting as a one off works. But I am having trouble with the automount. I do have a space in the name of the remote directory that I am trying to mount. I notice that part of the tutorial is blank. I’ve tried adding quotes (like the one-off mount), but still get errors.

    Any ideas? Thanks

  15. I had to add ,sec=ntlm after the password so that it worked, before that I got the following error:

    mount error(5): Input/output error
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

  16. If anyone is tetting the “mount error: could not resolve address for MYPCNAME: Unknown error”error, try using //MYPCNAME.local/share. I don’t know why but this worked for me. Stumbled upon it here: http://forums.devshed.com/linux-help-33/cant-ping-hostnames-ips-534040.html #4

  17. Hi,
    after sudo mkdir fra..
    when i access with guest mode…..sudo mount -t…… appear : couldn’t chdir to /mnt/fra: no such file or directory.
    Can you help me?

  18. Pingback: Raspberrypi How-tos | Hobbyist

  19. Great blog, thanks.

    One question if the windows computer is turned off but you have shares set to auto mount will the PI not run?

  20. Hi, thanks very much, this worked immediately.
    My share name has a space and I would like to automount, how do I do that – the section seems to be missing?
    Thank you.

  21. Pingback: Playing music on a Raspberry Pi using UPnP and DLNA (revisited) | Stephen C Phillips

  22. I am really impressed together with your writing abilities
    and also with the structure for your weblog. Is this a paid topic or
    did you customize it yourself? Either way keep up the excellent
    high quality writing, it is uncommon to look a nice blog like this one today.

    .

    • This is not a paid topic, all my articles are written by me, thanks for your feedback it encourages me to write more now

  23. @baboulobabas

    you need correct your sharing config for the folder. Add “Everyone” to the list of allowed users or use raspberry pi’s network name instead of everyone.

  24. Thanks alot, this made it so I didn’t need to use a SSH server in the MSBox.

  25. Hello, Neat post. There’s an issue with your website in web explorer, may test this? IE nonetheless is the marketplace leader and a big component of other people will pass over your magnificent writing because of this problem.

    • Thankyou for your comments but i need to look into this as i dont have much control over the wordpress blog as its not hosted by me.

      I will still try to look into it and check what can be done from my end. πŸ™‚

      Cheers

  26. Great now I cant even log in to the RPI!!! How do you fix a file you cant log in to get to?

  27. If you have a problem with error 13 Permission Denied when mounting the drive using cifs, try to add the username the following way:
    username=/username. If your computer is not in a domain, add the name of the machine or workgroup instead of domain.
    Good luck!

  28. Re-mount without reboot:

    $ sudo mount -a

  29. I did not work the PC name, just the IP adress.
    But i can’t write the disk. “permission denied”
    The read is working.
    The windows drive shared in full of right
    Windows version XP SP3, the drive is secondary, not windows boot

  30. Pingback: RasPi Samba Share mounten | Grosshirn

  31. doesn’t seem to work. I enter

    sudo mount -t cifs -o guest //GamePC/Users/user1/Downloads /mnt/gamepcmount

    and I get mount error(13) : permission denied

    I tried with the IP instead of the name. Same result.

    Shouldn’t I get an error message at least?

    Is there any difference if I am running windows 8?
    Homegroup is disabled.
    guest is enabled
    actually Everyone has acces to the folder

    what can I do?

  32. Really helped me setup file share to my RapberryPi. Works a charm! Many Thanks

  33. Pingback: Office window time-lapse | bish.co.uk

  34. I can’t mount my shares using the computer name, I have to replace the name with an IP address for it to mount. Also, isn’t putting a password in a text file unencrypted insecure?? How would I get the system to automount and prompt me for the share password and well as place a should cut to the share on the desktop once it is mounted???

    • The recommended way to do this is to create a credentials file in the /root folder and make permissions 600 to limit visibility to the root user.

      For example create a file /root/.smbcredentials, that has only 2 lines in it (no empty lines) with your details.

      username=XXXXXXXX
      password=XXXXXXXX

      Then in the fstab entry you specify the file as an additional option
      credentials=/root/.smbcredentials

  35. I can’t seem to get it… I’m getting an error:
    mount error: could not resolve address for MYPCNAME: Unknown error
    Any ideas what could be happening?

  36. Your comment system stripped that post of anything that was inside of greater than and less than brackets. sorry, check out this page for a clearer discription: http://en.gentoo-wiki.com/wiki/Samba#Clients

  37. The fstab file is not secure. Although it takes an extra step, put the login credentials in a separate file:

    fstab:
    /// / cifs credentials=/etc/, 0 0

    credentials file:
    username=
    password=

    Make sure you restrict access to the credentials file:
    chmod 600 /etc/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s