Safely removing SATA hard drive from a running system

I have a Debian-based system with a SATA controller running in AHCI mode. I sometimes need to plug and unplug a disk from an internal SATA bay. The bay is nothing fancy – you just slide a disk cradle into it and the SATA and power sockets make contact.

Wyzard on Unix & Linux Stack Exchange
has a good advice on how to do a proper hot unplug. The following is based on
that advice:

First you need to unmount the partitions. Then, deactivate any LVM groups with vgchange -an – I don’t use LVM, so I haven’t tried that. Finally, it is a very good idea to unregister device from the kernel and spin it down by

echo 1 > /sys/block/(device name)/device/delete

Then I can hear the disk spin down, wait for it to stop completely and just pull it out. When I put in back in, it registers properly. Please note, that I am using AHCI mode in the controller.