LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (http://www.linuxquestions.org/questions/debian-26/)
-   -   Custom udev rules not taking place? (http://www.linuxquestions.org/questions/debian-26/custom-udev-rules-not-taking-place-869872/)

xaos5 03-20-2011 08:59 PM

Custom udev rules not taking place?
 
I'm trying to write udev rules to make it easier to recognize the network cards in my server. After a reboot it doesn't seem to take place, what am I doing wrong? I'm running Debian Squeeze stable.

Code:

$ uname -a
Linux debian 2.6.32-5-amd64 #1 SMP Wed Jan 12 03:40:32 UTC 2011 x86_64 GNU/Linux

Code:

# ls -l /etc/udev/rules.d/
total 4
-rw-r--r-- 1 root root  689 Mar 14 04:07 01-network-names.rules
-rw-r--r-- 1 root root  613 Oct 30 20:38 10-vboxdrv.rules
-rw-r--r-- 1 root root 1371 Mar 12 17:38 70-persistent-net.rules
lrwxrwxrwx 1 root root  15 Oct 24 21:15 z60_hdparm.rules -> ../hdparm.rules

Code:

$ cat /etc/udev/rules.d/01-network-names.rules
#This file was created by David Rebbe

#$ ./net-info
#Name        MAC                        IRQ        SLOT
#eth0        6c:62:6d:ab:b1:5f        28        03:00.0
#eth2        00:e0:52:b7:a1:4f        20        04:05.0
#eth3        00:e0:52:b8:30:ef        21        04:06.0
#eth4        00:e0:52:b7:31:40        22        04:07.0
#eth5        00:0a:cd:1c:1c:89        27        04:07.0
#lo        00:00:00:00:00:00        0        Loopback device.


KERNEL=="eth?", SYSFS{address}=="6c:62:6d:ab:b1:5f", NAME="eth0"
#KERNEL=="eth?", SYSFS{address}=="00:00:00:00:00:00", NAME="eth1"
KERNEL=="eth?", SYSFS{address}=="00:e0:52:b7:a1:4f", NAME="eth2"
KERNEL=="eth?", SYSFS{address}=="00:e0:52:b8:30:ef", NAME="eth3-test"
KERNEL=="eth?", SYSFS{address}=="00:e0:52:b7:31:40", NAME="eth4"
KERNEL=="eth?", SYSFS{address}=="00:0a:cd:1c:1c:89", NAME="eth5"

Here is the script I used for the above, if anybody is interested:
Code:

#!/bin/bash
# Lists Network interfaces with their IRQ/MAC/Slot
# Copyright (C) 2010  David Rebbe
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

echo -e "Name\t\t\tMAC\t\t\tIRQ\tSLOT"
for dev in `/sbin/ifconfig -a | cut -d' ' -f 1 | xargs`
do
        # Find MAC address
        mac=`/sbin/ifconfig -a | grep $dev | grep HWaddr | awk '{print $(NF)}'`
        if [ -z $mac ]
        then
                mac="00:00:00:00:00:00"
        fi

        # Find IRQ matching interface 'name'
        #irq=`cat /proc/interrupts |grep $dev | awk '{print $1}' | tr -d ":"`
        #if [ -z $irq ];        then
        #        irq=-1
        #fi
        #if [[ $dev = "lo" ]]; then
        #        irq=0
        #fi
 
        # Find irq that matches in lspci
        # If the script is slow, its due to the following loop.
        matched_slot=false
        for slot in `lspci | grep Ether | awk ' {print $1}' | xargs`
        #for slot in `lspci | awk ' {print $1}' | xargs`
        do
                irq=`/sbin/ifconfig -a $dev | grep Int | awk '{ print $1 }' | sed 's|Interrupt:||'`
                if [[ -z $irq ]]; then
                        irq=-1
                fi
                lspci_irq=`lspci -v -s $slot | grep IRQ | awk '{print $(NF)}'`
                if [[ $irq = $lspci_irq ]]
                then
                        matched_slot=true
                        break
                fi
        done

        # echo output
        if [[ $matched_slot -eq true ]]
        then
                if [[ $irq -eq -1 ]]; then
                        slot="N/A"
                fi
                if [[ ${#dev} -lt 5 ]]; then
                        dev="$dev\t"
                fi
                echo -e "${dev}\t\t${mac}\t${irq}\t${slot}"
        fi
done


druuna 03-21-2011 03:54 AM

Hi,

Too my knowledge 01-network-names.rules is executed _before_ 70-persistent-net.rules. The latter will (partially?) overwrite the network cards rules created in the 01-network-names.rules file.

Personally I would add to/edit the 70-persistent-net.rules instead, but I guess you can also rename the 01-network-names.rules to 71-network-names.rules (71 or higher).

Hope this helps.

xaos5 03-22-2011 02:47 AM

Duh! I feel stupid for not checking that... Thanks.

druuna 03-22-2011 02:51 AM

Hi,
Quote:

Originally Posted by xaos5 (Post 4298862)
Duh! I feel stupid for not checking that...

That happens to the best of us :)
Quote:

Thanks.
You're welcome!


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