I was trying to use disk utility to format a Windows hard drive that I installed into an iMac. I kept getting an error about “MediaKit reports not enough space on device for requested operation.”

I Googled and found this blog: https://www.aioboot.com/en/mediakit-reports-not-enough-space-on-device-for-requested-operation/

The article explains how to use Terminal to use diskutil to unmount the partitions and then you can use disk utility GUI to erase and partition the drive.