LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   udev rules Slackware 11 (http://www.linuxquestions.org/questions/slackware-14/udev-rules-slackware-11-a-502209/)

swampdog2002 11-16-2006 09:19 AM

udev rules Slackware 11
 
Hello all,
I've been reading the document that many here have referred others to when creating udev rules. I have looked at this myself, but am somewhat confused as to how to apply this to Slackware 11. Basically, what I want to accomplish is the following:
  • create link to /dev/hdc using /dev/dvd-rom
  • create link to /dev/hdd using /dev/dvd-rw
  • create link from /dev/ttyS4 to /dev/modem

I am not sure where the main file that creates these udev rules in Slackware 11 is located, or if I have to create a new one to use. I would like to edit the existing one using the above links. Each time I create a symbolic link manually, it is gone after rebooting, which is something that I suppose udev does. Any information is appreciated. Thanks.

David the H. 11-16-2006 09:42 AM

Writing udev rules

Is this the page you've been looking at? To quote from it:

Quote:

Default udev rules are stored in /etc/udev/rules.d/50-udev.rules. You may find it interesting to look over this file - it includes a few examples, and then some default rules proving a devfs-style /dev layout. However, you should not write rules into this file directly.

Files in /etc/udev/rules.d/ are parsed in lexical order, and in some circumstances, the order in which rules are parsed is important. In general, you want your own rules to be parsed before the defaults, so I suggest you create a file at /etc/udev/rules.d/10-local.rules and write all your rules into this file.

In a rules file, lines starting with "#" are treated as comments. Every other non-blank line is a rule. Rules cannot span multiple lines.
(emphasis mine)

and

Quote:

In order to preserve the standard /dev layout, your own rules will typically leave the NAME alone but create some SYMLINKs and/or perform other assignments.

KERNEL=="hdc", SYMLINK+="cdrom cdrom0"

The above rule is probably more typical of the types of rules you might be writing. It creates two symbolic links at /dev/cdrom and /dev/cdrom0, both of which point at /dev/hdc. Again, no NAME assignment was specified, so the default kernel name (hdc) is used.
That should be pretty much all you need to know for what you want to do. If there are any differences between this and slack you should be able to figure them out pretty easily.

Good luck.

swampdog2002 11-16-2006 10:52 AM

Thanks for the reply. When I originally utilized this document, I did not have a 50-udev.rules file on my machine in the place that was specified within the document. I was going to look in there to see how the rules were setup prior to creating my own. I thought that rules that were already set up might collide with the ones that I was trying to create. Before 11, I did not bother with udev, but it seems to be an integral part of this new release. It seems pretty straightforward enough, so I'll see what I can come up with. Thanks.

hussar 11-16-2006 11:51 AM

That "Writing udev rules" site gets cited pretty often here in threads discussing udev, and for good reason.

One thing that bothers me a little though is the repeated reference to the statement that udev rules are in /etc/udev/rules.d/50-udev.rules. In slackware, they're not. At least they haven't been in udev-064, udev-071, or (the current version) udev-097. They are in /etc/udev/rules.d/udev.rules. So, if you want to bring your slack in line with the udev rules site, you need to move /etc/udev/rules.d/udev.rules to /etc/udev/rules.d/50-udev.rules and then write your own /etc/udev/rules.d/10-udev.rules.

swampdog2002 11-16-2006 12:05 PM

If I create my own udev rules in /etc/udev/rules.d and call the file 10-udev.rules as cited within the document, will udev still continue to load the original /etc/udev/rules.d/udev.rules as well, thereby overwriting the udev rules that were created by me? This is something that concerns me, but when I get the opportunity I shall find out with a trial-and-error session on my machine. I can always create a backup of the original udev.rules file and edit this directly, although this appears to be frowned upon by the documentation.

swampdog2002 11-17-2006 08:21 AM

I was able to successfully create my own udev rules by creating a file in /etc/udev/rules.d/10-udev.rules as the document explained and, for the most part, it seemed to work as expected. I had to manually edit the main udev.rules file for the floppy drive since, for some reason, I was receiving a message at startup stating that the link /dev/fd0 could not be created since it already existed. I don't know exactly how udev works, but other links for optical drives seemed to worked w/o any problems, but just commenting out a specific line (don't remember offhand) in udev.rules and creating my own rule seem to resolve this. The rules that I created were:

KERNEL=="fd0", SYMLINK+="floppy"
KERNEL=="hdc", SYMLINK+="dvd-rom"
KERNEL=="hdd", SYMLINK+="dvd-rw"

I don't know if these are necessarily ideal, but they seem to work for me.

David the H. 11-17-2006 01:52 PM

Glad to hear you got it to work.

As for the file names, AIUI, the primer page states that udev reads the config files in lexical order. so 10-udev.rules will be read before 50-udev.rules, and 50-udev.rules will be read before udev.rules. But every .rules file in the directory will be scanned in the end. So you slack users can rename the udev.rules if you want, or not, since either way it won't affect the loading order as long as you ensure that the local rules file has a lower alphanumeric sequence than the main one.

As for the floppy problem, perhaps the fact that the system needs a floppy drive at boot has something to do with it. I'm guessing the bootup process creates the fd0 device even before udev starts, so it naturally freaks out when it tries to create a device that's already there. Did udev go ahead and create the symlink in that case, or did the rule fail completely?

swampdog2002 11-17-2006 02:26 PM

Before I created my own udev rule for the floppy drive, and commented out the line in /etc/udev/rules.d/udev.rules, I would get a message stating that creation of /dev/fd0 failed due to the fact that this link already existed. I actually deleted both /dev/fd0 while logged in, and then rebooted. I still received the same message at startup, so perhaps something else was creating the /dev/fd0 link prior to udev, as you mentioned. However, with the rule that I created, it seems to be working alright, so I believe that I'll just leave it as is unless something else needs to be done.

urka58 11-17-2006 04:38 PM

Put this in you 10-udev.rules
# Floppy
KERNEL=="fd0", BUS=="platform", NAME="%k", SYMLINK+="floppy", GROUP="floppy", MODE="0660", OPTIONS+="last_rule"

Ciao

allend 11-17-2006 07:06 PM

If you want to create a link from /dev/ttyS4 to /dev/modem at boot up, add a symlink in the /lib/udev/devices directory using this command.
ln -s /dev/ttyS4 modem

ls -l modem should then give an output like this.
lrwxrwxrwx 1 root root 10 2006-11-02 00:49 modem -> /dev/ttyS4


All times are GMT -5. The time now is 01:13 AM.