How to differentiate four hard disks using udev rules

Hi all,

I have four hard disks in my module. My udev rule is like below


KERNEL=="sd*|sr*", KERNELS=="ata1", ENV{DEVTYPE}=="disk",       ENV{ID_SERIAL}=="?*", SYMLINK+="satadrive1"


KERNEL=="sd*|sr*", KERNELS=="ata2", ENV{DEVTYPE}=="disk",       ENV{ID_SERIAL}=="?*", SYMLINK+="satadrive2"
KERNEL=="sd*|sr*", KERNELS=="ata2", ENV{DEVTYPE}=="partition",  ENV{ID_SERIAL}=="?*", OPTIONS="all_partitions", SYMLINK+="satadrive2_%n"


KERNEL=="sd*|sr*", KERNELS=="ata3", ENV{DEVTYPE}=="disk",       ENV{ID_SERIAL}=="?*", SYMLINK+="satadrive3"
KERNEL=="sd*|sr*", KERNELS=="ata3", ENV{DEVTYPE}=="partition",  ENV{ID_SERIAL}=="?*", OPTIONS="all_partitions", SYMLINK+="satadrive3_%n"


KERNEL=="sd*|sr*", KERNELS=="ata4", ENV{DEVTYPE}=="disk",       ENV{ID_SERIAL}=="?*", SYMLINK+="satadrive4"
KERNEL=="sd*|sr*", KERNELS=="ata4", ENV{DEVTYPE}=="partition",  ENV{ID_SERIAL}=="?*", OPTIONS="all_partitions", SYMLINK+="satadrive4_%n"

But when i connect four hard disks, all hard disks “KERNELS” name is ata1 only.
How can i get 2nd,3rd,4th hard disk KERNELS name as ata2,ata3,ata4.
Thanks in advance.

Hi @jng

Welcome to toradex Community.

Could you provide me the Hardware and software versions of your setup? and how you’re creating the udev rules and loading the same.

I am using SOM and carrier board of apalis imx6. I have taken latest software image from toradex website.
version - Linux apalis-imx6 5.4.77-5.1.0 armv7l GNU/Linux.

I have connected 4 hard disks to the carrier board using one sata expander. I placed the udev rule file in /etc/udev/rules.d .
my udev rule is


KERNEL==“sd*|sr*”, KERNELS==“ata1”, ENV{DEVTYPE}==“disk”, ENV{ID_SERIAL}=="?", SYMLINK+=“satadrive1”

KERNEL==“sd*|sr*”, KERNELS==“ata2”, ENV{DEVTYPE}==“disk”, ENV{ID_SERIAL}=="?", SYMLINK+=“satadrive2”
|sr*", KERNELS==“ata2”, ENV{DEVTYPE}==“partition”, ENV{ID_SERIAL}=="?*", OPTIONS=“all_partitions”, SYMLINK+=“satadrive2_%n”

KERNEL==“sd*|sr*”, KERNELS==“ata3”, ENV{DEVTYPE}==“disk”, ENV{ID_SERIAL}=="?", SYMLINK+=“satadrive3”
|sr*", KERNELS==“ata3”, ENV{DEVTYPE}==“partition”, ENV{ID_SERIAL}=="?*", OPTIONS=“all_partitions”, SYMLINK+=“satadrive3_%n”

KERNEL==“sd*|sr*”, KERNELS==“ata4”, ENV{DEVTYPE}==“disk”, ENV{ID_SERIAL}=="?", SYMLINK+=“satadrive4”
|sr*", KERNELS==“ata4”, ENV{DEVTYPE}==“partition”, ENV{ID_SERIAL}=="?*", OPTIONS=“all_partitions”, SYMLINK+=“satadrive4_%n”

It is working when i connect one hard disk to sata expander(because its KERNELS==ata1).
But when i connect four hard disks, all hard disks “KERNELS” name is ata1 only. How can i get 2nd,3rd,4th hard disk KERNELS name as ata2,ata3,ata4.


After all what are you going to achieve? Udev rules are fine to apply something differently for specific device serial names, vendor pid/vid pairs, etc. What’s the difference among 4 disks? If you don’t know serial numbers or something, then different are only ports (USB / SATA / …).
Are you aware about /dev/disk folder structure? Symlinks stored there in by-id / by-label / etc should be enough to identify particular disk by port, partition label, etc.

In one system i am using 4 hard disks, in another system i am using another 4 hds. system by stsyem hds are changed. so i want a rule to work for any hds in any system.

But you kind of ignored my question. By what you want to differentiate you disks? By port they are connected (USB HUB port1, port2, …, SATA port 1, port, …)? By serial number? What’s different among them. That difference is required to create udev rules. No difference - no rules.

Thanks for your reply.

  1. Actually i am connecting 4 hds using a sata expander. I didn’t get the difference. Can you suggest how can i get different parameters if i connect hds using sata expander.

  2. How can i get KERNELS as ata2,ata3,ata4 for hds(2nd,3rd,4th hds) instead of ata1 for all hds. If this parameter is different then i can write udev rule. please suggest.

I think KERNELS string comes from driver or something and is not controlled from udev. For me it looks like you want to identify disks by expander port. Then what’s wrong with /dev/disk/by-path symlinks ? Here what I see plugging USB HUB to my Colibri board and adding two flash drives:


3 and 1 indicate different HUB ports from the same specific HUB. Every symlink from picture points to specific /dev/sda(b) device or /dev/sda(b)n partition. You should see something like that for SATA disks. Your udev rules at best would just produce shorter names, isn’t it?

Thanks for your reply.

Please tell me how can i use above information in udev rule(means which parameter i can check).

Hi @jng

Did you test the @Edward answer?is this solution works for you?