A Time Machine backup on my network had started taking three to four and a half hours just to mount. Not to back up, just to attach the drive image before anything else could happen. Cancelling didn’t stop it. The only way out was force-unmounting the share. It looked exactly like a hang.
It wasn’t. But getting to the bottom of it meant trusting a disk-image tool to safely convert several terabytes of backup history, and that went wrong in two ways I didn’t expect. One of them I hadn’t seen before: parts of the new copy simply came out as zeros, with no error message, no warning, nothing in any log.
The setup
First, why back up over the network at all. With a USB drive, the Mac only gets backed up while the drive is plugged in, so backups happen when I remember to connect it. Then I have to remember to eject it before unplugging, and a forgotten eject is how you end up with a drive that needs repairing. Mine also used to drop off USB now and then while it was mounted, which is worse. With the drive left on another Mac and the backup going over the network, none of that is my job any more: Time Machine backs up every hour on its own, and nobody pulls a cable in the middle of a write.
There are two ways to back up a Mac with Time Machine to a disk on another machine over SMB. The built-in one is a shared folder marked as a Time Machine destination (on a Mac, the folder’s advanced File Sharing options have a “Share as a Time Machine backup destination” checkbox). Time Machine then handles everything itself: for every backup it mounts the share, attaches its own sparsebundle image from it, backs up, then detaches and unmounts again.
The other way is what I had: a sparsebundle image sitting on a plain SMB share, which I attach myself, by double-clicking it or with hdiutil attach. Once it’s attached, the volume inside shows up like any other disk, and Time Machine backs up to it as if it were a local drive. The image stays attached between backups.
The backup in question is a Time Machine sparsebundle disk image sitting on a large external HDD attached to one Mac, reached over SMB by the Mac being backed up. Ten terabytes of virtual size, about 3.7 TB actually used. Every attach starts with macOS listing all of the image’s band files, the fixed-size chunks a sparsebundle is made of, before anything else happens.
That listing step was the three-to-four-and-a-half-hour wait. Not a network problem. The image had 444,659 band files at the default 8 MiB band size, and the external drive turned out to be badly seek-bound, around 150 reads per second. Listing nearly half a million files on a drive that slow is going to take hours no matter what’s on the other end of the network connection. A local listing of the same files, run directly on the Mac holding the drive, was just as slow with a cold cache. SMB wasn’t the bottleneck; the disk was.
Why 8 MiB bands in the first place
8 MiB is simply hdiutil‘s default band size. It isn’t what Time Machine itself chooses when it builds a network backup image of this size. When modern Time Machine creates an image on a network destination, it picks the band size so the band count stays at or under 16,384; for an image of about 3.7 TB that means 256 MB bands, not 8 MiB.1 In other words, the existing image hadn’t been built the way Time Machine would build one today; something upstream of this had used hdiutil‘s defaults instead. Fixing the band size to match what Time Machine itself would have chosen meant the band count would drop from hundreds of thousands to under fourteen thousand, which should make the listing step trivial.
The rule of thumb worth keeping in mind for anyone sizing a sparsebundle by hand: stay well under 100,000 bands, roughly image size divided by 50,000 gives the smallest band size worth using.2
Is this your problem?
If your Time Machine image over SMB takes a long time to attach, check its band size first. It’s in the bundle’s Info.plist, which is quick to read even when the bundle itself is slow:
plutil -p "/path/to/Your Backup.sparsebundle/Info.plist"PlaintextLook at band-size. A value of 8388608 is 8 MiB, the hdiutil default. Divide the space the backup uses by the band size to get a rough band count: a few terabytes at 8 MiB means hundreds of thousands of band files, and every attach has to list them all. Don’t list the bands folder to count them; on a slow drive that listing is exactly the slow part.
If the image was created by a recent Time Machine on a network destination, it most likely has big bands already, and the slowness is coming from somewhere else. Images made by hand with hdiutil, or carried over from an older setup, are the ones to suspect. In the built-in SMB mode a high band count hurts even more, since Time Machine attaches the image for every single backup.
The fix
The conversion itself is a single hdiutil command, run on the Mac the drive is plugged into rather than over the network:
hdiutil convert <source-bundle> -format UDSB -tgtimagekey sparse-band-size=524288 -o <destination-bundle>PlaintextOn this drive it copies at about 20 MiB/s, so 3.7 TB of real data meant roughly two days.
A note on that command: on a current macOS, hdiutil convert, attach, create and detach print a warning that they’re deprecated and point you to diskutil image instead (diskutil image create from for convert, diskutil image attach for attach, diskutil eject for detach). They all still work. I stayed with hdiutil convert because diskutil image create from can write a sparsebundle but has no option to choose its band size, and the band size was the whole point. For attaching, diskutil image attach --readOnly --noMount does the same job as hdiutil attach -readonly -nomount.
The first trap: it writes zeros out to the full virtual size
I expected the conversion to copy the 3.7 TB that’s actually in use and stop. It doesn’t. hdiutil convert walks the whole ten-terabyte virtual disk from start to end and writes every band, whether or not the source ever had data there. Once it gets past the real data, every band it writes is a full 256 MiB file of zeros, and those zeros take up real space on the drive. Its progress percentage counts against the whole 10 TB as well, so the real data was all copied by about 37 percent, and everything after that was zeros. Left alone, it would have kept writing zeros until it reached the end of the virtual disk, about 10 TB in all, on a drive with 4.8 TB free. I stopped it at about 42 percent, once it was clearly writing nothing but zeros.
Removing the zeros without breaking the image
Starting over wasn’t appealing: two more days of copying, and the same zero fill waiting at the end. So the question became whether the partial copy could be trimmed into a valid image. It could, because of how a sparsebundle works. The image is a folder of band files, and a band that doesn’t exist reads back as zeros. Deleting a band file that holds nothing but zeros leaves the disk inside the image exactly as it was, as if that stretch had simply never been written.
The steps, in order:
- Stop it in a way that keeps the output. I tested on a throwaway image first that force-killing
hdiutil convert(SIGKILL) leaves the bands it has already written in place, and that the image still attaches afterwards. - Find where the real data ends. The old image’s own band list answers that: its last data band sits about 3.73 TB in, so every new band past that point should be padding. One exception: the old image also had a single band at the very end of the 10 TB, which the conversion never reached.
- Prove each band is padding before deleting it. Every byte of all 1,895 bands past that point was read and checked. Not one of them held a single non-zero byte. Only then were they deleted, 508 GB in all.
- Copy the missing last band through macOS, not by hand. Both images were attached without mounting, and that last stretch was copied from one raw disk device to the other. The disk-image driver then writes the band file and updates the bundle’s bookkeeping itself (the newer format keeps a second folder,
mapped, next tobands), so I never had to edit the bundle’s internals. - Check the result. The trimmed image attached fine, the volume inside had the same ID as the original, and the
mappedfolder had no entries left pointing at deleted bands. The checks that compare actual content come in the next section.
The rule that keeps this safe: only delete a band you’ve read in full and found to be all zeros, and never edit a band file or the bookkeeping by hand.
The second trap: parts of the copy came out as zeros, with no error
This is the part worth remembering if you ever reach for hdiutil convert on something you can’t afford to lose.
During one overnight stretch of the conversion, some of the data never made it into the copy. hdiutil reported no error and carried on, its log had nothing, and the system log showed no disk errors for those hours either. So I can’t say for certain which layer lost those writes, hdiutil or something underneath it; all I know is that the copy was wrong and nothing said so. Fifty-six of the destination’s bands came out with runs of zeros, from 8 KiB up to about 10 MiB long, in exact spots where the original backup had real data. The copy had simply gone quiet in places and kept going as if nothing had happened.
Finding all of it took two passes. A straightforward scan for sparse holes in the band files caught some of the damage right away, 28 bands, then 2 more that only showed up on a later scan, but most of the affected bands weren’t actually sparse at the filesystem level, they were fully allocated files that just happened to be full of zero bytes where real data should have been. A hole scan can’t see that. The only thing that reliably found the rest was a direct content comparison: hashing fixed-size chunks of the raw block device on both the old and the new image, one image attached read-only at a time, and comparing the hashes. Run over the whole damaged stretch, about 450 GB on each side, that caught 26 more bands, for 56 in total. Every one of them was re-copied straight from the original and checked again with a fresh hash to confirm it matched.
Having found a damaged stretch, the obvious next question is whether it happened anywhere else in those multiple terabytes. Hashing every single chunk of a multi-terabyte image twice is expensive, so the actual check was a statistical sample: 20,000 randomly chosen chunks spread across the rest of the image, each compared the same way. None of them differed. Given the rate of damage found in the one bad stretch, roughly 10 mismatches would have been expected across a sample that size if the same failure rate held everywhere else, so zero is a reasonably reassuring result. It is still a sample, not a proof, and a full byte-for-byte comparison of the entire image is the only thing that would close that question completely.
To be clear about what this bug actually did and didn’t do: at no point was the original backup touched or put at risk. hdiutil convert only ever wrote to the new copy, and the missing data was missing from that copy only, never from the source. The risk here was trusting an incomplete copy, not losing the original.
Did it actually work
The numbers that mattered most, before and after:
- Mounting the old image over the network: 3h05m, 3h03m, and 4h27m across three separate attempts.
- Mounting the rebuilt image over the network: under about 35 seconds (the exact figure wasn’t recoverable from the log for this run).
- Mounting the rebuilt image locally, directly on the Mac holding the drive: 17 seconds.
One honest caveat: those two numbers for the rebuilt image were taken right after hours of checking it, so the drive’s cache was probably warm. The old image also attached in 33 seconds locally with a warm cache. The fair comparison is cold cache over the network, and that test is still to run.
(Placeholder: cold-cache attach of the old and the rebuilt image over the network.)
Switching over needed nothing special. With the old image left detached, I attached the rebuilt one. The volume inside it is the same volume Time Machine already knew, so its backup destination simply showed up as available again. Time Machine accepted it, and its next backup was incremental, picking up from the last backup in the old image rather than starting over. The old image is still sitting untouched next to the new one, and it stays until a restore test from the new one passes.
That first incremental backup copied 20 GB in under two hours, then Time Machine spent about eight more hours in post-backup cleanup on the same slow drive, mostly retrying the deletion of about 2,200 leftover folders from earlier interrupted backups, which it logs as deleted but never actually removes. Later backups were 1.7 to 4.7 GB and took about 45 to 55 minutes each, most of it that same retry.
What’s still open
Two checks are still pending before this gets treated as fully settled, and before the old image gets deleted: a restore test pulling actual files back out of the rebuilt image, including from an older snapshot, and an fsck_apfs -n pass over the new image’s filesystem. Both are being treated as required, not optional, precisely because of what the second trap above showed about trusting this tool’s output at face value.
(Placeholder: restore test result, pending.)
(Placeholder: fsck_apfs -n result, pending.)
The takeaway
A slow mount that looks like a hang is worth timing before assuming it’s a network problem; in this case the real bottleneck was a drive doing about 150 reads a second against a job that asked for nearly half a million of them. And if you’re ever moving a large disk image with hdiutil convert, budget for the full virtual size on the destination, not just the used space, and don’t trust the copy until you’ve actually compared its contents against the original. A run with no errors is not the same thing as a correct copy.
Leave a Reply