I wanted to setup a machine that would allow me to play music in my garage, as such I thought it would be a good exercise to use Ubuntu as I spend most of my life in Windows.
My music is on a windows machine at home currently and available via a windows share.
The Ubuntu installation of 14.04 was trouble free, and it sees the windows network straight away and I was able to browse around the windows share.
However it was not particularly easy to add these network shares to my playlist in either Rhythmbox or Clementine media players. It must be said that I made certain assumptions that because I could see and browse and play music from the network, after a vanilla install of Ubuntu, I thought everything was in place to access these folders. This is not the case
I wanted a easier a method, and this appeared to be mounting the windows share within Ubunutu permanently. To be honest it sounded straight forward however I encountered a few hurdles and I want to detail here what I did to get this up and running. I have pulled together a few articles/forum posts into this posting. I include these references at the bottom of this page.
In Ubuntu you can mount drives via the mount command, and you can do that manually every time you reboot, however if you want to get it to mount automatically then you need to add commands to the /etc/fstab (file system table) file, which is read by the mount command every time you reboot.
Note: I got confused, being from windows CIFS is an older variation of SMB, and as such is frowned upon. However using cifs in linux seemed to be recommended, eventually I believe this is just a naming issue. It seems that the smbfs is an older deprecated module, and that the current smb/cifs module for ubuntu is called cifs, however it supports current mordern variations of smb (inc 3.02). So by using the vers=3.02 in the options section of the mount command I was able to force SMB version. (I was connecting to a windows 8.1 machine, hence why I could use 3.02).
As I said a number of items are not installed by default which caused me issues when trying to mount. These were
Netbios - name resolution
(not sure if this is needed but its one of the hoops I jumped through)
sudo gedit /etc/nsswitch.conf
hosts: files wins dns
Save the file.
CIFS (smb access)
Now we add the mount commands to the /etc/fstab file. Now we can include the username and password as free text in this file, and that may be acceptable in most home scenarios. But we can put the credentials in a seperate file and then restrict access to that file to help protect the contents. This credential file can then be refernced in the mount commands.
Note: ~ here is short hand for /home/, now whilst ~ works in the command line you will find it does not always work within files. Therefore you will see later on we expand ~ fully in fstab.
In .smbcredentials enter these two lines, replacing and for the windows username and password
Save this file.
Lets create the folder where we want to mount the windows share. I used the /media/ folder
Ok, now we will enter the commands for the mount command into the fstab file. When Ubuntu is booting it will run these lines against the mount exe.
sudo gedit /etc/fstab
Add the following line (note: you can ommit vers=3.02 and it will default to smb1, however if you know the correct smb vers for your windows machine you should be able to specify it here)
// / /media/Mount cifs credentials=/home/ /.smbcredentials,iocharset=utf8,sec=ntlm,vers=3.02 0 0
Save the file
Now we can force the mount command to rerun all commands in the fstab file
sudo mount -a
Now everything being good, we should be able to access the windows share under the mount point we created.
In addition the mount should be available after a reboot.
Troubleshooting
I kept getting the following message whenever I tried to mount, this was because I had not installed the CIFS UTILS (again I made the assumption because I browse the network everything was already installed).I believe you can get this message for a number of reasons and the best way to figure it out is to use the command it suggests dmesg | tail
References
https://wiki.ubuntu.com/MountWindowsSharesPermanently
https://help.ubuntu.com/community/MountWindowsSharesPermanently
https://wiki.samba.org/index.php/LinuxCIFSKernel
https://wiki.samba.org/index.php/Samba3/SMB2
https://www.thomas-krenn.com/en/wiki/Mounting_a_Windows_Share_in_Linux
http://stackoverflow.com/questions/74626/how-do-you-force-a-cifs-connection-to-unmount
My music is on a windows machine at home currently and available via a windows share.
The Ubuntu installation of 14.04 was trouble free, and it sees the windows network straight away and I was able to browse around the windows share.
However it was not particularly easy to add these network shares to my playlist in either Rhythmbox or Clementine media players. It must be said that I made certain assumptions that because I could see and browse and play music from the network, after a vanilla install of Ubuntu, I thought everything was in place to access these folders. This is not the case
I wanted a easier a method, and this appeared to be mounting the windows share within Ubunutu permanently. To be honest it sounded straight forward however I encountered a few hurdles and I want to detail here what I did to get this up and running. I have pulled together a few articles/forum posts into this posting. I include these references at the bottom of this page.
In Ubuntu you can mount drives via the mount command, and you can do that manually every time you reboot, however if you want to get it to mount automatically then you need to add commands to the /etc/fstab (file system table) file, which is read by the mount command every time you reboot.
Note: I got confused, being from windows CIFS is an older variation of SMB, and as such is frowned upon. However using cifs in linux seemed to be recommended, eventually I believe this is just a naming issue. It seems that the smbfs is an older deprecated module, and that the current smb/cifs module for ubuntu is called cifs, however it supports current mordern variations of smb (inc 3.02). So by using the vers=3.02 in the options section of the mount command I was able to force SMB version. (I was connecting to a windows 8.1 machine, hence why I could use 3.02).
As I said a number of items are not installed by default which caused me issues when trying to mount. These were
- winbind - netbios name resolution
- cifs util - provides a helper for connecting to smb shares
Netbios - name resolution
(not sure if this is needed but its one of the hoops I jumped through)
sudo apt-get install winbind
Then we need to tell Ubuntu to use wins lookup, we do this by editing a file that dictates how and in what order Ubuntu will attempt name resolution. Open the /etc/nsswitch.conf file, look for the line that starts hosts: and add wins prior to dns.sudo gedit /etc/nsswitch.conf
hosts: files wins dns
Save the file.
CIFS (smb access)
sudo apt-get install cifs-utils
Now we add the mount commands to the /etc/fstab file. Now we can include the username and password as free text in this file, and that may be acceptable in most home scenarios. But we can put the credentials in a seperate file and then restrict access to that file to help protect the contents. This credential file can then be refernced in the mount commands.
gedit ~/.smbcredentials
Note: ~ here is short hand for /home/
In .smbcredentials enter these two lines, replacing
username=
password=
Save this file.
Lets create the folder where we want to mount the windows share. I used the /media/ folder
sudo mkdir /media/
Ok, now we will enter the commands for the mount command into the fstab file. When Ubuntu is booting it will run these lines against the mount exe.
sudo gedit /etc/fstab
Add the following line (note: you can ommit vers=3.02 and it will default to smb1, however if you know the correct smb vers for your windows machine you should be able to specify it here)
//
Save the file
Now we can force the mount command to rerun all commands in the fstab file
sudo mount -a
Now everything being good, we should be able to access the windows share under the mount point we created.
In addition the mount should be available after a reboot.
Troubleshooting
I kept getting the following message whenever I tried to mount, this was because I had not installed the CIFS UTILS (again I made the assumption because I browse the network everything was already installed).I believe you can get this message for a number of reasons and the best way to figure it out is to use the command it suggests dmesg | tail
mount: wrong fs type, bad option, bad superblock on //windowsserver/share, missing codepage or helper program, or other error (for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.helper program) In some cases useful info is found in syslog - try dmesg | tail or so
References
https://wiki.ubuntu.com/MountWindowsSharesPermanently
https://help.ubuntu.com/community/MountWindowsSharesPermanently
https://wiki.samba.org/index.php/LinuxCIFSKernel
https://wiki.samba.org/index.php/Samba3/SMB2
https://www.thomas-krenn.com/en/wiki/Mounting_a_Windows_Share_in_Linux
http://stackoverflow.com/questions/74626/how-do-you-force-a-cifs-connection-to-unmount