# macOS: hdiutil: create failed - Resource busy (or: hdiutil: couldn't eject "disk2" - Resource busy)

**Code:** `hdiutil: create failed - Resource busy` · **Category:** macOS · **Seen on:** macOS

A disk image operation failed because the volume or a file in it is still in use (Finder, Spotlight, a terminal).

## Meaning

Close windows/terminals using the volume, wait for Spotlight, then detach with `hdiutil detach -force /Volumes/NAME`. In build scripts retry detach a few times and disable Spotlight indexing (`mdutil -i off /Volumes/NAME`). `lsof +D /Volumes/NAME` shows who uses it.

## Common causes

- Finder window open on the volume
- Spotlight (mds) indexing the new volume
- A shell cd'd into /Volumes/NAME
- Backup/AV software scanning
- Duplicate image mounted under the same name

## Quick fix

1. `lsof +D /Volumes/NAME` then close the process
2. `hdiutil detach -force /Volumes/NAME`
3. Retry with a short sleep in scripts

## Detailed fix by platform

### macOS

1. `hdiutil info | grep -E "image-path|/dev/disk" && hdiutil detach -force /Volumes/NAME`

## How to diagnose

1. **Users** — lsof output?
2. **Spotlight** — Indexing?
3. **Retry** — Delay added?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/macos/hdiutil-resource-busy)
