How to automatically mount and umount Apple Time Capsule on Linux

How to automatically mount and umount Apple Time Capsule on Linux

Even though you may not own a Macbook, an iPhone/iPad or any other Apple device, you might still be the owner of a Time Capsule. I bought it when I was using a Macbook Pro. Time Capsule is wonderfully integrated with the various Apple devices and machines. Unfortunately, it becomes a pain to use Time Capsule under you boot GNU/Linux.

It is possible to manually mount a Time Capsule Volume on a directory. It is uncomfortable, isn’t it? Using Time Machine clones such as Déjà Dup, flyback or TimeVault becomes difficult. They may be automatically started by your Desktop Environment. However, they may give errors because of the still unmounted Time Capsule Volume.

  • What if the mount point (e.g. /mnt/timecapsule) exists but it is empty because of the non-mounted Time Capsule? Such backup programs would backup in our hard disk!
  • We could create a script th7at mounts Time Capsule on login.
    What if we don’t always use our laptop at home? There must be a way to discover if a Time Capsule is present on the current network and mount it.
  • The Time Capsule Volume must be unmounted when we logout, otherwise there will be an error if we are connected to a Wireless Network. Network volumes are sometimes unmounted after Network Manager is stopped, under some configurations.

I decided to handle these issues with a script, called timecapsule-handler (Download, gzip).

How to Download, Configure, and Run

I wrote this section especially for those unfamiliar with the GNU/Linux console. It is written keeping Ubuntu as reference distribution.
Experienced users may use any GNU/Linux distribution and they only need to know that:

  1. cifs-utils is needed in order to use the script
  2. The script should be under your $PATH and be invoked with root privileges (sudo)
  3. The script must be called just after network setup and before network teardown. Time Capsule likes clean umount.

First, download the script.

Edit the configuration variables with a text-editor. For your convenience, here is how to edit it with Ubuntu default graphical text editor:

You need to set values for the first three variables:

Save the file, give it execution permissions and move it in a directory under your $PATH (e.g., /usr/local/bin).

Install the required cifs-utils package.

That’s it. Here is how to use the script.
To mount Time Capsule, run:

To un-mount Time Capsule, run

Yes, it automatically detects everything.

How does it work?

Let’s observe it:

At line 31, we simply look if Time Capsule is already mounted, by calling the mount command. Typically, it will return something like:

See the last line of the command? In line 31 of the script we search in the output of the mount command the string $MOUNT_POINT (e.g, /mnt/timecapsule).

Then, between line 34 and line 36, if Time Capsule Volume is mounted, we umount it and delete the mount point using rmdir to be sure to protect data if the umount is unsuccessful.

Otherwise, between line 37 and line 42, we use the smbclient program to do a sort of ping of the device on the Network. If there is someone at the given IP, and this someone replies with something like “I am Time Capsule!”, we are sure to mount it. This is a typical output of the smbclient program:

The program gives a result within a second, that’s because the script is so fast in doing its job.
There may still be issues with my script. However, it would not do anything harmful to the system and fail silently in case of errors.

I hope that you may find it useful. Please report your experience in this post comments.

If for any reason the script does not work, I encourage you to try this older version.

About the Author

