Troubleshooting SAMBA Shares

SAMBA is the CIFS/SMB sharing server embedded into OpenELEC. From time to time people post in the forums saying "SAMBA isn't working, now I can't connect to shares on my HTPC" or "I can only connect to my HTPC using its IP address" so the purpose of this article is to educate people on what's going on. The statement that SAMBA is broken is rarely true. It's usually running fine, and the cause of the problem is simply the horribly ugly way that NetBios over TCP/IP name resolution works in Windows!

The reason you cannot see an \\OPENELEC\Share "that was working 5 mins ago" is down to browser election fights between the computers on the network. An election fight is a peer-to-peer negotiation over who gets elected to be in charge of the domain(s) and/or local master browser list which is the list of computer names that will appear in the Windows Network Neighbourhood (or it's current equivalent). The machine that wins the election is determined through a combination of uptime, OS version and config settings. This masterful piece of design ensures the outcome is often unpredictable and the election process can take time (minutes not milliseconds) and while it takes place your ability to browse the network is broken. Over time your HTPC often becomes the longest uptime device and has probably been elected as the machine in charge of the master browser. If you reboot your HTPC the browser list is destroyed and the remaining machines on the network start an election process to decide who owns the replacement and what the new list will contain. Once the election is over it will take time (again, minutes not milliseconds) to distribute the list and ensure every client has the same version. If you reboot other computers (often trying to rectify the disappearance of machines resulting from the HTPC being rebooted) they will re-join the network and announce their availability causing the election process to restart all over again, hence the appearance of the machine "fighting" each other. It's easy to see how this process may go round in circles for "some time" before things stabilise. Sadly, Mac and Linux computers suffer from the same browser-election purgatory as Windows machines as they (via the embedded SAMBA server) are ultimately participating in the same ridiculous election process.

In corporate networks this issue is mitigated by having a domain controller server. An election process still takes place, but the domain controller is configured to always win so the process is consistent and the election process completes faster. The good news is that it's simple to configure the SAMBA server on your OpenELEC based HTPC to always win the election and become the master browser. The reason for picking the HTPC to be the master browser is that it's probably the going to be the computer with the highest uptime in your home network. If you have NAS boxes that are always running they are also good candidates to be the master machine and the same idea below can be set in their SAMBA configs as well. Just remember that there should be only ONE master browser and things are okay.

First you need to create /storage/.config/samba.conf. There is a sample one in the directory that can be renamed. Then add the lines indicated below to your [global] section:

[global] server string = Media Centre(%i) workgroup = HOME domain master = yes <-- add this line local master = yes <-- add this line preferred master = yes <-- add this line os level = 100 <-- add this line netbios name = OPENELEC security = share guest account = root socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536 wins support = yes syslog only = yes name resolve order = lmhosts wins bcast host printcap name = /dev/null load printers = no

Even if you do this the problem will never be completely eliminated as each computer that joins the network will cause an election, but Windows network browsing should become a lot more stable. If things have become very messed up the best solution is to "turn everything off and on again" so that the old (incorrect) browser list is lost and a new (correct) one is created. The failsafe way to access your HTPC is to use it's IP address, e.g. \\192.168.1.2\ perhaps in combination with local 'hosts' file entries if you prefer \\NAME\ formats.

If you don't want your HTPC to become the master browser it is also possible to rig an existing Windows computer to be the master browser. For more information please read this article