The safest way to maintain file permissions on reboot is to write a script to reset permissions on given file at startup.
That way you are certain that they are correct.
In my case I needed to get write access to a file located in /hwmon/hwmon1/device/pwm1 && pwm1_enable. Those files controls the cpu fan on my motherboard (Gigabyte GA-73PVM-series).
I manually changed the permissions on the files, but at the next reboot the permissions were set back to read only…hmm.
This is how I solved it:
Created a single file called fan-speed-init.sh in /etc/init.d
fan-speed-init.sh:
/bin/chmod 664 /sys/class/hwmon/hwmon1/device/pwm1
/bin/chmod 664 /sys/class/hwmon/hwmon1/device/pwm1_enable
Set the ownership and permissions on this script so root can execute
sudo chmod 744 /etc/init.d/fan-speed-init.sh
sudo chown root:root /etc/init.d/fan-speed-init.sh
Now set this script to run at startup
sudo ln -s /etc/init.d/fan-speed-init.sh /etc/rc2.d/S99fan-speed-init.sh
sudo ln -s /etc/init.d/fan-speed-init.sh /etc/rc3.d/S99fan-speed-init.sh
sudo ln -s /etc/init.d/fan-speed-init.sh /etc/rc4.d/S99fan-speed-init.sh
sudo ln -s /etc/init.d/fan-speed-init.sh /etc/rc5.d/S99fan-speed-init.sh
This multiple linking could be done smarter by issuing the
update-rc.d -f fan-speed-init.sh start 99 2 3 4 5 .
where
- start is the argument given to the script (start, stop).
- 99 is the start order of the script (1 = first, 99= last)
- 2 3 4 5 are the runlevels to start
Dont forget the dot at the end
More info in /etc/rcS.d/README
Now at reboot, the file permissions is reset during start and at runlevel 2 my script is executed by root issuing the given chmod command setting permissions the way I want it. B-)

Recent Comments