Linux – Safe to manually spin down hard drive with hdparm

hard drivehdparmlinuxsafely-remove-hardware

I have a laptop with a ssd for primary OS drive, and a large Spinning disk for storage. I currently have an alias I use for manually spinning down the drive when I'm not using it (after umount of course):

sudo hdparm -y /dev/disk/by-id/ata-WDC_WD7500BPKX-80HPJT0_WD-WX31AB3N6985

Is this safe to use? Will hdparm refuse to do this if the drive has yet to sync or if I forget to umount it?
If not, is there a way to use hdparm (or another util) to check if it is safe to do this?


UPDATE —

As much as I appreciate both of your answers, they don't help me at all, because I've tried countless different value combinations for the APM and Spin-down time settings, with no results aside from a) less than 10 seconds before spin-down b) no spin-down but random parking, or c) no spin-down or parking. I've also tried to search the web for my specific drive model and its respective APM values, to no avail.

So, the direction I'd like to go in is this:
I need to figure out a way to see if the disk is in use so I can write a systemd service. The closest I can come to so far is lsof | grep /mnt/data, or some such nonesense. But, as you can see, that is far less than ideal. I'd like a method of attaining this that doesn't depend on a predetermined mount point, or the cpu greedy multiple invocations of lsof +D mntpoint in the answer I provided myself.

Check out my answer below for an idea of what I'm trying to do

Best Answer

Instead of manually trying to figure this out, rely on existing stuff. I use hd-idle on my file server, it works great. I also don’t unmount my drives because there’s really no reason to do so. If I want to access a file, the disks will spin up. Then, after the timeout passes, they’ll spin down again.

If you’re super paranoid about data integrity, you can use autofs, which can automatically mount and umount your filesystems on an as-needed basis. I haven’t used it myself, but the ArchWiki page offers some info that looks quite usable.

Related Question