Using Sparse Bundle Images in Mac and Sharing them in Dropbox
In this article, we will discuss one way of sharing sensitive information over the Internet. Encrypting images on a Mac and sharing them with Dropbox is a popular way of sending files over the Internet.
Disk image sparse bundles work like virtual volumes that can be “mounted” and “unmounted” to house files. Disk images adjust their size according to the space required by the files they contain. In other words, their size is dynamic, which can be an advantage when using file-sharing solutions like Dropbox. Images can also be encrypted, another advantage when using Dropbox. The downside is that this type of image is only compatible with Macs.
Creating a sparse bundle image
There are many tutorials on the Internet on how to create this type of file. Basically, it works as follows:
- Open Disk Utility.
- Create a new blank image (see screen shot above).
- Enter the information on the disk image:
- “Save As”: the name of the encrypted disk image, here “spiria”. The full name of the disk image is therefore spiria.sparsebundle.
- “Name”: the name of the volume contained in the disk image, which will appear in the disks in Finder once it is “mounted”. In this example, “myDisk”.
- “Encryption”: since we’re paranoid, let’s choose the most secure option: AES 256 bit.
- Password: since you’ll have to enter it each time the disk image is mounted, better choose a password that is both secure and easy to remember and enter.
- Finally, choose the image format: “SparseBundle disk image”.
This procedure results in an encrypted image in which we can store files of up to 100 MB. The disk image will be automatically mounted. Before proceeding, let’s make sure we can unmount and remount the image.
To unmount an image volume, just click on the Eject button to the right of the volume name, in the sidebar of the Finder window:
Or, type the following in the terminal:
hdiutil eject /Volumes/myDisk/
To mount a disk image, simply double-click on the spiria.sparsebundle file and enter your password. Or, type the following in the terminal:
hdiutil mount spiria.sparsebundle
Managing insufficient disk space in a sparse bundle image
Sooner or later, you will ask yourself the following question: “My disk is full, how can I make it bigger?” There are at least two answers to this question. Let’s use the terminal and learn to use the hdiutil, which was briefly mentioned in the previous section.
Reclaiming free space in existing sparse bundles by recompacting files:
After a while, a disk image will tend to fragment. Disk images are cut up in blocks, and these blocks are not always optimally filled as the disk image gets used. To reclaim this wasted space, unmount the disk volume, then use the following command:
hdiutil compact spiria.sparsebundle
Increasing the size of a sparse bundle image:
If the first solution doesn’t do the trick, you’ll have to increase the size of the image. This non-destructive operation is risk-free. Use the following command:
hdiutil resize -size 300m spiria.sparsebundle
After execution, the disk image will be sized to 300 MB instead of 100 MB.
Partitioning a sparse bundle into several volumes
Sometimes, I’ve had to organize my work in several volumes within a disk image. This allowed me to enhance my filing and to avoid deleting files by mistake. This operation was very easy before El Capitan (OS 10.11). For some strange reason, the partitioning function of the disk utility no longer works with sparse bundle images. This means you’ll have to work with the terminal, with the following command (and explanation):
diskutil partitionDisk /dev/disk4 GPT JHFS+ MyFirstClient 100m JHFS+ MySecondClient 0 b
In this example, I partition my disk image (spiria.sparsebundle) twice over:
- “MyFirstClient”, size 100 Mb, to JHFS+ format.
- “MySecondClient” using all remaining space (0 b option), or 214 Mb in JHFS+.
- To find the disk number, in this case /dev/disk4, refer to the response to the execution of the hdiutil mount command:
Proceed with caution: the disk partitioning procedure is destructive! All data contained in the disk image will be lost.
Proceed with caution: the disk partitioning procedure is destructive! All data contained in the disk image will be lost
The best way to put a disk image in Dropbox is to mount the disk on the working Mac, do the work, then unmount the disk. This forces syncronization with Dropbox and ensures that other Macs will work with the latest version. Stray from this best practice at the risk of creating Dropbox syncronization conflicts, which must then be resolved.
Before resolving these conflicts, look at the structure of the image. To see the contents of a sparse bundle, you must show the contents of the package by right-clicking on the spiria.sparsebundle file and selecting “Show Package Contents”. This shows the “bands” directory, which lists every encrypted piece of the disk image. This is where you’ll see any conflicting images.
Voluntarily creating version conflicts in Dropbox
To create a conflict, simply ignore everything that has just been said. Here is my sure-fire way of creating a conflict:
- I create a text file on my “Colombo” Mac, save it, and unmount the disks to force Dropbox to syncronize. The text file contains the phrase: “My text on the Colombo Mac on Dropbox.”
- I syncronize Dropbox on my other Mac, “Wardell”, and mount the disk image. I also remount the disk image on Colombo.
- On Colombo, I edit the text file to: “My text on the Colombo Mac on Dropbox. (Edited).”
- On Wardell, I also edit the text file: “My text on the Colombo Mac on Dropbox. Wardell.”
- Dropbox detects a conflict and notifies it.
- I unmount the disk image on Wardell.
- I unmount the disk image on Colombo.
- I let Dropbox syncronize…
- I remount both disk images.
- => The version saved on both Macs is the Colombo version.
Solving a sparse bundle image version conflict in Dropbox:
At this point, you should make a copy of the disk image before attempting to solve the conflict. To do so, unmount the disk image and go to the bands directory (see how to access it above). Since we want to recover the Wardell Mac version, we need to replace the files which conflict with the Wardell files. This means deleting the “0” and replacing it with “0 (Wardell’s conflicted copy…)”. We must replace ALL conflicting files, since we do not know how the image and the bands directory files match up. This time-consuming, painstaking process can get you out of a desperate situation. After replacing the files, mount the disk image, recover the file and copy it in the right disk image, i.e. the one in Dropbox.
- Disk Utility (El Capitan): Partition a physical disk.
- Apple a massacré utilitaire disque dans El Capitan.