Problem:
When you boot up or restart your computer you find that the sound always resets to the maximum volume of a 100%. This is caused when the PulseAudio server is started at desktop login time. You are afraid that it may blow up either your speakers, your ears, or your nerves, or probably all, and finding a solution is imperative.
In this tutorial I present you with a three step solution to have your ALSA volume settings restored to the last values set in your previously logged out session. I am presenting it here with the hope that it may relieve other users with the same issue of the seven year itch and I don't claim it to be the best solution; only that it is the only solution that has worked on my system. Follow the steps carefully and intelligently and you are sure to have success. So, before you remove PulseAudio from your system as a last resort so that you may have the comfort of booting up with your speakers at an agreeable audio volume, first try out my tutorial. Good luck.
1. Create a bootscript that would save your ALSA settings to a file in your home directory at Shutdown:
Your ALSA settings are stored to the file /var/lib/alsa/asound.state by default with $ sudo alsactl store and the values can be reset with $ sudo alsactl restore.
However, alsactl with the option -f can save the settings file to any user-specified location in the home directory. I will save the file asound.state in a local directory using $ alsactl -f store /<location> so that the settings can be restored from there without the use of a root shell.
First I will create a folder where the ALSA settings can be stored. Secondly I will create a shell script file in /etc/init.d called alsa-store that will tell alsactl to store the alsa values at my specified location. You can name the script anything you prefer.
In terminal:
Code: Select all
$ mkdir ~/.config/alsa
$ sudo gedit /etc/init.d/alsa-store
Replace gedit with your favourite text editor. In the text editor enter:
Code: Select all
#!/bin/sh
### BEGIN INIT INFO
# Provides: alsa-store
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Store Alsa settings
# Description: The purpose of this script is to stores the last Alsa volume
#settings to a file in the home directory at shutdown time.
### END INIT INFO
alsactl store -f /home/<your_username>/.config/alsa/asound.state
Replace <your_username> with your own username. Save and close, and in terminal do:
Code: Select all
$ sudo update-rc.d alsa-store defaults
Now your boot/ shutdown script is set up to save your alsa volume values to ~/.config/alsa/asound.state. You will use this file later to restore your volume settings when you next login. You may want to test it by rebooting, and checking weather the file asound.state has been created in the specified directory.
2. Create a shell script that would restore your settings at your desktop-session login.
Use a convenient location to create a new shell script file. Say, ~/scripts/ and call it something like alsa-restore.sh. In a terminal type:
Code: Select all
gedit ~/scripts/alsa-restore.sh
Code: Select all
#! /bin/sh
#Start PulseAudio daemon:
pulseaudio -D
#Restore ALSA volume settings:
alsactl restore -f /home/<your_username>/.config/alsa/asound.state
Code: Select all
chmod +x ~/scripts/alsa-restore.sh
3. Add an autostart entry to your Autostart list that will execute your script at login.
An easy way to make your script execute at login time is to add an autostart entry to the list in Settings → Session and Startup. In the Application Autostart tab click on the add button and enter a new name, say alsa-volume-restore, and in the command field enter:
Code: Select all
sh /home/<user_name>/scripts/alsa-restore.sh
Code: Select all
[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=alsa-volume-restore
Comment=alsa volume restore
Exec=sh /home/michael/scripts/asoundrestore.sh
OnlyShowIn=XFCE;
StartupNotify=false
Terminal=false
Hidden=false
Click OK and check the checkbox for your new entry. In the same list make sure to uncheck the entry for PulseAudio Sound System (Start the PulseAudio Sound System).
Now you are set up. Make sure to set your audio volume to anything under 100%, using the Audio Mixer panel Plugin, or the ALSA audio mixer in the Multimedia menu (or terminal: $ alsamixer), and reboot your system. Your audio volume should now be restored to the previous values.
Have fun.