Fixing Audio in Linux Guests | VirtualBox

I use VirtualBox to use Ubuntu in a Windows host environment. It’s not perfect, but it’s free and it works fairly well. The one major issue I have is the audio in the Linux (Ubuntu) guest. Sometimes, especially after using RDP to log into the Windows host, the audio in the Ubuntu guest gets screwed up. I’ve found several workarounds and a potential fix for audio issues with Ubuntu guests under VirtualBox, so I thought I’d share.

The first thing to do in this situation is to make sure your host audio (ie, Windows audio) works. Usually changing the volume level will make a sound, or you can load up the Sounds control panel and play some of the sample sounds there. If you can’t hear anything from these Windows sounds, you’ve got a Windows sound related issue, and your problem is probably not VirtualBox or your Ubuntu guest.

Then, you want to make sure that you’re not just having a problem with the application playing sounds. The easy way to test and see if this is the case is using aplay:

[email protected]$ aplay /usr/share/sounds/alsa/Front_Center.wav

This should play a sound out your speakers or your headphones. If you can’t hear this, and you’ve confirmed that the volume is up in your Ubuntu guest, you may find some of these fixes useful.

The Messy Way

The “hard way” to work around this is to:

  1. Shut down your Linux (ie, Ubuntu) guest
  2. Load the VirtualBox app again in your host OS (ie, Windows/OSX)
  3. Change the Audio Controller setting of the Linux guest. Usually I switch between the “Intel HD” and the “AC 97” audio options. Whichever one it was previously, I switch to the other.
  4. Start the Ubuntu guest again

Audio ought to work for a while after this.

However, this is messy, and requires that you shut down your Linux guest virtual machine and restart VirtualBox. This means you’ve got to stop whatever you’re doing, which sucks. Recently I found another solution.

Fixing the AC97 Driver

First, make sure you’ve set your audio to ICH AC97 in the Audio tab of the configuration interface.

Then, check to see if you’re having a clocking problem. Use this command:

[email protected]$ dmesg | less

Search for “ac97” by typing /ac97 and hitting enter.

If you see lines like:

intel8x0_measure_ac97_clock: measured 853869 usecs
intel8x0: clocking to 41161

…then this fix will probably work for you. Apparently the Intel AC97 driver tries to guess the clock rate of the emulated chip and fails. This bug was reported here and that’s where I got this workaround from.

Edit the file /etc/modprobe.d/alsa-base.conf in your favorite editor. (Note: the file and location may vary depending on the Linux distro – this works in Ubuntu 12.04 LTS, though)

You’ll have to be root for this. For instance:

sudo nano /etc/modprobe.d/alsa-base.conf

At the bottom of the file, add this line:

options snd-intel8x0 ac97_clock=48000

Then save and exit. (In nano, this is Ctrl-O to save, then Ctrl-X to exit)

You’ll have to reboot, but hopefully afterwards your audio problems will be solved and stay that way!

The “Reset Linux Audio” Fix

Sometimes I’ve run into situations where the audio subsystem glitches for whatever reason, and nothing short of a reboot seems to fix it. I’ve found that the following command helps though:

pulseaudio -k && sudo alsa force-reload

This will kill the audio subsystem and reload it, which will often immediately fix an ongoing audio issue.

If you’ve got other VirtualBox Linux audio issues that you managed to solve, feel free to leave a comment to help the rest of us…