Skip to content

Instantly share code, notes, and snippets.

@mpaolino
Last active September 26, 2020 01:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mpaolino/91c3587045fa8d1a9353b74bf102c83b to your computer and use it in GitHub Desktop.
Save mpaolino/91c3587045fa8d1a9353b74bf102c83b to your computer and use it in GitHub Desktop.
udev rules file to statically name sound cards in alsa and pulseaudio with the same vendor, product and serial id.
# This is a sample ude rules file to staticaly assign names to sound cards (in this case USB) that have the exact
# same product, vendor and serial number. This normally creates card names in pulseaudio that are a combination of this
# attributes plus an auto incrementing numbering, the problem is that the cards will get their names depending on the
# order the cards are plugged in.
# This udev rules fixes that issues by assigning a name to any card that is plugged in the same USB port, I don't know
# any other way.
#
# Name this file something like /etc/udev/rules.d/95-identical-cards-names.rules
# The list of cards should be changed to match your system, the only lines you are supposed to change/remove/add
# are DEVPATHs, look a the comments comments to see where to get the soundcard path.
#
#
# For alsa card naming (check with `cat /proc/asound/cards`)
#
SUBSYSTEM!="sound", GOTO="alsa_naming_end"
ACTION!="add", GOTO="alsa_naming_end"
# DEVPATH can be obtained by looking at `udevadm monitor --subsystem=sound` while pluging in the sound card.
# Do one card at a time, the "?" char on card should stay as it matches any card number that may pop on that USB port.
DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3.5/2-1.3.5:1.0/sound/card?", ATTR{id}="MyCard1"
DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3.7/2-1.3.7:1.0/sound/card?", ATTR{id}="MyCard2"
DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3.3/2-1.3.3:1.0/sound/card?", ATTR{id}="MyCard3"
DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3.1/2-1.3.1.4/2-1.3.1.4:1.0/sound/card?", ATTR{id}="MyCard4"
LABEL="alsa_naming_end"
#
# For pulsaudio card naming (check with `pacmd list-sources`)
#
# This could go in a separate file if you want
SUBSYSTEM!="sound", GOTO="pa_naming_end"
ACTION!="change", GOTO="pa_naming_end"
KERNEL!="card*", GOTO="pa_naming_end"
# Same as before, edit these lines at will. PulseAudio will notice the PULSE_NAME value and name the card with that.
DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3.5/2-1.3.5:1.0/sound/card?", ENV{PULSE_NAME}="MyCard1"
DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3.7/2-1.3.7:1.0/sound/card?", ENV{PULSE_NAME}="MyCard2"
DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3.3/2-1.3.3:1.0/sound/card?", ENV{PULSE_NAME}="MyCard3"
DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3.1/2-1.3.1.4/2-1.3.1.4:1.0/sound/card?", ENV{PULSE_NAME}="MyCard4"
LABEL="pa_naming_end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment