I'm running Arch Linux (systemd) on several systems. Some have SSD storage, others have nvme storage devices and some use rotational HDD's. Some systems use dm-crypt to encrypt the filesystem. All systems run btrfs on /
.
I wish to have a bash script determine the physical device which hosts the root filesystem (/
). The purpose is to check if that block device supports trim, and if so, to then take some action if fstrim.timer is not enabled on the system.
If we know that /
is on /dev/sda
for example, we can check hdparm -I /dev/sda | grep TRIM
to find out if trim is supported. If so, I can do systemctl enable fstrim.timer
.
But on an encrypted system, /
is reported as being on /dev/mapper/cryptoroot
or something similar, and I am not finding a script-friendly way to map that back to the physical block device (e.g., /dev/sda
) to determine if it supports trim.
My understanding is that SSD's generally benefit from having periodic trim run, while NVMe devices may not.
For non-encrypted situations, these questions are relevant:
How do I find on which physical device a folder is located?
Find out what device /dev/root represents in Linux?
https://unix.stackexchange.com/a/431968/15010