Skip to content

Instantly share code, notes, and snippets.

@mpaolino
Last active August 7, 2023 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mpaolino/f29954781ee1242c753ccfa387a9e652 to your computer and use it in GitHub Desktop.
Save mpaolino/f29954781ee1242c753ccfa387a9e652 to your computer and use it in GitHub Desktop.
udev sample rules to make alsa a pulseaudio name USB sound cards with the same product, vendor 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` and 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 this block at will.
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