Option 1
Before you go with the custom service below, the way alsa reloads your configureation is by checking if /var/lib/alsa/asound.state
exists and what is in it (your list of sound devices) , through the systemd alsa-restore.service
that runs at boot (to reload your configuration) and at shutdown (to preserve your last configuration)
It is essential to first check whether that particular service exists with
sudo systemctl status alsa-restore.service
and the status should report
alsa-restore.service - Save/Restore Sound Card State
Loaded: loaded (/lib/systemd/system/alsa-restore.service; static; vendor preset: enabled)
Active: active (exited) since Sun 2020-09-27 11:43:13 EDT; 5h 43min ago
Docs: man:alsactl(1)
Main PID: 755 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 11833)
Memory: 0B
CGroup: /system.slice/alsa-restore.service
Sep 27 11:43:13 FOOT systemd[1]: Starting Save/Restore Sound Card State...
Sep 27 11:43:13 FOOT systemd[1]: Finished Save/Restore Sound Card State.
The alsa-restore.service located in /lib/systemd/system/alsa-restore.service
should look like so:
#
# Note that two different ALSA card state management schemes exist and they
# can be switched using a file exist check - /etc/alsa/state-daemon.conf .
#
[Unit]
Description=Save/Restore Sound Card State
Documentation=man:alsactl(1)
ConditionPathExists=!/etc/alsa/state-daemon.conf
ConditionPathExistsGlob=/dev/snd/control*
After=alsa-state.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=-/usr/sbin/alsactl -E HOME=/run/alsa -E XDG_RUNTIME_DIR=/run/alsa/runtime restore
ExecStop=-/usr/sbin/alsactl -E HOME=/run/alsa -E XDG_RUNTIME_DIR=/run/alsa/runtime store
if this service exists, but is disabled, you can enable and start it with
sudo systemctl enable alsa-restore.service
sudo systemctl start alsa-restore.service
If sudo systemctl status alsa-restore.service
reports some additional error in its status that causes it to fail, that may need to be solved first.
Option 2
After double-checking alsa force-reload
is not a oneshot command wrapper for alsactl
but instead it is responsible for the restart of the corresponding alsa service, which occurs in two steps, first stopping, then starting it again.
To summarize, sudo alsa force-reload
does is the following
- Checking if the command
alsactl
can be located, and if not it exits right away
- Running a script located at
/usr/share/alsa/utils.sh
which provides some indexing functions among other things.
- Checking if
/var/lib/alsa/asound.state
exists
- Running
alsactl -E HOME="$ALSACTLHOME" -E XDG_RUNTIME_DIR="${ALSACTLRUNTIME}" restore $CARD >/dev/null 2>&1
to restore volume states for each card found in asound.state
Step #4 is exactly what the alsa-restore.service
executes on boot and shutdown under proper operation, hence all the issues point to it being disabled or not there at all.
We already know that alsactl
exists on your system because alsa force-reload
works, but Next time you reboot and your audio is not automatically reloaded, instead of using alsa force-reload
, try running from terminal:
sudo /usr/sbin/alsactl -E HOME=/run/alsa -E XDG_RUNTIME_DIR=/run/alsa/runtime restore
If this command restores your audio, then this is what you want to run at startup as a service (and its corresponding version to also run at shutdown), at appropriate moment.
Hence, if alsa-restore.service
does not exist on your system, you should then and only then create your own myaudio.service
like so:
sudo nano /etc/systemd/system/myaudio.service
Copy the following into it:
[Unit]
Description=Start Audio
ConditionPathExists=!/etc/alsa/state-daemon.conf
[Service]
Type=oneshot
ExecStart=-/usr/sbin/alsactl -E HOME=/run/alsa -E XDG_RUNTIME_DIR=/run/alsa/runtime restore
ExecStop=-/usr/sbin/alsactl -E HOME=/run/alsa -E XDG_RUNTIME_DIR=/run/alsa/runtime store
RemainAfterExit=true
[Install]
WantedBy=sound.target
Saving it, followed by:
sudo systemct enable myaudio.service
sudo systemctl start myaudio.service
sudo systemctl status myaudio.service
Which will enable, start and report the status of your new service. If the 3 commands complete without errors, then you can reboot and test it.