I have a simple udev rule on ubuntu 19.10

ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", RUN+="/sbin/hdparm -B 127 -S 120 /dev/%k"

I have 2 drives which this can be applied to

# lsblk -d -o name,rota
loop0      0
loop1      0
loop2      0
loop3      0
sda        1
sdb        1
sdc        0
sdd        1
nvme0n1    0

After boot, I check the disks

# hdparm -B /dev/sda

 APM_level      = 127
# hdparm -B /dev/sdd

 APM_level      = 254

I could not quite figure out why it is not applied to /dev/sdd. I am able to execute the command from shell and it works on /dev/sdd fine.

Also triggering the rule with:

udevadm trigger /dev/sdd

executes the command correctly.

Any ideas on how this can be debugged?

PS. /dev/sdb does not support APM attributes, can it be that udev stops execution because hdparm fails? In that case how can I skip /dev/sdb only?


After trying it quite a bit and making a shell script to record output of hdparm it looked like the output of hdparm showed the drives were updated. But when I check the drive settings, they were not applied!

So, now instead I have setup the settings in /etc/hdparm.conf

/dev/sda {
        apm = 127
        spindown_time = 120

/dev/sdb {
        spindown_time = 120

/dev/sdd {
        apm = 127
        spindown_time = 120

and now all the settings are applied

Perhaps not as elegant as using udev rule but it works!

  • 1
    Could you hotplug the disk? Will udev rule work such way?
    – edo1
    Nov 16, 2019 at 21:42
  • It works if I run udevadm trigger /dev/sdd
    – yurtesen
    Nov 16, 2019 at 22:14
  • Try update-initramfs -u and reboot
    – edo1
    Nov 16, 2019 at 22:17
  • Why? That makes no sense...
    – yurtesen
    Nov 16, 2019 at 22:24
  • I guess your rule should be included into initramfs image
    – edo1
    Nov 16, 2019 at 22:30


You must log in to answer this question.

Browse other questions tagged .