The Photos app on the Mac has two options for storing your photos. You can tell it to keep the full-size originals of everything, or you can have it self-manage, keeping your master library in iCloud and storing a mixture of full-resolution and low-res versions locally to save space.
The trouble is, even when you choose the “Optimize Mac Storage” option, the Photos app’s storage can metastasize and take over your whole drive. Today we’ll see how to cap this storage, giving Photos a hard limit on how much space it can use. For instance, if you have a MacBook with a 128GB SSD, you could choose to only use 30GB for Photos — and it will never, ever use more.
Use a sparse disk image to limit Photos storage
This trick comes by way of Marco Arment on Episode 334 of the Accidental Tech Podcast. You can listen to the tip at the one-hour, 38-minute mark.
To limit the Photos library, we’re going to create a sparse disk image, set it to mount at login, and move the Photos library file onto it. A disk image is like a virtual disk on your Mac. Even though it is actually just a file on your internal Mac SSD, it appears as an external disk.
Just like any other removable drive, the disk image can be mounted and ejected. You specify its size when creating it, and it carves out that space from your SSD. The other advantage of a locally stored disk image is that it is just as fast as the SSD it sits on.
A sparse disk image is the same thing, only it takes up less space — for a while. Say you create a 30GB sparse disk image, and then drag a 1GB file onto it. The image will only take up 1GB space. That’s the magic of the sparse image. You specify its maximum size, but in use, it stretches and shrinks to the size of the files stored on it.
Create a sparse disk image
So, step one is to create a sparse disk image. Actually, that’s the second step. The first step is to make sure you have a proper local backup of your photo library.
On your Mac, open up the Disk Utility app, and choose File > New Image > Blank Image from the menu (or type ⌘N). Then, make sure it looks something like this:
I created a small 100MB image for testing. You should make it the size you want to limit Photos to. Don’t worry about it taking up your whole drive. My 100MB image is just 7.3MB on disk. Yours will be similar, until you start adding files. Make sure you choose the Sparse Disk Image option. Save it somewhere easy to find, like in your Pictures folder.
Create it, and the disk will be created, and the mount itself. Just make sure that it is big enough to hold the current library, plus extra for future expansion.
Add the sparse image disk to your login items
Next we add the disk to login items, so that it mounts whenever you start up your Mac. This is essential. If you don’t do this, Photos won’t be able to find your library. And remember, Photos downloads images from iCloud even while the app itself isn’t running.
To add the sparse image to your login items, open System Preferences, then click on Users & Groups. Click on your own name, and drag the image file from your Pictures folder into the Login Items section. That’s it.
Move your Photos library to the sparse disk image
Next, we perform the final step — moving your Photos library. Apple has an official guide for this part. It’s meant for moving your Photos library to an external drive, but it works the same way when using a disk image. Just quit the Photos app, locate the library file (in your Pictures folder, by default), and drag it to the newly mounted disk. The disk will show up in the Finder’s sidebar or on the desktop (or both).
This is the only tricky part of the plan, because you will be copying the file, not moving it. This means you will have to have enough space on your SSD for both versions. Or maybe you won’t. The APFS file system on modern Macs lets you create copies of files without using up any extra space. All those “copies” are just instances of the same file, markers that point back to the one master file on your disk. (I don’t know if this applies to disk images.)
Once the copy is complete, double-click the new Library file, and it will open in Photos. If you have any errors, check the Apple Support article for help. It should just work, though. Once you verify that everything works properly, delete the original Photos library. That’s it. You’re done. Now, the optimized library can never grow larger than the box you’ve planted it in.
Caveats about this method of Photos library management
There are a few things to watch out for. This is not a supported way to use your Photos library, so perhaps odd things might happen. Also, if you’re running macOS High Sierra, you should read this blog post from Carbon Copy Cloner developer Mike Bombich. It details a bug that can cause data loss on an APFS sparse disk image.
Otherwise, this is a neat trick. Use it to make sure your Photos library can never again run out of control.