Ubuntu – Why does hd-idle need sudo to run in rc.local


I have added a command that runs "hd-idle". It seems to need to run as root as otherwise it does not spin down the drives as instructed. Behavior seems to be the same when executed manually or via rc.local. hd-idle was compiled with make install as opposed to installed with apt-get if it matters.

From another question on this site I know rc.local runs as root, so why do I still need to add sudo for my hd-idle to run?

Last 2 lines of rc.local:

sudo hd-idle -i 300

exit 0;

The above rc.local works as expected and the hard drives go into stand by mode after 300 seconds. If I remove "sudo" and reboot the hard drives never spin down.

Best Answer

  • hd-idle requires root to work with the files in /proc/diskstats because /proc/ and /dev/ owned by root.

    I wouldn't advise changing the ownership, but perhaps you can add your user account to the dial out group.

    $sudo usermod -a -G dialout <user-name>

    Then you can try doing things like accessing hardware

    You could also try changing the group permissions to /proc/diskstats to include the dialout group. (I am not advising this. but you could try it)

    I think some of the logging features write to /var/log/hd-idle which is also owned by root.

    I think you could modify the source, and add a user to the diaout group to get this software to work as a not explicitly root user, but I am recommending caution.

    Answer taken from hd-idle source code.

  • Related Question