If you erased the whole physical drive as @John Galt mentioned and began installing macOS, then after the first copy phase completed, the iMac rebooted to finish phase 2 and this is where you are at now? If so, then most likely the hard drive is failing, or you may be encountering a GPU failure (somewhat common on the 27" 2017 model).
Try running the Apple Diagnostics to see if any hardware issues are detected. Unfortunately the diagnostics don't detect most drive failures, nor will it likely detect a failing GPU, but it is worth a try.
It may be possible to check the health of the iMac's internal hard drive by creating & booting a Knoppix Linux USB stick. If the diagnostics don't report any issues and you would like instructions for checking the hard drive using Linux, then let me know. You will need access to another computer (Mac/Windows/Linux) in order to create this Linux USB boot stick.
If you have a spare USB3 SSD, then you could instead install macOS to the external USB3 SSD instead. We could still check the health of the internal hard drive to confirm my suspicions as there are some utilities available for macOS to do so. If the internal drive is failing, then the easiest solution is to boot & use macOS from an external USB3 SSD since it is tricky replacing the internal drive.
My money is on a failing hard drive, but either item is a possibility.