Saturday, March 3, 2012

Setting up Time Machine and Netatalk 2.2.2 on Ubuntu 11.10

    This was the biggest pain to setup and get working that I have yet encountered with Ubuntu 11.10. There is a small mountain information available on the internet on how to do this, yet none if it worked. I followed all of the guides and searched "man pages" for almost two weeks before I found the the proverbial keys to the kingdom. What follows is everything I learned from weeks of trial and error.

    Before we get started, it is important to understand what I was trying to. I have been using Ubuntu 11.10 for a while now as a file server (using Samba) and as a Plex media server. Until recently everything was working just fine. I was able to share folders using Samba that let me copy new media to my server with relative ease. However, I was running low on disk space and really wanted to include space for both my wife and I's Mac's to use use Time Machine for backup.

    To accomplish this I purchased a 3TB hard drive and installed it in the Ubuntu server. I set it up for sharing as I normally would, and followed the various guides for how to do this with sparse bundle files. This was a disaster. With the production of osX Lion, Time Machine now requires the use of the Apple File sharing Protocol or AFP. The functional difference is fairly simple. When connecting to the server you use afp://<ip-address> instead of smb://<ip-address>. Sounds simple doesn't it.

    It wasn't. Not by a long shot.

    You see, there are few pieces of software that are not installed by default when you first install Ubuntu on your machine. You will need to do the following from the command line on your Ubuntu machine:

    sudo apt-get install <package name>

    The following packages will need to be installed with the above command:

    libdb4.7-dev     (Berkeley v4.7 Database Libraries [development])
  libgcrypt11      (LGPL Crypto library - runtime library)
  avahi-daemon     (Avahi mDNS/DNS-SD daemon
  tcpd             (Wietse Venema's TCP wrapper utilities)
  netatalk         (AppleTalk user binaries)

    Install all of the above onto your Ubuntu machine using the apt-get command from above. Contrary to what I have read, you do not have to uninstall or disable Samba in any way. Samba works just fine along side of Netatalk and Avahi.

    The version of Netatalk that you get from the "default" repository is (as of this writing) version 2.2.4~beta. If you are not comfortable using "beta" software, you can download the source for version 2.2.2 (the version I am using) from here. You can download on to your mac, unzip it and then copy the folder to you linux box to a convent directory to work from. Before you jump right in to things:

    ITS A TRAP!

    Sorry, that was just to get your attention. You see, once again Ubuntu 11.10 does not come with the correct software to make software from source code. Oh it sure seems like it does, but according to this article from Ubuntu it doesn't. If you don't want to click the link here is what to do:

    sudo apt-get install build-essential checkinstall
  sudo apt-get install cvs subversion git-core mercurial 
  sudo chown $USER /usr/local/src
  sudo chmod u+rwx /usr/local/src


    You are now ready to build from source. I put my "netatalk-2.2.2" folder in ~/Downloads, it was just an easy folder since it was already setup to be a shared folder under Samba. Using a terminal, navigate to the netatalk-2.2.2 folder. Enter the following command:

    ./configure --enable-debian
 
    You should now have a configuration that looks like:

./configure --enable-debian output

    Next enter the following from the command line:

    make
    sudo make install 

    This will build and install netatalk-2.2.2.

    Once you are either done building from source or you installed from the package manager, its time to start configuring. First, navigate to /usr/local/etc/netatalk and enter the following command:

    sudo nano afpd.conf

    This will open the file afpd.conf in a text based text editor. Don't worry, all of the commands you need are listed at the bottom of the terminal window. You need scroll to very last line of the file and make sure it reads exactly as follows: (make sure the is no "#" character at the beginning.

    - -tcp -noddp -uamlist uams_randnum.so,uams_dhx.so,uams_dhx2_passwd.so -nosavepassword

    It was the uams_dhx2_passwd.so that was tripping me up for so long. It was this trouble ticket on ask Ubunutu that finally solved it for me. But, we are not done yet. Next we need to add all of the "shares" to the afp server. To do this, in Terminal type:

    sudo nano AppleVolumes.default

    Once again, scroll all the way to the end of the file. You will see this line that start and ends with a tilde ( thats "~" character ). If you want to have access to your "User Home Folder" on your linux box, change this line to read:

    ~ "Home" allow:UserName cnidscheme:dbd options:usedots,upriv

    If not, delete this line instead.

   To explain how this line works, the "~" in the folder name on the Ubuntu machine that is to be shared. The "Home" you change to whatever you want. This is what shows up to other computers on the network as the folder name. The "allow:UserName" you change "UserName" to the user name that you use to login to your Ubuntu machine. The rest of the line (for now) is unimportant, just make sure all of the rest is there.

If you want to share more folders or drives you can do that too. My 3TB hard drive is partitioned into two 500GB partitions and one 2TB partition. (Actually, due to the space the file system takes up it's 1.8TB but that is really unimportant). These partition are mounted as:

    /media/files  (The 1.8TB partition)
    /media/tm1    (One of the 500GB partitions)
    /media/tm2    (The other 500GB partition)

    To make sure my Mac's on my network can access them via AFP, and thus use time machine, on the very next line (directly under the '~ "Home" ' line, enter the following lines:

    /media/files "Files" allow:UserName cnidscheme:dbd options:usedots,upriv

    /media/tm1 "Time Machine 1" allow:UserName cnidscheme:dbd options:usedots,upriv,tm
    /media/tm2 "Time Machine 2" allow:UserName cnidscheme:dbd options:usedots,upriv,tm

   Notice the "tm" at the end of options. This allows TimeMachine to see the folders as usable across the network. Don't try it yet; we are not done yet. 

    That is all we need to do to configure netatalk, now we need to configure Avahi. Avahi is basically a Name-Server for netatalk. It also shows you a nice icon in the Finder window for your server. You will be creating a new XML file that will control Avahi. Enter the following command from Terminal:

    sudo nano /etc/avahi/services/afpd.service

    Create the XML file as follows:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=Xserve</txtrecord>
</service>
</service-group>

    Save and exit nano. We are almost done. With this file the way it is, you Finder icon on your mac for your Ubuntu server will be for an Apple Server. If you wish to change this, you can replace "Xserve" with the following options: Macmini, iMac, MacPro, Xserve, MacBook, MacBookPro,MacBookAir as needed or wanted. 

    Almost done. Now, in Terminal enter the following commands:

    sudo service netatalk restart
    sudo service avahi restart

    From your Mac, open a Terminal and enter the following connamd: 

    defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

    This line enable your Mac's Time Machine to view available TimeMachine folders on network shared drives. 

    To test everything, from your Mac, open a finder window and you should see your server on left pane under "SHARED". That means Avahi is working. To test netatalk we do two tests. For test one, select the  Finder menu item "GO -=> Connect to server". Enter "afp://<username>@<ip-address of Ubuntu server>" You can also omit the "<username>@", you will just have to manually enter your Ubuntu user name in the login window. 

    If it works, and you can browse folders, eject the connection. There is an "eject" button next to the server name in the left pane of the Finder window. Now double-click the name of the server. You will be asked to log in again. Once again, enter your Ubuntu login information. Assuming everything is working you can now open Time machine and click "Select Drive". Your two drives "tm1 and tm2" from the Ubuntu server should now show up as "Time Machine 1" and "Time Machine 2". Select one and start the backup process. 

    That it! All done! 

    I hope this has been helpful to someone out there. It took me a while to ferret out all of the details of working with Ubuntu 11.10, osX Lion and osX Snow Leopard. It took longer than expected, but now that I know how to do all of this, I will be able to re-create it, and I have learned where on the internet to search for information. happy networking and until next time ...