As an experimental feature (primarily due to being limited to Linux host only and unknown Linux distribution coverage) VirtualBox supports passing through the PC speaker to the host. The PC speaker (sometimes called system speaker) is a way to produce audible feedback such as beeps without the need for regular audio/sound card support.
The PC speaker passthrough feature in VirtualBox handles beeps only. Advanced PC speaker use by the VM (such as PCM audio) will not work, resulting in undefined host behavior.
Producing beeps on Linux is unfortunately a very complex topic. VirtualBox offers a collection of options, in an attempt to make this work deterministically and reliably on as many Linux distributions and system configurations as possible:
Table 9.4. PC speaker configuration options
Code | Device | Notes |
---|---|---|
1 |
/dev/input/ by-path/platform- pcspkr-event-spkr
|
Direct host PC speaker use. |
2 |
/dev/tty
|
Uses the terminal association of the VM process. VM needs to be started on a virtual console. |
3 | /dev/tty0 or
/dev/vc/0 |
Can only be used by user root
or users with capability cap_sys_tty_config |
9 | user specified console or evdev device path | Like 1-3, just with a custom device path. |
70 |
/dev/tty
|
Standard beep only. Loses frequency and length. See code 2. |
79 | user specified terminal device path | Like 70, just with a custom device path. |
100 | all of the above | Tries all above codes. |
To enable PC speaker passthrough use the following command:
VBoxManage setextradata "VM name" "VBoxInternal/Devices/i8254/0/Config/PassthroughSpeaker" N
Replace N
with the code representing the
case you want to use. Changing this setting will take effect when the VM is
started next. It is safe to enable PC speaker passthrough on all host OSes.
It will only have an effect on Linux.
The VM log file, VBox.log
, will
contain lines with the prefix PIT: speaker:
showing the PC speaker passthrough setup activities. It gives hints which
device it picked or why it failed.
Enabling PC speaker passthrough for the VM is usually the simple
part. The real difficulty is making sure that VirtualBox can access the
necessary device, because in a typical Linux install most of them can only
be accessed by user root
. You should
follow the preferred way to persistently change this, e.g. by referring to
your distribution's documentation. Since there are countless Linux
distribution variants, we can only give the general hints that there is
often a way to give the X11 session user access to additional devices, or
you need to find a working solution using a udev configuration file. If
everything fails you might try setting the permissions using a script
which is run late enough in the host system startup.
Sometimes additional rules are applied by the kernel to limit access (e.g. that the VM process must have the same controlling terminal as the device configured to be used for beeping, something which is often very difficult to achieve for GUI applications such as VirtualBox). The table above contains some hints, but generally refer to the Linux documentation.
If you have trouble getting any beeps even if the device permissions are set up and VBox.log confirms that it uses evdev or console for the PC speaker control, check if your system has a PC speaker. Some systems do not have one. Other complications can arise from Linux rerouting the PC speaker output to a sound card. Check if the beeps are audible if you connect speakers to your sound card. Today almost all systems have one. Finally, check if the audio mixer control has a channel named "beep" (could be hidden in the mixer settings) and that it isn't muted.