Locally mounting Samba shares on Ubuntu

Viewing a Windows network file share on Ubuntu is easy enough. In the Places menu, click Network, then Windows Network, then the computer you want to look in, and so on and so forth.

Only programs that use GNOME’s virtual file system framework (gnome-vfs) will be able to directly open files over the network like this – Gedit, Totem Movie Player, Evince (PDF viewer) etc (incidentally, gnome-vfs does more than samba; you can also treat things like remote FTP and SFTP/SCP folders this way). Things like VLC, Firefox etc can only see files on the local filesystem, so network shares have to be mounted locally for them. This is done using smbfs.

Make a directory to mount each share you want, or just one to mount the root directory of every share of the remote machine. I wanted to mount two different shares, so here’s what I did:

sudo mkdir /media/smbfs
sudo mkdir /media/smbfs/video
sudo mkdir /media/smbfs/music

Install smbfs:

sudo apt-get install smbfs

And mount shares like so:

sudo mount //mezzanine/video /media/smbfs/video -o username=guest,password=
sudo mount //mezzanine/music /media/smbfs/music -o username=guest,password=

I use simple file sharing on my Windows machine, so network shares require no authentication, but smbfs expects it; setting the username to “guest” and leaving the password blank suffices. Of course if your shares do require user/pass, that’s where you’d specify them (leaving “,password=” off will make it prompt you for a password on the command line).

To mount these shares when the system boots, you need to add them to the filesystem table, /etc/fstab. Only root can write to this, so:

sudo nano (or gedit) /etc/fstab

And at the end of the file, add:

# my smbfs shares:
//mezzanine/video /media/smbfs/video smbfs username=guest,password= 0 0
//mezzanine/music /media/smbfs/music smbfs username=guest,password= 0 0

The first line with the # is a comment, to serve as a reminder for what the following few lines are for. The two numbers at the end are to do with filesystem maintainance; they really don’t matter for this.

Once they’re in fstab, by the way, they can be unmounted and remounted using just sudo mount (or umount) /media/smbfs/mountname after booting.

One Response to “Locally mounting Samba shares on Ubuntu”

  1. Jeremy says:

    I initially used that approach as well, but I found that my system became unstable if the network went down, and it had pending reads/writes to the remote share.

    I now either use SMBFS over automount (so it doesn’t have to come up on bootup, and automatically dismounts) or I use SSHFS, which uses FUSE, which seems to be more tolerant of network interruptions for some reason.

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>