I noticed that I never figured this out completely. Linux maps SATA and USB (and many more kind of) storage devices to /dev/sd[a-z] device files in the order in which they were "found". Now given that you know that for example a CF flash card is connected to a machine via SATA how do you determine which device file it got? Of course you could just look at dmesg, but what if you want to do this programmatically? Parsing it? That's not a good solution. The kernel must provide an API to figure this out and I guess it should be simple. But so far I just haven't found it.

Linux nowadays has a lot of system information written into the filesystem (sysfs, procfs, etc) where you might get the information required to figure out the device file. This however depends on weather the features were enabled at compile time. I am looking for a solution which also works on a minimal kernel, without all the fancy fs things.

  • Would UUID mapping constitute 'fancy fs things', because if not that would be a very simple way to go?
    – 111---
    Jun 30, 2015 at 21:15
  • Yes but what if there is no partition yet on the device?
    – Nils
    Jul 1, 2015 at 5:46
  • I guess udev rules is probably the answer..
    – Nils
    Jul 1, 2015 at 8:53

1 Answer 1


You either use the persistent names in /dev/disk/ or higher level software which interacts with udev using the libudev API.

You must log in to answer this question.

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