Oct 19, 2011

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.

written by dgraziotin

Dr. Daniel Graziotin received his PhD in computer science, software engineering at the Free University of Bozen-Bolzano, Italy. His research interests include human aspects in empirical software engineering with psychological measurements, Web engineering, and open science. He researches, publishes, and reviews for venues in software engineering, human-computer interaction, and psychology. Daniel is the founder of the psychoempirical software engineering discipline and guidelines. He is associate editor at the Journal of Open Research Software, academic editor at the Research Ideas and Outcomes (RIO) journal, and academic editor at the Open Communications in Computer Science journal. He is the local coordinator of the Italian Open science local group for the Open Knowledge Foundation. He is a member of ACM, SIGSOFT, and IEEE.

  • AlexFromBelgium Oct 24, 2011 Reply

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

  • Seth Feb 26, 2012 Reply

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

    • dgraziotin Feb 27, 2012 Reply

      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 ineed.coffee... to ineed.coffee[]: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

  • Andrés L. Pacheco Jun 6, 2012 Reply

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

  • Tom Jul 11, 2012 Reply


  • Bladtman Nov 22, 2012 Reply

    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.

    • dgraziotin Nov 24, 2012 Reply

      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!

      • Bladtman Feb 1, 2013 Reply

        I’ll be sure to put it up here if I make anything worthwhile 🙂

  • Jason Dec 2, 2012 Reply

    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?

    • dgraziotin Dec 2, 2012 Reply

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

      • Scott Mar 22, 2014 Reply


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

        Any ideas?

        • Paulo Silveira Apr 26, 2014 Reply

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


          • matthew Jun 14, 2015

            make sure you have the correct variable set for time capsule volume. to verify you can download the windows version of “airport utility” and open it with wine. once there go to manual setup-disk there you will see your time capsule volume.

  • Ingo Jan 7, 2013 Reply

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

  • Jason Jan 9, 2013 Reply

    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…

    • dgraziotin Jan 9, 2013 Reply

      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

  • João Feb 1, 2013 Reply

    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?

    • dgraziotin Feb 1, 2013 Reply

      Hello, did you install cifs-utils?

      • João Feb 1, 2013 Reply

        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

      • João Feb 1, 2013 Reply

        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!

        • dgraziotin Feb 2, 2013 Reply

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

  • Adam Feb 28, 2013 Reply

    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.

    • dgraziotin Feb 28, 2013 Reply

      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.

      • Adam Feb 28, 2013 Reply

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

  • Franco May 31, 2013 Reply

    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.

    • gary Jul 1, 2013 Reply


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


  • Stetson Jun 18, 2013 Reply

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

    How would I accomplish this part?

  • John Sep 3, 2013 Reply

    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!

  • Brady Sep 6, 2013 Reply

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

    • dgraziotin Sep 7, 2013 Reply

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

      • wershlak Sep 13, 2013 Reply

        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!

  • Roberto Marin Oct 4, 2013 Reply

    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

  • dgraziotin Oct 10, 2013 Reply

    Thanks wershlak and Roberto for the addition!

  • Erik van Oosten Nov 3, 2013 Reply

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

    apt-get install smbclient

  • Erik van Oosten Nov 3, 2013 Reply

    To escape the escaping see my gist: https://gist.github.com/erikvanoosten/7293883

    • dgraziotin Nov 3, 2013 Reply

      Thank you for providing this more elegant solution!

  • Erik van Oosten Nov 3, 2013 Reply

    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

  • Séb Nov 22, 2013 Reply

    Works on Slackware 14.1 : thank you very much !

    • dgraziotin Nov 22, 2013 Reply

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

  • valdez Dec 21, 2013 Reply

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

  • Pedro Apr 4, 2014 Reply

    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]#

  • pedro Apr 4, 2014 Reply

    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

    • dgraziotin Apr 5, 2014 Reply

      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.

  • Francesco Jun 28, 2014 Reply

    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?

    • dgraziotin Jul 7, 2014 Reply

      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.

  • James Oct 13, 2014 Reply

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

  • Gerry Nov 9, 2014 Reply

    Thank you so much mate, exactly what I needed.

  • Gonzalo Dec 14, 2014 Reply

    Thanks!!! Worked like a charm.

  • Wally Apr 5, 2015 Reply

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

  • milan May 1, 2015 Reply

    The main idea of your solution is great.
    I installed your script on LMDE with great expectations, everything passed well, but it does not works. I got the message as follows:
    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)

    I also tried to change the name of the Time Capsule, but without results.
    I will be thankful for solving this problem.
    Thanks in advance.

  • Wally May 5, 2015 Reply

    This is a wonderful script and works well when linked in /etc/init.d/ to run on startup, but I had noticed on sleep and resume that the timecapsule mount contents would disappear because the network connection would die.

    My fix is to add a script into: /usr/lib/pm-utils/sleep.d
    (These scripts run on sleep/hibernate and wake/thaw in Debian-based systems.)

    Here’s the script. I named the script “01timecapsule” so it executes near the beginning of the sleep process. Make sure it’s owned by root and has execute permission.

    • Gareth Jun 30, 2015 Reply

      Hello! thanks so much for your script, it works perfectly with my Airport Extreme & usb hard drive. I’m having a hard time figuring out where to put the script to run at startup because it requires sudo.

      I tried placing the script in /etc/init.d with no success
      I also tried putting the path in /etc/rc.local

      both with no joy.

      I’m very new to this – have any of you done this before?

      • dgraziotin Jun 30, 2015 Reply

        Hello. Suppose you have the script at /usr/local/bin/timecapsule-handler, and that it is executable sudo chmod +x /usr/local/bin/timecapsule-handler

        Then, you need to to put

        At the end of /etc/rc.local. This should be sufficient.

        • Gareth Jun 30, 2015 Reply

          oh wow! you hero! I honestly didn’t expect a reply so fast – I’ll give this a try and let you know the score 🙂

          Thanks again for your help 🙂

          • Gareth Jun 30, 2015

            So I tried adding the line to rc.local after double-checking the permissions.
            the script does not run at boot, but will always work if i manually type: sudo timecapsule-handler

            I’ve attached a screenshot that might help better explain what I mean:

            I imagine it’s something to do with the order things are starting up in, I’ll have a play with it later & see if I can find a different way to get it to start.

            Thanks again for taking the time to help, it genuinely is appreciated – good luck with the rest of your day 😀


  • dgraziotin Jul 1, 2015 Reply

    You are in the right direction.

    The script needs a network adapter properly configured (and connected) before the actual login to your desktop environment. This is not in the default settings of Network-Manager. However, I think I remember an option for making your connection settings global and active before the starting the desktop environment. Otherwise, you need to ask in the forums of your current Linux distribution for how to start a script (with sudo privileges) right after Network-Manager connects to a certain network.

    • Gareth Jul 21, 2015 Reply

      For those who find this thread after me.
      If you’re having the same issue I do with the network stack not running before rc.local starts
      sleep 30
      then your script location

      it’ll delay the next command by 30 seconds, allowing the system to start fully.

      Hope it helps the next person 😀

      Good luck everybody!

  • Fernando Schmidt Jan 6, 2016 Reply

    Does anyone know if it’s working in Raspbian Jessie ? I have the script in Raspbian Wheezy and works perfectly, but when I run the script in Jessie, nothing happens. I’ve tried both the solutions suggested by dgraziontin as by Erick van Oosten.

    • Fernando Schmidt Jan 20, 2016 Reply

      Okay, I made it work with the following line:
      sudo mount -t cifs //[myIP]/Data /mnt/timecapsule -o password=[mypass],sec=ntlm,uid=1000,gid=1000

      Does somebody know how to translate this to a /etc/fstab line so that it is getting automatically mounted?

      • Gareth Feb 4, 2016 Reply

        I’m sure it’s possible in fstab, that’s why I put it in my /etc/rc.local – I don’t know how to write fstab entries

  • Guilherme Aug 24, 2016 Reply


    In tests of smbclient, it works, but in mount.cifs its fail!!
    User and password are correctly, smbclient with password too run correctly. I can navigate in folders and files!

    #Ubuntu mate 16.04

Leave a comment