Apple - Disk Utility won't Unmount HD for formatting
You can force unmount a drive by running the following Terminal command:
diskutil unmountDisk force /Volumes/VOLUMENAME
Replace VOLUMENAME
with the name of a volume on the disk you are trying to unmount.
Following this, attempt to Erase/Partition the drive again in Disk Utility. Using the above command can interrupt file read/writes, which can cause file corruption. However, since you are erasing the drive anyway, this doesn't really matter in your situation.
When a disk is first connected, macOS helpfully tries to run fsck on the volume. If the volume is large or has extensive problems, this process can run for a long time before it fails.
The following Terminal command should identify the process at fault:
sudo lsof | grep diskn
replacing diskn with the number of the offending disk.
Once you have the process ID, you can kill it thus:
sudo kill -9 pid
replacing pid with the process ID determined above.
Then you can run diskutil normally, either from GUI or command line.
Disable Spotlight for that Hard Drive (System Preferences)
https://discussions.apple.com/thread/1454712?start=0&tstart=0