Update: 2013-02-28 Post updated to include instructions for beginners
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.
Additionally,
- 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:
- cifs-utils is needed in order to use the script
- The script should be under your $PATH and be invoked with root privileges (sudo)
- The script must be called just after network setup and before network teardown. Time Capsule likes clean umount.
First, open a terminal, download and unzip the script:
|
1 |
wget http://task3.cc/wp-content/uploads/2011/10/timecapsule-handler.gz && gunzip timecapsule-handler.gz |
Edit the configuration variables with a text-editor. For your convenience, here is how to edit it with Ubuntu default graphical text editor:
|
1 |
gedit timecapsule-handler |
You need to set values for the first three variables:
|
1 2 3 4 |
TIMECAPSULE_IP="" # e.g. "192.168.1.100" TIMECAPSULE_VOLUME="/Time\ Capsule" # also try "/Data" TIMECAPSULE_PASSWORD="YOURPASSWORDHERE" # prefix special characters, e.g. \! MOUNT_POINT=/mnt/timecapsule # no need to create the directory. No " here |
Save the file, give it execution permissions and move it in a directory under your $PATH (e.g., /usr/local/bin).
|
1 |
chmod +x timecapsule-handler && sudo mv timecapsule-handler /usr/local/bin |
Install the required cifs-utils package.
|
1 |
sudo apt-get install cifs-utils |
That’s it. Here is how to use the script.
To mount Time Capsule, run:
|
1 |
sudo timecapsule-handler |
To un-mount Time Capsule, run
|
1 |
sudo timecapsule-handler |
Yes, it automatically detects everything.
How does it work?
Let’s observe it:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#!/bin/bash # # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. # # Version 2, enhanced for Ubuntu 12.04 and Ubuntu 12.10 # Runs on all GNU/Linux distros (install cifs-utils) # Author: Daniel Graziotin <dgraziotin AT task3 DOT cc> - http://task3.cc # Purpose: Check if there is a TimeCapsule in your network and mount it # for use it under Gnu/Linux. Unmount it if it is already mounted. # The mount point is created and destroyed after use (for prevent # automatic backup software to backup in the directory if the device # is not mounted) # Instructions: # 1) Install cifs-utils (sudo apt-get install cifs-utils) # 1) Change the first four variables according to your configuration. # 2) Run this program at boot when your network is already # set up. Also, run it on logoff to umount Time Capsule. TIMECAPSULE_IP="" # e.g. "192.168.1.100" TIMECAPSULE_VOLUME="/Time\ Capsule" # also try "/Data" TIMECAPSULE_PASSWORD="YOURPASSWORDHERE" # 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` TIMECAPSULE_PATH="//$TIMECAPSULE_IP$TIMECAPSULE_VOLUME" if [[ "$IS_MOUNTED" ]] ;then umount $MOUNT_POINT rmdir $MOUNT_POINT else 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" | /bin/bash fi fi |
At line 31, we simply look if Time Capsule is already mounted, by calling the mount command. Typically, it will return something like:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
$ mount proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) sys on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,relatime,size=10240k,nr_inodes=195863,mode=755) run on /run type tmpfs (rw,nosuid,nodev,relatime,size=10240k,mode=755) /dev/sda1 on / type ext4 (rw,noatime,nodiratime,discard,errors=remount-ro,commit=0) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) shm on /dev/shm type tmpfs (rw,nosuid,nodev,relatime) tmpfs on /tmp type tmpfs (rw,nosuid,nodev) fusectl on /sys/fs/fuse/connections type fusectl (rw) gvfs-fuse-daemon on /home/dgraziotin/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=dgraziotin) //192.168.0.2/Time Capsule on /mnt/timecapsule type cifs (rw) |
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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ smbclient --no-pass -L 192.168.0.2 Anonymous login successful Domain=[WORKGROUP] OS=[Apple Base Station] Server=[CIFS 4.32] Sharename Type Comment --------- ---- ------- IPC$ IPC Anonymous login successful Domain=[WORKGROUP] OS=[Apple Base Station] Server=[CIFS 4.32] Server Comment --------- ------- Workgroup Master --------- ------- |
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.
















Hey man.
Thanks for the script! I’m going to test it out tomorrow.
I’ll let you know how it goes!
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
=>
timecapsule-handler.gz'Resolving task3.cc... 94.75.235.227
Connecting to task3.cc[94.75.235.227]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 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
timecapsule-handler
aeshma:tm dgraziotin$ file timecapsule-handler
timecapsule-handler: Bourne-Again shell script text executable
Thanks much, pal! your script worked like a charm, excellent and very simple!
Brilliant!
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
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?
Great script man! Thanks! Care putting it on GitHub or so where it will be persistent for generations of users to come
?
Sure, here it is: https://gist.github.com/4487187
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 /10.0.1.1/Disk, 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 (/10.0.1.1/Disk)
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
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..
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.