Can Linux mount a normal Time Machine sparse bundle disk image directory?

31

13

I am looking to see if Linux can mount and read the files natively stored on a Time Capsule over a network share. Like this question, I am looking for something that replicates at least read-only function of hdiutil to attach and then mount a sparse bundle disk images.

The SMB mount is easy since the Time Capsule shares using both AFP and SMB, but I'm not so sure the sparse disk bundle can be mounted as the reconstituted HFS+ directory.

Bonus points for a working mount command or pointer to the appropriate package that parses this DMG format.

In case it's not clear - this is how the band files look to me when mounted from a Mac in Terminal and what I expect Linux to see without the ability to mount the actual file system that is encoded in a multitude of binary band files.

host:iMac.sparsebundle mike$ ls -la
total 24
drwxrwxrwx@     7 mike  staff      264 Jul  5 10:01 .
drwx------      6 mike  staff      264 Mar 26 13:11 ..
-rwxrwxrwx      1 mike  staff      499 Feb 24 15:33 Info.bckup
-rwxrwxrwx      1 mike  staff      499 Feb 24 15:33 Info.plist
drwxrwxrwx  31101 mike  staff  1057390 Jun 17 20:19 bands
-rwxrwxrwx      1 mike  staff      532 Jun 24 22:06 com.apple.TimeMachine.MachineID.plist
-rwxrwxrwx      1 mike  staff        0 Feb 24 15:33 token
host:iMac.sparsebundle mike$ ls -la bands | head -10
total 1582092552
-rwxrwxrwx  1 mike  staff  8388608 Jul  5 08:33 0
-rwxrwxrwx  1 mike  staff  8388608 May 31 13:02 1
-rwxrwxrwx  1 mike  staff  8388608 Jun 24 22:16 10
-rwxrwxrwx  1 mike  staff  8388608 Mar 19 17:15 1000
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 10000
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 10001
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 10002
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 10003
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 10004
host:iMac.sparsebundle mike$ ls -la bands | tail -10
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:51 fff6
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:51 fff7
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:51 fff8
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:51 fff9
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:51 fffa
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 fffb
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 fffc
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 fffd
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 fffe
-rwxrwxrwx  1 mike  staff  8388608 May 31 00:50 ffff
host:~ mike$ ls -la bands|wc -l
   96636

bmike

Posted 2011-07-05T13:14:25.687

Reputation: 2 773

Why do you need to "mount" the sparsebundle? Linux should see it as a directory, just cd in to it once the volume where your Time Machine backups are being stored is mounted on Linux. – Ian C. – 2011-07-05T13:25:36.837

1Thanks Ian C - I edited the question to clarify what I'm looking for - the raw data is all there, just not stored in a more readable format that is most useful for reading a specific file from a specific point in time. – bmike – 2011-07-05T14:03:46.067

Answers

34

You may use a combination of these two:

FUSE filesystem for reading Mac OS sparse-bundle disk images

Apple's Time Machine fuse read only file system

The first takes care of the .sparsebundle format, presenting it as a dmg file, which can then be mounted like normal. The second takes care of the directory hard-links used by Time Machine.

Tor Arne Vestbø

Posted 2011-07-05T13:14:25.687

Reputation: 456

I couldn't mount the dmg out of the box so I also had to use darling-dmg which mounted it via FUSE. – Praxeolitic – 2017-03-12T21:32:07.427

This should be the accepted answer. tmfs did the job for me perfectly on Debian 7.0. – Gordon Bailey – 2013-05-10T16:14:54.007

I thank @GordonBailey for pinging me to this - I missed the notification that another answer was provided. – bmike – 2013-06-22T18:35:05.720

4

This is an extension to the answer by @TorArneVestbø.

Once you have installed https://github.com/torarnv/sparsebundlefs and https://github.com/abique/tmfs you need to run the following script in Bash. Make sure to update the two variables at the beginning to be the source and destination.

SB="/path/to/your/Backup.sparsebundle"
TM_MNT="/path/to/where/to/mount"

# Make directories
mkdir -p "$TM_MNT"
SB_MNT=`mktemp --tmpdir -d sparsebundle_mnt.XXX`
SB_DMG="$SB_MNT/sparsebundle.dmg"
HFS_MNT=`mktemp --tmpdir -d hfsx_mnt.XXX`

# Mount the sparse bundle
sudo `which sparsebundlefs` "$SB" "$SB_MNT"

# Mount the HFS+ partition
OFF=`sudo parted "$SB_DMG" unit B print | tr 'B' ' ' | awk '/hfsx/ {print $2}'`
SZ=`sudo parted "$SB_DMG" unit B print | tr 'B' ' ' | awk '/hfsx/ {print $4}'`
LO=`sudo losetup -f "$SB_DMG" --offset $OFF --sizelimit $SZ --show`
sudo mount -t hfsplus -r "$LO" "$HFS_MNT"

# Mount the Time Machine filesystem
sudo `which tmfs` "$HFS_MNT" "$TM_MNT" -ouid=$(id -u $USER),gid=$(id -g $USER),allow_other

