Assume that I have some device mounted to
/backups. I'm copying selected files from the system to backup and I would like to reduce the amount of noise the device is making. I know that I can can use
hdparm -M to adjust the device "Automatic Acoustic Management (AAM)" setting. However, I don't know how I should get the device (e.g.
/dev/sdc) from a given directory (for example, if I had a script that computed the latest backup location as
The best I can do is
echo /dev/$(lsblk -no pkname $(findmnt -nvoSOURCE -T "$DIRECTORY"))
but that requires hardcoding
/dev/ prefix and assumes that there's only one backing disk. How to make this more stable?
Note that this question is specifically about locating the correct disk(s), not the partition. In case you only need to find the correct partition
findmnt will be enough.
Also note that in case a directory is mounted on
md device, the parent device will be something like
md0 which cannot be used with
hdparm. In that case there will be more than one underlying disks so in reality this question is about mapping a single file or directory to one or more disks.