Force Eject a Stuck Drive from the CLI

I recently ran into a problem with macOS High Sierra in which I could not eject a drive because the system thought it was being shared.

I had previously shared it, true, but the client no longer had the device mounted.

smbd was confused and rejecting the unmount.

Even using diskutil to try an unmount didn't work. The OS was trying desperately to protect me from myself.

Eventually I found the solution, which was to use the force keyword in addition to the unmount:

diskutil unmountDisk force /Volumes/Disk_Name