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?

1 Answer 1


BTRFS supports multiple devices, so what you can do is use btrfs fi show to get the list of block devices. Then use cryptsetup status to check if a given device is a LUKS container. If it is the command will output the underlining device.

I wouldn't call this script-friendly, since you'll have to parse the output, but it should work.

  • Thank you. I will see if I can make this work, and if so, I'll accept your answer.
    – MountainX
    Nov 5, 2018 at 17:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .