For The Impatient
To restore a non working sound system in Linux guest under VirtualBox, make sure that "Intel HD Audio" is used as the audio controller for the Linux guest in VirtualBox Manager.
In the Linux guest, when the issue occurs, run the following two commands in sequence:
In the Linux guest, when the issue occurs, run the following two commands in sequence:
sudo rmmod -f snd_hda_intel
sudo modprobe snd_hda_intel power_save=0 power_save_controller=N
Note: your user account must have root privilege. You can then test the sound using the following command:
aplay /usr/share/sounds/alsa/Front_Center.wav
If the sound still does not work, adjust the host machine's volume a little. That will make the sound work. I have verified this trick multiple times in the 6 days after the boot up of my Debian virtual machine.
To make it easier, you can create two aliases:
alias resetsound='sudo rmmod -f snd_hda_intel;sleep 1;sudo modprobe snd_hda_intel power_save=0 power_save_controller=N;sleep 1'
alias testsound='aplay /usr/share/sounds/alsa/Front_Center.wav'
Note: your user account must have root privilege. You can then test the sound using the following command:
aplay /usr/share/sounds/alsa/Front_Center.wav
If the sound still does not work, adjust the host machine's volume a little. That will make the sound work. I have verified this trick multiple times in the 6 days after the boot up of my Debian virtual machine.
To make it easier, you can create two aliases:
alias resetsound='sudo rmmod -f snd_hda_intel;sleep 1;sudo modprobe snd_hda_intel power_save=0 power_save_controller=N;sleep 1'
alias testsound='aplay /usr/share/sounds/alsa/Front_Center.wav'
The Issues
I use Debian Stretch/Xfce as my Linux guest. It is a stable/speedy OS. VirtualBox guest additions are properly installed.
Under VirtualBox version 5.2, there are periodic noises in the sound system in the guest.
Under VirtualBox version 6.0.4, the noises are gone. But after a random period the guest won't play sound. Youtube will flash a waiting circle on any videos. This can be verified by the following command in a Terminal:
aplay /usr/share/sounds/alsa/Front_Center.wav
The above command won't return when the guest experiences this issue. A guest reboot will regain the sound.
Noticed the following error during Debian boot up:
snd_intel8x0 measure - unreliable dma position
Also the following error in syslog:
Mar 12 11:23:58 Angular pulseaudio[1534]: [alsa-sink-Intel ICH] alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write.
Mar 12 11:23:58 Angular pulseaudio[1534]: [alsa-sink-Intel ICH] alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_intel8x0'. Please report this issue to the ALSA developers.
Mar 12 11:23:58 Angular pulseaudio[1534]: [alsa-sink-Intel ICH] alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.
The Research
I spent many hours researching this issue. Besides reboot, some of the major things I have tried:
1. Force AC97 Frequency
2. Disable I/O APIC Setting in VirtualBox VM Settings
3. Observed the following error during guest boot up and cannot find a solution:
snd_intel8x0 measure - unreliable dma position
Submitted a kernel bug report to bugzilla.kernel.org
4. Reload ALSA
5. Suspect that it is a power saving issue of the virtual sound card. This leads to the solution.
The Theory
The virtual sound card enters into a sleep state and never wakes up. This makes the entire sound system stuck at trying waking up the sound card. This fits the symptom with the "aplay" command test.
There are two parameters related to the power saving feature of the sound card. Using "Intel HD Audio" sound card as an example, the parameters are:
/sys/module/snd_hda_intel/parameters/power_save
/sys/module/snd_hda_intel/parameters/power_save_controller
The above two parameters are actually two system files. In the Debian guest,
/sys/module/snd_hda_intel/parameters/power_save --> 0
/sys/module/snd_hda_intel/parameters/power_save_controller --> Y
The "Y" value indicates that the Debian guest is dynamically managing the power saving of sound card. This is obviously not needed and should be turned off. I tried to change it to N without much success. Upon guest reboot it will revert to Y. I have added an option entry to the following file:
/etc/modprobe.d/alsa-base.conf
/etc/modprobe.d/alsa-base.conf
The option entry is:
options snd-hda-intel power_save=0 power_save_controller=N
This sets the power_save_controller option to N at boot. But after a while, the sound still stops working. So changing power saving options does not solve the issue.
But the research on these parameters led to the following page:
The first post by "markoer" gave me the solution that I was long looking for: a reset of the sound system and regain sound without reboot.
The Solution
To test if the sound is working, use the below command:
aplay /usr/share/sounds/alsa/Front_Center.wav
Or the ALSA speaker-test command:
speaker-test
To reset and regain the sound system, run the following two commands.Or the ALSA speaker-test command:
speaker-test
sudo rmmod -f snd_hda_intel
sudo modprobe snd_hda_intel power_save=0 power_save_controller=N
Note the above script is for the "Intel HD Audio" sound card option in VirtualBox. The "AC97" audio controller requires a different mod which I have not tried and tested. The "SoundBlaster 16" option does not work in Linux.
I have many instances where I tried the reset commands and it did not work. I adjusted the volume on the host machine (Windows 10) to make sure that the host sound is OK. Then the sound worked!!!
No comments:
Post a Comment