Predictable video assignment for HD-PVR using udev¶
If you have more than one HD-PVR on your system then it is possible that they will occasionally swap positions on video0 and video1 after a reboot. The result of course is that then your channel changer will change the channel on one set top box (STB) and you will end up recording on another.
In order to prevent this, you can use udev rules to force assignment of specific HD_PVRs to specific video devices.
First, execute the following:
udevadm info -a -p $(udevadm info -q path -n /dev/video0)
and look for something like:
ATTRS{product}=="Hauppauge HD PVR" ATTRS{serial}=="xxxxxxxx"
where xxxxxxxx is the short form serial number of the HD PVR
Alternatively this can be found using:
udevadm info --query=all --name=/dev/video0
and look for
E: ID_SERIAL_SHORT=xxxxxxxx
Next, you need to create a file for udev to execute when an HD-PVR is found. The file should be /etc/udev/rules.d/ and you can call it something like 78-hdpvr.rules. This file will have the following content with one line for each HD-PVR you have:
KERNEL=="video[0-9]*" , ATTRS{product}=="Hauppauge HD PVR" , ATTRS{serial}=="xxxxxxxx" , NAME="v4l/video0", SYMLINK+="video0" KERNEL=="video[0-9]*" , ATTRS{product}=="Hauppauge HD PVR" , ATTRS{serial}=="yyyyyyyy" , NAME="v4l/video1", SYMLINK+="video1"
where xxxxxxxx and yyyyyyyy are the values obtained with udevadm.
To clarify, this will assign the HD-PVR with the matching serial number to /dev/v4l/videoX and create a symlink in /dev/videoX. The "+=" means preserve any other links created to these devices so be default on our system /dev/video will be the same symlink as /dev/video0.
If you want to verify that udev id doing what you want then you can use the following command:
udevadm test /class/video4linux/video0
substituting the appropriate video identifies (ie. video0 or video1). Read through the resulting output and verify that it executed your command and created the needed links.