For backup purposes, I needed to automatically mount a network share from a Windows computer on startup. I hoped that Ubuntu would make this seemingly common need to taken care of, but it’s not – there’s some work involved. So let’s get to it.
Let’s ensure the things we need are installed already. Run these commands to make sure you have
sudo apt-get install samba
sudo apt-get install smbfs
It’s likely you have Samba already, and you probably don’t have smbfs, so that’ll be downloaded and installed for you.
Make sure your sharing computer is actually setup to share. I’ve done this so many times – I thought I set a computer to share a folder and it wasn’t correct. On Linux, making a folder shared is normally enough, but make sure you do not allow guests as they’ll cause strange problems. Always login. Please.
If you’re going to be sharing from Windows, you’ll need to go into some advanced preferences. Let’s say you have a MyFolder and you want it shared. Right click and go to properties. Go to sharing. Don’t you dare click share, you must click Advanced Sharing… instead. Now click the check box and then hit the permissions button below. There should be an Everyone group already there, if there isn’t, you have a problem that’s out of this walkthrough’s scope. Anyway, if it’s there, select it and then click on the Full Control check box below. Once done, click on Ok, Apply and Ok and Ok again. You can close that now. You have shared your folder.
Finally, if you have installed the Windows Live Essentials, you will have yet another step. You may have installed the Windows Live Sign In Assistant with the essentials bundle – if you did, you’ll need to uninstall it. It may even just come with Windows, who knows.
It’s time to edit your fstab file. I strongly suggest doing a
sudo cp /etc/fstab /etc/fstab.backup for safety reasons.
Fire up your favorite terminal editor, but I’m using vim:
sudo vim /etc/fstab. Move down a to some empty lines in the file. Get ready.
To mount your share, you’ll need to provide an address. I’ve only done it with host names, but apparently IP address work too. Then, you’ll also need a mounting point. My preference is
/mnt/sharing_computer/share_name but it’s up to you. Then, you’ll need to setup the username and password. If you’re worried about having passwords in plain text, well, I’m trying to find a better way actually, myself.
Anyway, here’s the syntax:
//computer_name/share_name /mnt/sharing_computer/share_name cifs username=theusername,password=thepassword,auto,rw 0 0
Write that into the file with your details. Then save it. Now, go to your mounting location. You’ll need to make the directories you specified in the fstab. So if you did what I suggested, that would be,
sudo mkdir /mnt/ryan-desktop/school-docs. Then you should be set.
But there’s one more thing. If you’re on Windows, or you going through an established Windows based network, you’ll need to look at your hostname. It seems to be case sensitive, so you’ll have to watch out for that. You might consider restart your linux machine now, after your fstab has been edited. Why? Well, you want to see if your share auto-mounts. If it does, great and if not – well, I don’t know. Maybe you missed something above or you’re unlucky. I can’t really help that much if things don’t work out, sorry.
Honestly, I’m not a Guru, I hardly know what I’m doing half the time. These steps have worked for me in the past and they might work for you in the future. This was tested on and is still used on a Ethernet connected Ubuntu 10.04 machine. Your mileage will vary.