Oh and there is always IRC. You can probably get some near instant support there. #archlinux is probably the most active support IRC channel I have ever seen.
]]>run: '/sbin/hdparm -S 241 /dev/sdb'
I think I don't have enough will to fight it anymore. Maybe it's just broken...
]]>Well, as you can see, from the output udev is performing /sbin/hdparm -S 241 /dev/sdb which is exactly what I want. However, the disk is not spun down after half an hour. If I run that command manually from console, I get the result I wanted.
Anyway, I was browsing journalctl for any details of this problem (haven't found any) and I think we could have wrongly named KERNELS path. Please look on that:
[root@linux mk]# journalctl -b |grep 2:0:0:0
maj 13 10:33:13 linux kernel: scsi 2:0:0:0: Direct-Access ATA SAMSUNG SP2504C VT10 PQ: 0 ANSI: 5
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] 488395055 512-byte logical blocks: (250 GB/232 GiB)
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] Write Protect is off
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] Mode Sense: 00 3a 00 00
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
maj 13 10:33:13 linux kernel: sd 2:0:0:0: [sda] Attached SCSI disk
maj 13 10:33:15 linux kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDING /sys/devices/pci0000:00/0000:00:08.0/ata3/host2/target2:0:0/2:0:0:0/block/sda
maj 13 10:33:25 linux udisks-daemon[300]: **** UPDATING /sys/devices/pci0000:00/0000:00:08.0/ata3/host2/target2:0:0/2:0:0:0/block/sda
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDED /sys/devices/pci0000:00/0000:00:08.0/ata3/host2/target2:0:0/2:0:0:0/block/sda
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDING /sys/devices/pci0000:00/0000:00:08.0/ata3/host2/target2:0:0/2:0:0:0/block/sda/sda1
...
And so on. It's sda across the whole output. And sdb?
[root@linux mk]# journalctl -b |grep sdb
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] 488397168 512-byte logical blocks: (250 GB/232 GiB)
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] Write Protect is off
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] Mode Sense: 00 3a 00 00
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
maj 13 10:33:13 linux kernel: sdb: sdb1 < sdb5 >
maj 13 10:33:13 linux kernel: sd 4:0:0:0: [sdb] Attached SCSI disk
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb, type changed from 'scsi' to 'sat'
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb [SAT], opened
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb [SAT], SAMSUNG SP2504C, S/N:S09QJ1GLB15632, FW:VT100-50, 250 GB
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb [SAT], found in smartd database: SAMSUNG SpinPoint P120
maj 13 10:33:24 linux smartd[245]: Device: /dev/sdb [SAT], WARNING: May need -F samsung3 enabled; see manual for details.
maj 13 10:33:25 linux smartd[245]: Device: /dev/sdb [SAT], is SMART capable. Adding to "monitor" list.
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDING /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb
maj 13 10:33:25 linux udisks-daemon[300]: **** UPDATING /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb
maj 13 10:33:25 linux udisks-daemon[300]: helper(pid 320): launched job udisks-helper-ata-smart-collect on /dev/sdb
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDED /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb
maj 13 10:33:25 linux udisks-daemon[300]: **** ADDING /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb/sdb1
maj 13 10:33:25 linux udisks-daemon[300]: **** UPDATING /sys/devices/pci0000:00/0000:00:08.1/ata5/host4/target4:0:0/4:0:0:0/block/sdb/sdb1
...
I'm going to change the path, we'll see if it helps:
[root@linux mk]# cat /etc/udev/rules.d/90-hdparm.rules
# /dev/sdb sleeps after 30 minutes
ACTION=="add", SUBSYSTEM=="block", KERNELS=="4:0:0:0", RUN+="/sbin/hdparm -S 241 /dev/$kernel"
/dev/$kernel is whatever the kernel name is for that particular hardware path (2:0:0:0). So you need to determine what that is. You can probably go searching through /sys to find it, or just use hdparm to find that info as well.
I really didn't fund that document about writing udev rules all that complicated. It covers the most basic forms, but I guess I was also writing and trying them as I went along. So I was really learning by doing. I think that by me simply giving you these rules, I am actually hindering your ability to understand for yourself. So sorry about that.
If you have something more specific about what your issue might be, I'll check back on this thread. Good luck sir!
]]>[root@linux mk]# udevadm test /sys/block/sdb/
calling: test
version 203
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.
=== trie on-disk ===
tool version: 203
file size: 5632867 bytes
header size 80 bytes
strings 1260755 bytes
nodes 4372032 bytes
load module index
Skipping overridden file: /usr/lib/udev/rules.d/80-net-name-slot.rules.
read rules file: /usr/lib/udev/rules.d/10-dm.rules
read rules file: /usr/lib/udev/rules.d/11-dm-lvm.rules
read rules file: /usr/lib/udev/rules.d/13-dm-disk.rules
read rules file: /usr/lib/udev/rules.d/40-gphoto.rules
read rules file: /usr/lib/udev/rules.d/40-hpet-permissions.rules
read rules file: /usr/lib/udev/rules.d/40-hplip.rules
read rules file: /usr/lib/udev/rules.d/40-usb-media-players.rules
read rules file: /usr/lib/udev/rules.d/42-usb-hid-pm.rules
read rules file: /usr/lib/udev/rules.d/50-firmware.rules
read rules file: /usr/lib/udev/rules.d/50-udev-default.rules
read rules file: /usr/lib/udev/rules.d/53-sane.rules
read rules file: /usr/lib/udev/rules.d/56-hpmud_add_printer.rules
read rules file: /usr/lib/udev/rules.d/56-hpmud_support.rules
read rules file: /usr/lib/udev/rules.d/60-cdrom_id.rules
read rules file: /usr/lib/udev/rules.d/60-ffado.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-alsa.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-input.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-serial.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-storage-tape.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-storage.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-v4l.rules
read rules file: /usr/lib/udev/rules.d/61-accelerometer.rules
read rules file: /usr/lib/udev/rules.d/64-btrfs.rules
read rules file: /usr/lib/udev/rules.d/69-cd-sensors.rules
IMPORT found builtin 'usb_id --export %p', replacing /usr/lib/udev/rules.d/69-cd-sensors.rules:89
read rules file: /usr/lib/udev/rules.d/69-dm-lvm-metad.rules
read rules file: /usr/lib/udev/rules.d/69-libmtp.rules
read rules file: /usr/lib/udev/rules.d/70-infrared.rules
read rules file: /usr/lib/udev/rules.d/70-power-switch.rules
read rules file: /usr/lib/udev/rules.d/70-uaccess.rules
read rules file: /usr/lib/udev/rules.d/70-udev-acl.rules
read rules file: /usr/lib/udev/rules.d/71-seat.rules
read rules file: /usr/lib/udev/rules.d/73-seat-late.rules
read rules file: /usr/lib/udev/rules.d/75-net-description.rules
read rules file: /usr/lib/udev/rules.d/75-probe_mtd.rules
read rules file: /usr/lib/udev/rules.d/75-tty-description.rules
read rules file: /usr/lib/udev/rules.d/78-sound-card.rules
read rules file: /usr/lib/udev/rules.d/80-drivers.rules
read rules file: /etc/udev/rules.d/80-net-name-slot.rules
read rules file: /usr/lib/udev/rules.d/80-udisks.rules
read rules file: /usr/lib/udev/rules.d/80-udisks2.rules
read rules file: /usr/lib/udev/rules.d/85-usbmuxd.rules
read rules file: /usr/lib/udev/rules.d/86-hpmud_plugin.rules
read rules file: /usr/lib/udev/rules.d/90-alsa-restore.rules
read rules file: /etc/udev/rules.d/90-hdparm.rules
read rules file: /usr/lib/udev/rules.d/90-pulseaudio.rules
read rules file: /usr/lib/udev/rules.d/95-cd-devices.rules
read rules file: /usr/lib/udev/rules.d/95-dm-notify.rules
read rules file: /usr/lib/udev/rules.d/95-keyboard-force-release.rules
read rules file: /usr/lib/udev/rules.d/95-keymap.rules
read rules file: /usr/lib/udev/rules.d/95-udev-late.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-dell.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-fujitsu.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-gateway.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-ibm.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-lenovo.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-toshiba.rules
read rules file: /usr/lib/udev/rules.d/95-upower-csr.rules
read rules file: /usr/lib/udev/rules.d/95-upower-hid.rules
read rules file: /usr/lib/udev/rules.d/95-upower-wup.rules
read rules file: /etc/udev/rules.d/99-gpusb.rules
read rules file: /usr/lib/udev/rules.d/99-systemd.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 40284 bytes strings
28908 strings (240888 bytes), 25286 de-duplicated (204227 bytes), 3623 trie nodes used
GROUP 6 /usr/lib/udev/rules.d/50-udev-default.rules:50
IMPORT 'ata_id --export /dev/sdb' /usr/lib/udev/rules.d/60-persistent-storage.rules:30
starting 'ata_id --export /dev/sdb'
'ata_id --export /dev/sdb' [11055] exit with return code 0
LINK 'disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632' /usr/lib/udev/rules.d/60-persistent-storage.rules:42
IMPORT builtin 'path_id' /usr/lib/udev/rules.d/60-persistent-storage.rules:55
IMPORT builtin 'path_id' returned non-zero
IMPORT builtin 'blkid' /usr/lib/udev/rules.d/60-persistent-storage.rules:70
probe /dev/sdb raid offset=0
LINK 'disk/by-id/wwn-0x50000f001bb15632' /usr/lib/udev/rules.d/60-persistent-storage.rules:80
IMPORT 'udisks-part-id /dev/sdb' /usr/lib/udev/rules.d/80-udisks.rules:84
starting 'udisks-part-id /dev/sdb'
'udisks-part-id /dev/sdb' [11056] exit with return code 0
IMPORT 'udisks-probe-ata-smart /dev/sdb' /usr/lib/udev/rules.d/80-udisks.rules:111
starting 'udisks-probe-ata-smart /dev/sdb'
'udisks-probe-ata-smart /dev/sdb' [11057] exit with return code 0
RUN '/sbin/hdparm -S 241 /dev/$kernel' /etc/udev/rules.d/90-hdparm.rules:2
handling device node '/dev/sdb', devnum=b8:16, mode=0660, uid=0, gid=6
preserve permissions /dev/sdb, 060660, uid=0, gid=6
preserve already existing symlink '/dev/block/8:16' to '../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fdisk\x2fby-id\x2fata-SAMSUNG_SP2504C_S09QJ1GLB15632'
creating link '/dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632' to '/dev/sdb'
preserve already existing symlink '/dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632' to '../../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fdisk\x2fby-id\x2fwwn-0x50000f001bb15632'
creating link '/dev/disk/by-id/wwn-0x50000f001bb15632' to '/dev/sdb'
preserve already existing symlink '/dev/disk/by-id/wwn-0x50000f001bb15632' to '../../sdb'
ACTION=add
DEVLINKS=/dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632 /dev/disk/by-id/wwn-0x50000f001bb15632
DEVNAME=/dev/sdb
DEVPATH=/devices/pci0000:00/0000:00:08.1/ata3/host2/target2:0:0/2:0:0:0/block/sdb
DEVTYPE=disk
ID_ATA=1
ID_ATA_DOWNLOAD_MICROCODE=1
ID_ATA_FEATURE_SET_AAM=1
ID_ATA_FEATURE_SET_AAM_CURRENT_VALUE=0
ID_ATA_FEATURE_SET_AAM_ENABLED=0
ID_ATA_FEATURE_SET_AAM_VENDOR_RECOMMENDED_VALUE=254
ID_ATA_FEATURE_SET_HPA=1
ID_ATA_FEATURE_SET_HPA_ENABLED=1
ID_ATA_FEATURE_SET_PM=1
ID_ATA_FEATURE_SET_PM_ENABLED=1
ID_ATA_FEATURE_SET_SECURITY=1
ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=88
ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=88
ID_ATA_FEATURE_SET_SMART=1
ID_ATA_FEATURE_SET_SMART_ENABLED=1
ID_ATA_SATA=1
ID_ATA_SATA_SIGNAL_RATE_GEN1=1
ID_ATA_SATA_SIGNAL_RATE_GEN2=1
ID_ATA_WRITE_CACHE=1
ID_ATA_WRITE_CACHE_ENABLED=1
ID_BUS=ata
ID_MODEL=SAMSUNG_SP2504C
ID_MODEL_ENC=SAMSUNG\x20SP2504C\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
ID_PART_TABLE_TYPE=dos
ID_REVISION=VT100-50
ID_SERIAL=SAMSUNG_SP2504C_S09QJ1GLB15632
ID_SERIAL_SHORT=S09QJ1GLB15632
ID_TYPE=disk
ID_WWN=0x50000f001bb15632
ID_WWN_WITH_EXTENSION=0x50000f001bb15632
MAJOR=8
MINOR=16
SUBSYSTEM=block
TAGS=:systemd:
UDISKS_ATA_SMART_IS_AVAILABLE=1
UDISKS_PARTITION_TABLE=1
UDISKS_PARTITION_TABLE_COUNT=2
UDISKS_PARTITION_TABLE_SCHEME=mbr
UDISKS_PRESENTATION_NOPOLICY=0
USEC_INITIALIZED=49937
run: '/sbin/hdparm -S 241 /dev/sdb'
unload module index
But it doesn't How can I check what $kernel actually stands for? Maybe it'd be better to change it to something else?
]]>Did you read through the Arch wiki page on udev? There is a link to writing udev rules there. The linked page is short, and very straight forward, as it only covers the most basic of use cases (which is enough for what you want to do here).
In short, you need to give it enough info to be able to identify only that disk. But you also may use anything from the top level, that is the section with ATTR and not ATTRS, and you may use stuff below it. But if you use stuff below it, you may only use things from teh same section. So if this is indeed the disk you actually want to use, you might do something like this:
ACTION=="add", SUBSYSTEM=="block", KERNELS=="2:0:0:0", RUN+="/sbin/hdparm -S 241 /dev/$kernel"
So you see that I used SUBSYSTEM=="block" there. If you had wanted to use a subsystem below that of some kind. You would have had to have used the SUBSYSTEM=="scsi" because it would be in the same section as KERNELS="2:0:0:0". So I think that should actually work. You might want to check to make sure, but I am fairly certain that other disks will result in a different KERNELS=="x:0:0:0".
]]>[mk@linux ~]$ udevadm info -a -p $(udevadm info -q path -n /dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632)
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:08.1/ata3/host2/target2:0:0/2:0:0:0/block/sdb':
KERNEL=="sdb"
SUBSYSTEM=="block"
DRIVER==""
ATTR{ro}=="0"
ATTR{size}=="488397168"
ATTR{stat}==" 360 1138 2858 216 0 0 0 0 0 216 216"
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:08.1/ata3/host2/target2:0:0/2:0:0:0':
KERNELS=="2:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{rev}=="VT10"
ATTRS{type}=="0"
ATTRS{scsi_level}=="6"
ATTRS{model}=="SAMSUNG SP2504C "
ATTRS{state}=="running"
ATTRS{queue_type}=="none"
ATTRS{iodone_cnt}=="0x1c3"
ATTRS{iorequest_cnt}=="0x1c3"
ATTRS{timeout}=="30"
ATTRS{evt_media_change}=="0"
ATTRS{ioerr_cnt}=="0x18"
ATTRS{queue_depth}=="1"
ATTRS{vendor}=="ATA "
ATTRS{device_blocked}=="0"
ATTRS{iocounterbits}=="32"
looking at parent device '/devices/pci0000:00/0000:00:08.1/ata3/host2/target2:0:0':
KERNELS=="target2:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:08.1/ata3/host2':
KERNELS=="host2"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:08.1/ata3':
KERNELS=="ata3"
SUBSYSTEMS==""
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:08.1':
KERNELS=="0000:00:08.1"
SUBSYSTEMS=="pci"
DRIVERS=="sata_nv"
ATTRS{irq}=="20"
ATTRS{subsystem_vendor}=="0x1458"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x010185"
ATTRS{consistent_dma_mask_bits}=="32"
ATTRS{dma_mask_bits}=="32"
ATTRS{local_cpus}=="00000000,00000003"
ATTRS{device}=="0x03f6"
ATTRS{msi_bus}==""
ATTRS{local_cpulist}=="0-1"
ATTRS{vendor}=="0x10de"
ATTRS{subsystem_device}=="0xb002"
ATTRS{numa_node}=="0"
ATTRS{d3cold_allowed}=="1"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
I can't use model string to specify the disk because I have 2 physical drives called SAMSUNG SP2504C.
]]>[root@linux mk]# cat /etc/udev/rules.d/90-hdparm.rules
# /dev/sdb sleeps after 30 minutes
ACTION=="add", SUBSYSTEM=="block", ATTRS{model}=="S09QJ1GLB15632", RUN+="/sbin/hdparm -S 241 /dev/$kernel"
And the output is:
[mk@linux ~]$ udevadm info -q path -n /dev/disk/by-id/ata-SAMSUNG_SP2504C_S09QJ1GLB15632
/devices/pci0000:00/0000:00:08.1/ata3/host2/target2:0:0/2:0:0:0/block/sdb
If it is a udev rule, post the output of:
$ udevadm info -a -p $(udevadm info -q path -n /dev/sdX)
Where X is the drive you are trying to apply the rule to (obviously).
Also, post your udev rule itself. Maybe we can find where yu have gone wrong.
]]>In any case, I do think that the udev rule would in fact be the "correct way".
]]>