Enable SAMBA server
Contents
Introduction
SAMBA is an ethernet based service which allows an AppleTV to share files and printers.
This how-to bases on the AwkwardTV forum SMB in reverse.
Prerequisites
This method bases on the installation via SSH. Following this method, the extracting and editing commands will work directly on the AppleTV.
Installation
The installation bases on the MacPorts project and its Samba package. The idea is to install a SAMBA service on an Intel Mac and copy it to the AppleTV. Luckily, you won't have to do this yourself, as the result is downloadable.
- Copy it to your AppleTV via
scp
or Fugu to/Users/frontrow/Documents/
.
- Login and assume higher privileges (if prompted for password, enter the password for frontrow ):
ssh frontrow@AppleTV.local sudo -s
- OPTIONAL STEP: If you don't have much space in the '/' file system you may want to do this
mkdir /mnt/opt ln -s /mnt/opt /opt
- Extract it:
tar -xvjpf /Users/frontrow/Documents/samba3_macports_bin.tar.bz2 -C /
Note: the above only works if you have installed bunzip2 on your AppleTV. If not, then extract it using bunzip2 on your Mac and then copy the tar file to the AppleTV. In this case, eliminate the "j" from the tar command string -- it should be "tar -xvpf ....."
If you just untar the file, make sure you have changed to "/opt" folder.
Configuration
Configuration file
The server configuration is found in /opt/local/etc/samba3/smb.conf
.
Edit it:
cp /opt/local/etc/samba3/smb.conf.sample /opt/local/etc/samba3/smb.conf nano -w /opt/local/etc/samba3/smb.conf
Note: if you have not installed nano on your AppleTV this will not work. In this case, edit the file on your Mac and then transfer it to the AppleTV.
Editing the configuration can be a tedious process. The simplest thing to do is to modify the proper part in order to have:
[homes] comment = Home Directories browseable = yes writable = yes
By default these modifications will enable to you mount only your "frontrow" homefolder. If you would like to be able to mount let's say your USB drive, you need to add something like this in the bottom of the file:
[USB] comment = USB Drive path = /Volumes/USB Drive name valid users = frontrow public = no writable = yes printable = no
Password
The SAMBA passwords are different from the user login ones.
Give the user frontrow
a password:
sudo /opt/local/bin/smbpasswd -a frontrow
Change Service File Permissions
sudo chown root:wheel /opt/local/sbin/smbd sudo chmod 4555 /opt/local/sbin/smbd sudo chown root:wheel /opt/local/sbin/nmbd sudo chmod 4555 /opt/local/sbin/nmbd
Service
The service is now ready to be started:
/opt/local/sbin/smbd -c /opt/local/etc/samba3/smb.conf /opt/local/sbin/nmbd -c /opt/local/etc/samba3/smb.conf
Test if from your Mac's Finder menu: Go -> Connect to Server... (Cmd-K)
,
give the server address smb://AppleTV.local
and follow the indications.
The chosen directories are mounted on /Volumes/
.
You can unmount them from there, either from the Finder or from the Terminal.
Automatic loading at boot
All three of the following options accomplish the same thing in different ways.
Using launchd
Automatically loading the Samba service at boot can be done by launchd
by defining two LaunchDaemons.
- Login to the AppleTV and navigate to the user startup items location:
ssh frontrow@AppleTV.local sudo -s
- Create a file
/System/Library/LaunchDaemons/org.samba.smbd.plist
with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.samba.smbd</string> <key>OnDemand</key> <false/> <key>ProgramArguments</key> <array> <string>/opt/local/sbin/smbd</string> <string>-c</string> <string>/opt/local/etc/samba3/smb.conf</string> </array> <key>RunAtLoad</key> <true/> <key>ServiceDescription</key> <string>samba</string> </dict> </plist>
- Then create a file
/System/Library/LaunchDaemons/org.samba.nmbd.plist
with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.samba.nmbd</string> <key>OnDemand</key> <false/> <key>ProgramArguments</key> <array> <string>/opt/local/sbin/nmbd</string> <string>-c</string> <string>/opt/local/etc/samba3/smb.conf</string> </array> <key>RunAtLoad</key> <true/> <key>ServiceDescription</key> <string>samba</string> </dict> </plist>
Unmount the Samba shares, restart the AppleTV and try mounting them again.
Using rc.local
Automatically loading the Samba service at boot can be done with the help of /etc/rc.local
.
Create or edit the file and add the commands from the following listing:
# rc.local # For AppleTV 2.0.1 (2.0.0?) you may need to uncomment the following line to remount hard disk read/write # mount -uw / # start the SAMBA service /opt/local/sbin/smbd -c /opt/local/etc/samba3/smb.conf /opt/local/sbin/nmbd -c /opt/local/etc/samba3/smb.conf
Unmount the Samba shares, restart the AppleTV and try mounting them again.
Defining a startup item
Let's define a Shares
startup item:
- Login to the AppleTV and navigate to the user startup items location:
ssh frontrow@AppleTV.local sudo -s cd /Library/StartupItems/
- Create the folder defining the startup item and go inside it:
mkdir Shares cd Shares
- Create the
Shares
startup item script (the name must match the directory):
#!/bin/sh ## # Share control ## . /etc/rc.common samba_path='/opt/local' service_name='Network Shares' StartService () { echo "Starting $service_name" $samba_path/sbin/smbd -c $samba_path/etc/samba3/smb.conf $samba_path/sbin/nmbd -c $samba_path/etc/samba3/smb.conf } StopService () { echo "Stopping $service_name" } RestartService () { StopService sleep 2s StartService } RunService "$1"
- Grant read,execute permission to
Shares
:
sudo chmod 555 Shares
- Create the
StartupParameters.plist
definition:
{ Description = "Network Shares"; Provides = ("Network Shares"); Requires = ("Disks"); }
Unmount the Samba shares, restart the AppleTV and try mounting them again.