As mentioned in the comments, /etc/profile.d
is being run as the user logging in, so will not have sufficient permissions to modify system configuration. You could add a sudo
command there, but that would just mean you'll need to type your password again when you log in - this would be annoying and will also not work if the logging in user is not a system admin. Also, it will not do its job if no one is logging in after boot.
There are a few options, including adding /etc/rc.local
as you mentioned, which was one of the common ways to do this kind of custom "on-boot" jobs before SystemD made the whole /etc/rc*
thing irrelevant.
But - if you already have /etc/rc.local
set up with your script, you can just enable it in SystemD by:
- Make sure
/etc/rc.local
is executable. For example by running chmod a+x /etc/rc.local
. The SystemD compatibility mode will not work otherwise.
- Allow the SystemD compatibility mode to be enabled by creating the file
/etc/systemd/system/rc-local.service.d/enable.conf
with the contents below.
- Enable the SystemD compatibility by running
sudo systemctl enable rc-local
/etc/systemd/system/rc-local.service.d/enable.conf
:
[Install]
WantedBy=multi-user.target
Next time your system boot, SystemD will run your custom /etc/rc.local
.
SystemD Alternatives
- Make use of SystemD tmpfiles management system to have it write what you need during boot. This is my recommended solution.
- See this AskUbuntu question for some people making SystemD services to do the same thing.
- I believe you can write a udev rule that disables "
power/wakeup
" when it sees whatever the XHC is (I think its the onboard XHCI USB hub?), as documented here: https://www.kernel.org/doc/html/v4.13/driver-api/usb/power-management.html