Hotpluggable HDMI Audio

Hotpluggable HDMI Audio


This was first written in 2011. It was before udev merged into systemd. It was before Arch Linux surrendered its soul to systemd.

Although it is outdated, some people have said they still refer to it. So, it can stay by popular demand. Proceed at your own risk.

Queue swimmy special effects and harp music as we travel back in time … back in time … back in time …


My laptop runs Arch Linux. Arch Linux targets people who want a simple and customisable system. A simple and customisable system doesn’t pre-empt what you want to happen when you (dis)connect a HDMI cable.

This how-to will help you set up HDMI hotplugging. The result will be that when you connect a HDMI cable, you will immediately get HDMI audio output, and when you disconnect the cable, your default settings will automatically be restored.

I assume:

  1. You’re running Arch Linux;
  2. You have synched ALSA from pacman;
  3. When you run aplay -l you obtain,
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC269VB Analog [ALC269VB Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0

The more your set-up differs to this, the more I invite you to demonstrate your independence.

We will work through three basic steps:

  1. Create two different ALSA configuration files.
  2. Create a script for switching between configurations.
  3. Create a udev rule that runs when the HDMI cable is (dis)connected; the rule calls the script for switching configurations.

  4. ALSA Configuration Files

For non-standard set-ups, ALSA will refer to one of two different configuration files, either ~/.asoundrc or /etc/asound.conf, as explained here. We will keep two different configuration files, and symbolically link /etc/asound.conf to the correct file.

We will keep the configuration files in /etc/alsa/. Create that directory if it doesn’t exist yet:

[[ -d /etc/alsa/ ]] || sudo mkdir -v /etc/alsa/

Place the following two files in /etc/alsa/:

2. ALSA Configuration Switcher Script

Also place the following script in /etc/alsa/: hdmi-switch. Ensure /etc/alsa/hdmi-switch has execute permisions, then test it with both the cable plugged in and not plugged in. Ensure the script successfully modifies your ALSA configuration before proceeding.

3. Create a udev rule to automate the configuration switching

Place the following file in /etc/udev/rules.d/: hdmi.rules. Make udev start using the new rule straight away by running:

sudo udevadm control --reload-rules

Voila! Revel in your new hotpluggable HDMI audio goodness.