-   Linux - General (
-   -   How does one change a system udev rule permanently? (

farnsy 03-12-2013 06:53 PM

How does one change a system udev rule permanently?
I'm running Fedora 18 and the udev rule /usr/lib/udev/rules.d/60-cdrom_id.rules has a "feature" in it that prevents me from disabling the hardware button on my cdrom drive (ordinarily I would do so using 'eject -i 1'). My toddler keeps pressing my eject button and driving me crazy.

I can edit the file and change it so eject behaves correctly but there's a big warning at the top of the file that says "do not edit this file, it will be overwritten on update." I have noticed that it has indeed been overwritten a few times with updates and I get bugged with going in and fixing it all the time.

If one isn't supposed to edit the files in /usr/lib/udev/rules.d by hand, where is it that one can modify what gets written to them?

Alternate solutions would be great as well. At present my top idea is to keep a copy of the file (edited) around somewhere and have a cron job overwrite the version in /usr/lib/udev/rules.d periodically. Not very elegant.

Emerson 03-12-2013 06:57 PM

Create 61-cdrom_id.rules? As a custom rule it should not be overwritten.

farnsy 03-12-2013 07:35 PM

That's a great idea! I probably need a bit more skill with udev to implement it, though. I just made an edited copy of the 60 version and called it 61-... but the behavior of the cdrom did not change. Probably I need to set up 61 so it overrides instead of adds to 60. For reference, here's the code in 60-cdrom_id.rules:


# do not edit this file, it will be overwritten on update

ACTION=="remove", GOTO="cdrom_end"
SUBSYSTEM!="block", GOTO="cdrom_end"
KERNEL!="sr[0-9]*|xvd*", GOTO="cdrom_end"
ENV{DEVTYPE}!="disk", GOTO="cdrom_end"

# unconditionally tag device as CDROM
KERNEL=="sr[0-9]*", ENV{ID_CDROM}="1"

# media eject button pressed
ENV{DISK_EJECT_REQUEST}=="?*", RUN+="cdrom_id --eject-media $devnode", GOTO="cdrom_end"

# import device and media properties and lock tray to
# enable the receiving of media eject button events
IMPORT{program}="cdrom_id --lock-media $devnode"

KERNEL=="sr0", SYMLINK+="cdrom", OPTIONS+="link_priority=-100"


and the 61 version is the same except the line starting with ENV{DISK_EJECT_REQUEST} is commented out. I suppose I need a way to remove the 60 version before implementing the 61. Am I going the right direction?

rknichols 03-12-2013 07:35 PM

Put your modified 60-cdrom_id.rules file in /etc/udev/rules.d . That's where local overrides go. From `man 7 udev`:

Rule files are required to have a unique name, duplicate file names are ignored.
Files in /etc/udev/rules.d/ have precedence over files with the same name in
/lib/udev/rules.d/. This can be used to ignore a default rules file if needed.

farnsy 03-12-2013 07:46 PM

That worked perfectly. Thanks rknichols! I'll be sure to read the man page more carefully next time.

So the solution is to put a rule of the exact same name in /etc/udev/rules.d.

sundialsvcs 03-12-2013 08:11 PM

Or, you could re-program your toddler . . . ;)

farnsy 03-13-2013 12:52 AM

Haha, working on it. :)

All times are GMT -5. The time now is 05:05 PM.