LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices

Reply
 
Search this Thread
Old 03-20-2011, 08:59 PM   #1
xaos5
Member
 
Registered: Dec 2004
Distribution: debian and slackware
Posts: 217

Rep: Reputation: 31
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

Last edited by xaos5; 03-22-2011 at 02:48 AM.
 
Old 03-21-2011, 03:54 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
Old 03-22-2011, 02:47 AM   #3
xaos5
Member
 
Registered: Dec 2004
Distribution: debian and slackware
Posts: 217

Original Poster
Rep: Reputation: 31
Duh! I feel stupid for not checking that... Thanks.
 
Old 03-22-2011, 02:51 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,
Quote:
Originally Posted by xaos5 View Post
Duh! I feel stupid for not checking that...
That happens to the best of us
Quote:
Thanks.
You're welcome!
 
  


Reply

Tags
debian, network, udev


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slack 13.1 : /etc/udev/rules.d70-persistent-net.rules Ramurd Slackware 10 02-18-2011 09:56 AM
cat: /etc/udev/rules.d/70-persistent-net.rules: No such file or directory rcg1984 Linux From Scratch 2 09-17-2008 07:02 AM
Location for Custom udev Rules Toods Slackware 7 11-19-2007 12:42 PM
slackware-current, udev 0.96, and custom udev rules not working rignes Slackware 6 08-10-2006 03:43 AM
need help fixing my udev rules or ivman rules hedpe Linux - Hardware 2 03-18-2006 10:07 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration