You are not logged in.

#1 2014-05-02 19:04:45

Hotonhum
Member
Registered: 2014-02-02
Posts: 11

Spin down hard disks with udev and hdparm not working.

Hi,

I'm using XFCE and been trying to find a solution to automatically spin down my HDD hard drive for some time now.
xfce4-power-manager doesn't seem to be able to spin down hard drives (I've got the most recent update).
So I've tried to use udev and hdparm and have created following file:

/etc/udev/rules.d/75-hdparm.rules
--------------------------------------------
ACTION=="add", SUBSYSTEM=="block", ATTR{model}=="TOSHIBA MK5061GS", RUN+="/sbin/hdparm -S 180 /dev/disk/by-id/ata-TOSHIBA_MK5061GSY_82L7P5ZNT"

However, this won't spin down my disk after 15 Minutes.
When I use the same hdparm command in a shell, it's working.
I've read a few similar questions on here and that's what I've created my .rules file from.
What am I doing wrong?
Also, would a udev rules like this still spin down the disk after a suspend?

Kind regards,

Hotonhum

Last edited by Hotonhum (2014-05-02 19:05:36)

Offline

#2 2014-05-03 06:21:18

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Spin down hard disks with udev and hdparm not working.

Hotonhum wrote:

When I use the same hdparm command in a shell, it's working.

Then your udev rule probably isn't matching.

I would turn it into a script, and add to the script e.g.:

echo "`date`" >> /tmp/disk.log

As an easy way to prove that the script is at least being executed.

Alternatively, use the better udev rule:

ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", RUN+="/usr/bin/hdparm -B 255 /dev/$kernel"

Offline

#3 2014-05-03 19:31:29

Hotonhum
Member
Registered: 2014-02-02
Posts: 11

Re: Spin down hard disks with udev and hdparm not working.

Thank you for your suggestions.
I'd prever using a udev rule.
Also I only want to use hdparm on one single drive.

I will try using
ACTION=="add|change"
and
KERNEL=="sd?1"

Last edited by Hotonhum (2014-05-03 19:32:16)

Offline

#4 2014-05-03 19:40:52

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Spin down hard disks with udev and hdparm not working.

It's a bit wrong to match on partition 1 (as well as being unnecessary), because it's possible for drives to be partitionless.

Match on the drive, i.e. a-z.

Offline

#5 2014-05-03 19:51:46

Hotonhum
Member
Registered: 2014-02-02
Posts: 11

Re: Spin down hard disks with udev and hdparm not working.

I've read that matching on i.e. sda is wrong, too as the drive that belongs to sda could change.
Could I also use sd?
The drive would stil be identified by its model I think.

Offline

#6 2014-05-03 21:37:40

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Spin down hard disks with udev and hdparm not working.

Look at the "queue/rotational" line I already gave you. Use *that* rule.

Offline

#7 2014-05-04 08:19:28

Hotonhum
Member
Registered: 2014-02-02
Posts: 11

Re: Spin down hard disks with udev and hdparm not working.

OK I'll try that.
Since I only want to match one drive I think matching on "model" would be better though.
Do you know why matching on "model" doesn't work?

Offline

#8 2014-05-04 10:12:37

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Spin down hard disks with udev and hdparm not working.

Your rule is wonky, most likely. What is the output of:

udevadm info -a --name /dev/sda

Notice all those "looking at parent device" lines in the output - it's a hierarchy, and you have to match on the right *level* of the hierarchy.

So you almost need to be using ATTRS{model} rather than ATTR, for starters, and then add an additional filter to get the right level (e.g. SUBSYSTEM=="block").

Offline

#9 2014-05-07 09:30:32

Hotonhum
Member
Registered: 2014-02-02
Posts: 11

Re: Spin down hard disks with udev and hdparm not working.

My sda drive is not the drive I want to be controlled by hdparm. I want hdparm to control my sdb drive.
The output of

udevadm info -a --name /dev/sdb

is

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sdb':
    KERNEL=="sdb"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{ro}=="0"
    ATTR{size}=="976773168"
    ATTR{stat}=="    3964     4658    73986     9746      129      235     5664      940        0     7620    10683"
    ATTR{range}=="16"
    ATTR{discard_alignment}=="0"
    ATTR{events}==""
    ATTR{ext_range}=="256"
    ATTR{events_poll_msecs}=="-1"
    ATTR{alignment_offset}=="0"
    ATTR{inflight}=="       0        0"
    ATTR{removable}=="0"
    ATTR{capability}=="50"
    ATTR{events_async}==""

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0':
    KERNELS=="1:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{rev}=="MC10"
    ATTRS{type}=="0"
    ATTRS{scsi_level}=="6"
    ATTRS{model}=="TOSHIBA MK5061GS"
    ATTRS{state}=="running"
    ATTRS{unload_heads}=="0"
    ATTRS{queue_type}=="none"
    ATTRS{iodone_cnt}=="0x107a"
    ATTRS{iorequest_cnt}=="0x107a"
    ATTRS{device_busy}=="0"
    ATTRS{evt_capacity_change_reported}=="0"
    ATTRS{timeout}=="30"
    ATTRS{evt_media_change}=="0"
    ATTRS{ioerr_cnt}=="0x2a"
    ATTRS{queue_depth}=="1"
    ATTRS{vendor}=="ATA     "
    ATTRS{evt_soft_threshold_reached}=="0"
    ATTRS{device_blocked}=="0"
    ATTRS{evt_mode_parameter_change_reported}=="0"
    ATTRS{evt_lun_change_reported}=="0"
    ATTRS{evt_inquiry_change_reported}=="0"
    ATTRS{iocounterbits}=="32"
    ATTRS{eh_timeout}=="10"

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0':
    KERNELS=="target1:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata2/host1':
    KERNELS=="host1"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1f.2/ata2':
    KERNELS=="ata2"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1f.2':
    KERNELS=="0000:00:1f.2"
    SUBSYSTEMS=="pci"
    DRIVERS=="ata_piix"
    ATTRS{irq}=="19"
    ATTRS{subsystem_vendor}=="0x17aa"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x01018f"
    ATTRS{enabled}=="1"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{local_cpus}=="00000000,00000000,00000000,0000000f"
    ATTRS{device}=="0x1e01"
    ATTRS{msi_bus}==""
    ATTRS{local_cpulist}=="0-3"
    ATTRS{vendor}=="0x8086"
    ATTRS{subsystem_device}=="0x5006"
    ATTRS{numa_node}=="-1"
    ATTRS{d3cold_allowed}=="1"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

I have updated my udev rule with your suggestions so that it now looks like this:

/etc/udev/rules.d/75-hdparm.rules

ACTION=="add|change", KERNEL=="sd?", SUBSYSTEM=="block", ATTRS{queue/rotational}=="1", RUN+="/sbin/hdparm -S 180 /dev/disk/by-id/ata-TOSHIBA_MK5061GSY_82L7P5ZNT"

Offline

#10 2014-05-12 09:13:56

Hotonhum
Member
Registered: 2014-02-02
Posts: 11

Re: Spin down hard disks with udev and hdparm not working.

The rule I posted still doesn't spin down my HDD.
Does anyone know what I'm doig wrong?

Offline

#11 2014-05-12 19:20:08

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Spin down hard disks with udev and hdparm not working.

Try debugging it wink  How about:

... RUN+="/sbin/hdparm -S 180 /dev/disk/by-id/ata-TOSHIBA_MK5061GSY_82L7P5ZNT > /tmp/debug.log 2>&1"

So you can actually see the output.

Offline

#12 2014-05-21 17:56:21

Hotonhum
Member
Registered: 2014-02-02
Posts: 11

Re: Spin down hard disks with udev and hdparm not working.

I tried to use the debugging solution you posted but udev doesnt create the file /tmp/debug.log
Do you know if any permission problems could be the problem of this?
Do I need to set any permissions on the 75-hdparm.rules file?

Offline

Board footer

Powered by FluxBB