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 /backups/2017/12/31
).
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 df
or 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.
df $DIRECTORY
will give you the device name (among other information) of the partition. – ridgy Jan 02 '18 at 10:06/dev
? All devices live under/dev
. – phemmer Jan 02 '18 at 13:48lsblk --help
documentsPKNAME
as internal parent kernel device name. I wouldn't trust that to mean a device name under/dev
unless explicitly spelled out in some documentation. – Mikko Rantalainen Jan 02 '18 at 18:11