Helper scripts for udev configuration in Chapter 7

Reece Dunn msclrhd at
Sun Sep 30 10:07:57 PDT 2007


These are some scripts I have written to auto-detect what network card
and cd drive udev rules to use:

cat > detect-cd << "EOF"
# Written by Reece H. Dunn <msclrhd at>

for block in `find /sys/block -maxdepth 1 -name [sh]d* | sed 's@/sys@@'`; do
  udevtest ${block} > tmp/udev-info
  if [[ `cat /tmp/udev-info | grep -F "ID_TYPE=cd"` ]]; then
    MODEL=`cat /tmp/udev-info | grep -F "ID_MODEL" | sed
"s at .*ID_MODEL=\(.*\)'@\1@"`
    REVISION=`cat /tmp/udev-info | grep -F "ID_REVISION" | sed
"s at .*ID_REVISION=\(.*\)'@\1@"`

    echo "SUBSYSTEM==\"block\", ENV{ID_MODEL}==\"${MODEL}\",
ENV{ID_REVISION==\"${REVISION}\", SYMLINK+=\"cdrom dvd\"}"
  rm /tmp/udev-info

cat > detect-net << "EOF"
# Written by Reece H. Dunn <msclrhd at>

for net in `grep -H . /sys/class/net/*/address | sed -e
'/:00:00:00:00:00:00/d'`; do
  address=`echo $net | sed -e 's at .*address:\(.*\)@\1@'`
  name=`echo $net | sed -e 's at .*net/\(.*\)/address.*@\1@'`
  echo "ACTION==\"add\", SUBSYSTEM==\"net\",
SYSFS{address}==\"${address}\", NAME=\"${name}\""

These can then be used like this:

    ./detect-cd > /etc/udev/rules.d/82-cdrom.rules
    ./detect-net  > /etc/udev/rules.d/26-network.rules

The detect-cd script will only work properly with machines that only
have one CD, as it always uses the same symlink for the CD devices.

Are these useful to include in the LFS book?

- Reece

More information about the lfs-dev mailing list