Daniel Graziotin is a doctoral researcher in Computer Science at the Free University of Bozen-Bolzano. His research interests include human aspects in empirical software engineering with psychological measurements, Web engineering, and Open Science. He is Editorial Associate at the Journal of Open Research Software and the local coordinator of the Italian Open science local group for the Open Knowledge Foundation. He is a member of the ACM, SIGSOFT, IEEE, and the IEEE Computer Society.


  1. Hey man.
    Thanks for the script! I’m going to test it out tomorrow.
    I’ll let you know how it goes!

  2. You accidently gzipped the file twice. After running gunzip on the download, I needed to append “.gz” and run gunzip again.

    • Thank you for the report. This is quite strange, because
      $ wget /wp-content/uploads/2011/10/timecapsule-handler.gz--09:18:17--  /wp-content/uploads/2011/10/timecapsule-handler.gz           => <pre class="decode:1 inline:true " >timecapsule-handler.gz'Resolving to[]:80... connected.HTTP request sent, awaiting response... 200 OKLength: 893 [text/plain]100%[========================================>] 893           --.--K/s             09:18:17 (8.52 MB/s) -timecapsule-handler.gz’ saved [893/893]

      aeshma:tm dgraziotin$ gunzip timecapsule-handler.gz
      aeshma:tm dgraziotin$ ls
      aeshma:tm dgraziotin$ file timecapsule-handler
      timecapsule-handler: Bourne-Again shell script text executable

  3. Thanks much, pal! your script worked like a charm, excellent and very simple!

  4. Brilliant!

  5. That’s pretty cool.
    I’m probably going to steal this for auto mounting usb drives without a DE as well :)
    Just have to find out what kind of events are fired on usb plugging/unplugging.
    Anyway; a nice read, thanks.

    • Sure you can steal it. Just remember to respect its license ;)

      I guess the most simple plan is to learn some udev rules.
      See this related superuser question.

      If you come out with a nice idea, share it with the rest of the world. Good luck!

      • Thanks.
        I’ll be sure to put it up here if I make anything worthwhile :)

  6. Thanks for this script!! I can’t believe Apple left us high and dry.

    I can’t get it to work though. I keep getting messages saying

    “sh timecapsule-handler
    mount error(13): Permission denied
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)”

    why does it hate me?

    • Are you calling the script either as root user or by appending sudo before it?

      • Hey.

        Nice work, though I’m also having this issue. Appending sudo before script call.

        Any ideas?

        • I Have the same problem? Do you have any solution?


  7. Great script man! Thanks! Care putting it on GitHub or so where it will be persistent for generations of users to come :-)?

  8. This is a great and much needed project, but I’m in some hot water over it.

    At first I ran it and the program seemed to work, though I could never get it to mount the time capsule. My disk was located at /, which is what I indicated in the file. After some time, I realized that though I could not seem to access the time capsule within Linux, after running timecapsule-handler I could see it in my Windows virtual machines that run within linux. So that was great news.

    The probablem now is that I restarted the computer and it stops in the middle of booting every time now with a black screen. Nothing happens unless I press a function key, at which point it says

    mount.cifs: bad UNC (/
    mountall: mount /media

    and that’s it. I’ve tried about 100 things to recover, including SystemRescueCD, SuperGrubDisk 2, and Rescatux…

    • I have never tested this script on a virtual machine. Is this error still happening on the virtual machine?
      According to your description, I image the following settings:

      Is this what you are using?
      Are you running the script after the network has been setup? Are you also running it on shutdown before the network is taken down?
      What happens if you unplug your time capsule and try to boot Linux?

      Hope this helps

  9. Hello, I’m trying to make this work on my ubuntu (so i can get rid of w7 for good) but i can’t get it done. I filled my TIme Caspule configs and tried to run sudo timecapsule-handler – it tells me “command not found” or if i i’m under root it tells “Permission denied”.

    I’m a newbie in linux… could anyone give a little help?

    • Hello, did you install cifs-utils?

      • Yes, after that i stucked.

        Actually i forgot to mention two things: first, the link for the script is broken (it doesn’t extract), i had to download fro github and then i could write de configs. Two: I’m using wubi under windows 7 (it’s a shame, i know)

        Thanks in advance

      • I did it! I was reading around about linux terminal commands, and about the ctrl+alt+F1 shortcut. So i went to the “text-only” mode and tried again with sudo… After that, i just opened mnt and there it is! Beautiful…

        Thanks for the script man, it’s THAT good!

        • Glad it worked for you as well!
          Regarding the script hosted on my website: it works for me, strange..

  10. I’m having the same problem Joao had. I followed all of the instructions and when I run “sudo timecapsule-handler”, “sudo: timecapsule-handler: command not found” is returned. I’m new to linux and am unsure how to get this working. Thanks for the help in advance. I did install cifs-utils.

    • Now I get it! I was not clear enough in my post. I assumed that people reaching the post would have been familiar with the terminal. The issue is not having the script in your $PATH.

      The script must have execution permission. Run the following command while being in the same folder where timecapsule-handler is.

      In order to use the script just by calling its file name (the sudo timecapsule-handler command), you must move timecapsule-handler in a directory included in your $PATH (e.g., /usr/bin/ and /usr/local/bin).

      Otherwise, to run the script you have to be in the same directory where the script is and run:

      You can also provide the full path where the script is

      I updated the post to clarify this. Hope it fixes your issue.

      • Thanks for the help! That fixed it. People like you are why I’m a linux user now.

  11. thanks dgraziotin for the scipt , it work for me in ubuntu 12.10 but when I tried to used it in ubuntu 13.04 the script didnt work. so I add a sec=ntlm to the script and works fine in 13.04
    so the last four line of the modified script are:

    I take a while figure it out for me looking in the web. hope this will help others.

    • Franco,

      You are correct, the sec=ntlm helped me out. Without that I can’t write to the folder on fedora 16.


  12. “The script must be called just after network setup and before network teardown. Time Capsule likes clean umount.”

    How would I accomplish this part?

  13. Man, this is great! You saved me hours of work.

    I was running into an issue when while trying to mount my time capsule as a NAS, but for some reason Ubuntu Server 12.04 kept throwing the error:

    Retrying with upper case share name
    mount error(6): No such device or address
    Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

    The way I was trying to mount it was this:
    sudo mount.cifs // /media/capsule -o pass=password

    Your script probably does something else to make this work. I’ll have to have a closer look at it later. Anyway, thanks for this awesome script!

  14. Just an FYI. This script does not work for Fedora 19

    • Thank you for reporting this. You could be even of more help if you provide eventual error messages you receive.

      • I had to add the above mentioned “sec=ntlm” after the password in the mount command for it to work in fedora 19. There were no other issues.

        Thanks for the script!

  15. Very nice man.

    Working on Ubuntu 13.04, just need to add “sec=ntlm” on the line of the mount, like that:

    echo “mount.cifs $TIMECAPSULE_PATH $MOUNT_POINT -o pass=$TIMECAPSULE_PASSWORD,file_mode=0777,dir_mode=0777,sec=ntlm” | /bin/bash

  16. Thanks wershlak and Roberto for the addition!

  17. You also need smbclient. With Ubuntu 12.04 this is not installed with cifs-utils.

    apt-get install smbclient

    • Thank you for providing this more elegant solution!

  18. The addition of “,sec=ntlm” to the options is also required in more recent 12.04 versions.

    In case you can’t find the volume name, start the air-port utility on your mac and look under ‘disks’.

    Proper quoting prevents the need for escaping of special characters. Here’s my version of the script:

    TIMECAPSULE_IP=""                         # e.g. ""TIMECAPSULE_VOLUME="/Time Capsule"        # also try "/Data"export PASSWD='YOURPASSWORDHERE'          # No need to escape anything (except "'")MOUNT_POINT="/mnt/timecapsule"            # no need to create the directoryIS_MOUNTED=<pre class="decode:1 inline:true " >mount 2> /dev/null | grep "$MOUNT_POINT" | cut -d' ' -f3

    if [[ “$IS_MOUNTED” ]] ;then
    umount $MOUNT_POINT
    rmdir $MOUNT_POINT
    CHECK_TIMECAPSULE= smbclient --no-pass -L "$TIMECAPSULE_IP" 2>&1 > /dev/null | grep -m1 -i apple
    if [[ “$CHECK_TIMECAPSULE” =~ “Apple” ]] ;then
    mkdir “$MOUNT_POINT”
    mount -t cifs “$TIMECAPSULE_PATH” “$MOUNT_POINT” -o file_mode=0777,dir_mode=0777,sec=ntlm
    unset PASSWD

  19. Works on Slackware 14.1 : thank you very much !

    • I have just switched to Slackware 14.1 as well. Happy to hear that it works for you!

  20. Wow, thanks!
    I am embarrassed to say how much time I chased this problem….
    You saved me.

  21. what did I do wrong?

    [root@centos bin]# timecapsule-handler
    mkdir: cannot create directory /mnt/timecapsule': File exists
    /bin/bash: line 1: unexpected EOF while looking for matching

    /bin/bash: line 2: syntax error: unexpected end of file
    [root@centos bin]#

  22. config file:

    TIMECAPSULE_IP=”″ # e.g. “”
    TIMECAPSULE_VOLUME=”PEDRO’s Time Capsule/Data” # also try “/Data”
    TIMECAPSULE_PASSWORD=”passw” # prefix special characters, e.g. \!
    MOUNT_POINT=/mnt/timecapsule # no need to create the directory

    IS_MOUNTED=mount 2> /dev/null | grep "$MOUNT_POINT" | cut -d' ' -f3

    if [[ “$IS_MOUNTED” ]] ;then
    umount $MOUNT_POINT
    rmdir $MOUNT_POINT
    CHECK_TIMECAPSULE=smbclient --no-pass -L $TIMECAPSULE_IP 2>&1 > /dev/null | grep -m1 -i apple
    if [[ “$CHECK_TIMECAPSULE” =~ “Apple” ]] ;then
    mkdir $MOUNT_POINT
    echo “mount.cifs $TIMECAPSULE_PATH $MOUNT_POINT -o pass=$TIMECAPSULE_PASSWORD,file_mode=0777,dir_mode=0777,sec=ntlm” | /bin/bash

    • Try to escape PEDRO’s -> PEDRO\’s.

      Otherwise, try to rename your Time Capsule to something simpler, e.g. “TIMECAPSULE” and change the config file to use the simpler name.

  23. Hi, nice job and thank you very much for this script! I have just one more problem: run this script automatically at the login and logout. Is it possible?

    • Sure! Just follow any tutorial regarding running programs and scripts at login/logout for your desktop environment. For example, see autostart for KDE here. Just remember that the script needs root privileges when run. See this as an example.

  24. Thanks! Worked like a charm. I’d spent hours trying to do this manually on Raspbian but kept getting error(13) permission denied.

  25. Thank you so much mate, exactly what I needed.

  26. Thanks!!! Worked like a charm.

  27. Mate, I’ve been trying to figure this out for the last 12 months. This is bloody amazing! THANK YOU!


Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">