The final mount will be accessible by you (as long as $TM_MNT is accessible to you). The final line may fail if FUSE is not setup to allow other user, it tells you how to fix it.

To unmount you need to do the following:

sudo umount "$TM_MNT"
sudo rmdir "$TM_MNT"
sudo umount "$HFS_MNT"
sudo rmdir "$HFS_MNT"
sudo losetup -d "$LO"
sudo umount "$SB_MNT"
sudo rmdir "$SB_MNT"

This was tested on a Fedora 28 system and is working well.

thaimin

Posted 2011-07-05T13:14:25.687

Reputation: 343

3

Apple's Time Machine fuse read only file system

https://github.com/abique/tmfs

tomislav

Posted 2011-07-05T13:14:25.687

Reputation: 149

4What's the purpose of this answer? Does it do anything? Are we to guess it even answers the question? You'll need to unpack what the purpose of this even is and how it fixes the problem – random – 2011-11-06T16:59:46.667

3

The above post, from Alexandre Bicque, provides a Linux (?unix) program that will open a Time Machine sparsebundle stored on a Mac-formatted HFS+ disk or disk partition, allowing reading of the files on a Linux server.

Getting it set up isn't for the faint-hearted. It's written in C++ and requires 3 C++ libraries - cmake, FUSE, and Boost, with certain minimum versions (which may not be default latest versions for my Ubuntu Server 10.04.) It also requires finding and installing a g++ compiler and the above libraries.

I use Ubuntu server 10.04 and am not much of a programmer. However, after a fair bit of work and time, I did manage to install all the necessary libraries, compile and link the tmfs package, and use it. It does work, allowing mounting a TimeMachine Time Capsule. HOWEVER, it does require that the disk on which the sparsebundle image is written be an HFS+ disk or partition. It won't work if the image is written on an NTFS or ext2/ext3/ext4 file system on a Linux server.

As of Apple's OS X 10.7 (Lion), Time Machine (sparsebundle) images will no longer work if mounted on a Windows (smb/Samba) Linux share, and it's necessary to run Linux/Unix Netatalk (afpd plus avahi-daemon) services to use Linux as a Time Machine server.

I've done a lot of looking for another solution. I suspect that a Linux/Unix C++ programmer could do better than have I, extending Alexandre Bicque's work to allow the use of ext4 or ntfs file systems. I'm trying to figure out how to do it, but have a long way to go.

I think it will require that I understand much better the fuse (user-space file system) and perhaps the boost::filesystem system development helpers in order to move forward.

Rod Prior

Posted 2011-07-05T13:14:25.687

Reputation: 31

AFAICS, currently no requirement for HFS+ exists for either of tmfs. The description mentions HFS, but the steps described will work anyway. – Blaisorblade – 2013-06-17T01:41:57.940

2

Unfortunately the path to finding things in a sparsebundle from Linux is not straightforward. It can be done, but it requires interpreting some inode information that Apple embeds in the hardlinks to find the actual file in the sparsebundle. This MacWorld hint describes how you go about figuring out where a hardlink in a sparsebundle points to in terms of the actual file so you can access it from a Linux system. It deals with a Time Machine disk that's been attached as a local disk to a single machine.

In your case <mount point>/Backups.backupdb is most likely <machinename>.backupdb`.

I'm not sure whether <mount point>/.HFS+ Private Directory Data exists in the same spot for a shared disk being used for Time Machine backups by multiple machines. You'll have to do a little ls -la inspection of the disk and sparsebundles to find that.

But otherwise those MacWorld instructions will help you retrieve files on a Time Machine bundle, from Linux.

A update regarding the mount point.

I did some experimenting based on your updated question. It looks like the mount point should be the *.sparsebundle directory and not the drive. If I mount the drive in OS X and the go to /Volumes/Remote Backups/mymachine.sparsebundle I see the bands directory like you do and it's useless.

But if I mount mymachine.sparsebundle such that I can go to /Volumes/Time Machine Backups (that's what it mounts as automatically in Finder when I double click on the mymachine.sparsebundle) I see the expected Backups.backupdb directory and under that the date-time directories as expected.

Ian C.

Posted 2011-07-05T13:14:25.687

Reputation: 5 383

thanks for the answer, but I'm not seeing the same file structure as you. I don't get Backups.backupdb since that is encoded inside the band files. Since it takes so long to enumerate that directory in raw form, I ran a ls | tee /tmp/bands to capture the output. I have 96636 binary files, most of them 8388608 in size. I have no issue getting around the backup structure once it's turned into a file system by mac's disk utility and then re-shared. I just can't figure how to process the bands on linux without OS X system to re-share the file system. – bmike – 2011-07-05T14:57:52.167

@bmike: try mounting the *.sparsebundle file as a hfsplus filesystem on Linux instead of the remote drive. Similar to what happens if you open the .sparsebundle on your Mac and you end up with a /Volumes/Time Machine Backups volume on OS X. Updated answer with more detail. – Ian C. – 2011-07-05T19:02:25.977

On Linux you can't mount directly sparsebundle files, unlike Mac OS X. – Blaisorblade – 2013-06-17T01:44:05.387