A Linux User Reference

Search tips
  • search ignores words that are less than 4 characters in length
  • searches are case insensitve
  • if a search does not return anything try it in Boolean mode then Query expansion mode by checking the appropriate radio button e.g. searching for 'cron' in just the Administration category returns nothing - presumably because the 50% threshold is reached. Boolean mode ignores this threshold so a search for 'cron' returns several hits
  • in Boolean mode preceding a word with a '+' means the result must include that word, a '-' means it must not
  • in Boolean mode '+crontab -anacron' means match articles about crontab that DO NOT mention anacron
  • to match a phrase e.g. 'manage system' check the Boolean mode radio button and enclose the phrase in quotes "some phrase ..."
  • in Query expansion mode the search context is expanded beyond the keywords you entered - relevancy of hits may well be degraded


Dynamic Device Management

  • Introduction
    • udev provides a dynamic device directory containing only the files for devices currently present
    • creates or removes device node files in '/dev'
    • renames network interfaces

    Usually runs as 'udevd' and receives device uevents directly from the kernel.

    $ ps aux | grep [Uu]dev
    root       334  0.0  0.0  17320   900 ?        S    12:37   0:00 upstart-udev-bridge --daemon
    root       336  0.0  0.0  21944  1756 ?        Ss   12:37   0:00 /sbin/udevd --daemon
    root      2351  0.0  0.0  21940  1308 ?        S    14:24   0:00 /sbin/udevd --daemon
    root      2352  0.0  0.0  21940  1308 ?        S    14:24   0:00 /sbin/udevd --daemon

    Stop, start, ... - /sbin/udevd

    # /etc/init.d/udev {status|start|stop|restart|reload|force-reload}
    $ service udev {status|start|stop|restart|reload|force-reload}
    $ service udev status
    udev start/running, process 336

    udev configuration file - /etc/udev.conf

    $ more udev.conf
    # The initial syslog(3) priority: "err", "info", "debug" or its
    # numerical equivalent. For runtime debugging, the daemons internal
    # state can be changed with: "udevadm control --log-priority=<value>".

    Configures logging

  • udev rules
    • when a device is added or removed from the system the kernel issues a 'uevent'
    • on receiving a 'uevent' 'udevd' uses configured rules to identify the device
    • the rules use device attributes provided in sysfs
    • a rule that matches a device can supply

      • additional device information
      • specify a device node name and multiple symlink names
      • instruct 'udev' to run additional programs as part of the device event handling
    • rule files are updated dynamically

    /etc/udev directory tree

    `-- udev.conf 
    |   `-- README 
    |-- 05-options.rules 
    |-- 05-udev-early.rules 
    |-- 20-names.rules 
    |-- 30-cdrom_id.rules 
    |-- 40-basic-permissions.rules 
    |-- 40-permissions.rules 
    |   |-- 95-hal.rules 
    |   |-- 95-udev-late.rules
    /etc$ tree -af udev
    ??? udev/rules.d
    ?   ??? udev/rules.d/70-persistent-cd.rules
    ?   ??? udev/rules.d/70-persistent-net.rules
    ?   ??? udev/rules.d/README
    ??? udev/udev.conf
  • A basic udev rule

    This is a rule to always ensure that the NIC with this mac address is named 'eth0'.


    # PCI device 0x10ec:0x8168 (r8169)
    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:1f:95:xx:xx:xx", \
    ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

    Not that practical but a rule ..

  • Using a program in a rule

    There are several machines with wireless adapters, IPs are obtained via DHCP. The adapters keep getting swapped between machines which results in the interface name changing. You want the same interface name whatever adapter is plugged in.

    Add a rule that allows any valid mac address to be named wlan0 - /etc/udev/rules.d/70-persistent-net.rules

    # USB device 0x:0x (rt73usb)
    # Whatever the mac address - use wlan0 for its name, could also just leave out the address attribute string.
    SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="??:??:??:??:??:??", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"

    The problem now is - what happens if more than one wireless adapter is plugged into a single system? You can cater for this scenario by adding a program to the rule.

    Assume that a small script '' exists to check if 'wlan0' exists or not. If it exists it outputs a string wlanN where N is the next interface number to use, if it does not exist it outputs wlan0.

    Modified rule to cater for more than one wireless adapter connected at the same time

    UBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="??:??:??:??:??:??", ATTR{type}=="1", KERNEL=="wlan*", PROGRAM="" NAME="%c"

    When a program used in a rule outputs a space-separated list of words these words can be accessed via the following variables -

    %c{N}        References each word where N is the position in the list starting from 1
    %k           Evaluates to the kernel name for the device (e.g.sda1)
    %n           Evaluates to the kernel number for the device (in this case 1).
  • udev management tool
    udevadm cmd [cmd specific options]
    udev<cmd>   [options]
    Some udev commands:
     udevadm info | udevinfo [options]                     Query udev db.  Get a devices sysfs representation,
                                                           helps in rule creation.
     udevadm trigger | udevtrigger [options]               Request kernel device uevents.
     udevadm settle | udevsettle [options]                 Watches uevent queue, exits if all current events 
                                                           are handled.
     udevadm control | udevcontrol [options] instruction   Modify the internal state of the running udev daemon.
     udevadm monitor | udevmonitor [options]               Listens to kernel uevents and udev rule events,
                                                           prints the devpath of the event to the console. 
       --environment                                       Print the complete environment for all events.
       --kernel                                            Print the kernel uevents.
       --udev                                              Print the udev event after the rule processing.
     udevadm test | udevtest [options] devpath             Simulate a udev event run for the given device and 
                                                           print debug output.
     udevadm version 
     udevadm help

    See man page for all options.

    Print all possible attributes (in rule format) for all devices starting with the one stated walking up the chain of parent devices

    # udevadm info --attribute-walk --name sda1 
      looking at device '/devices/pci0000:00/0000:00:0a.0/host0/target0:0:0/0:0:0:0/block/sda/sda1':
        ATTR{stat}=="   34  1218  1938  1576     0     0     0     0     0   960  1576"
      looking at parent device '/devices/pci0000:00/0000:00:0a.0/host0/target0:0:0/0:0:0:0/block/sda':

    Dump,list contents of udev DB

    $ udevadm info --export-db | head -n 8
    P: /devices/LNXSYSTM:00
    E: UDEV_LOG=3
    E: DEVPATH=/devices/LNXSYSTM:00
    P: /devices/LNXSYSTM:00/ACPI_CPU:00
    E: UDEV_LOG=3
    E: DEVPATH=/devices/LNXSYSTM:00/ACPI_CPU:00

    Get all udev info for a specific device

    $ udevadm info --query=all --path /block/sda/sda10
    P: /devices/pci0000:00/0000:00:0a.0/host0/target0:0:0/0:0:0:0/block/sda/sda10
    N: sda10
    S: block/8:10
    S: disk/by-id/scsi-SATA_ExcelStor_Techn_PVE301Q493Y51B-part10
    S: disk/by-id/ata-ExcelStor_Technology_J8160S_PVE301Q493Y51B-part10
    S: disk/by-path/pci-0000:00:0a.0-scsi-0:0:0:0-part10
    $ udevadm info --query=all --name sda10

    Print major/minor no. of device on which the file '/etc/modules' resides

    $ udevadm info --device-id-of-file /etc/modules
    $ udevadm info --query=all --path /block/sda/sda5 | grep -E '(MAJ|MIN)'
    E: MAJOR=8
    E: MINOR=5
  • List device attributes
    /sbin/udevadm info
    $ udevadm info --attribute-walk --name sdc1
    Udevadm info starts with the device specified by the devpath and then
    walks up the chain of parent devices. It prints for every device
    found, all possible attributes in the udev rules key format.
    A rule to match, can be composed by the attributes of the device
    and the attributes from one single parent device.
      looking at device '/devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/block/sdc/sdc1':
        ATTR{stat}=="     412    15217    16675     1840       43        5      135      532        0     1080     2372"
        ATTR{inflight}=="       0        0"
      looking at parent device '/devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/block/sdc':

    These attributes can be used in any rule for this device.

  • Monitor udev events

    Monitor dismounting, removing, adding and mounting fs on usb disk

    $ udevadm monitor --udev
    monitor will print the received events for:
    UDEV - the event which udev sends out after rule processing
    UDEV  [17088.375356] change   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/block/sdc (block)
    UDEV  [17088.382217] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/block/sdc/sdc1 (block)
    UDEV  [17088.398047] change   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/block/sdc (block)
    UDEV  [17097.991794] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/scsi_generic/sg3 (scsi_generic)
    UDEV  [17097.994399] remove   /devices/virtual/bdi/8:32 (bdi)
    UDEV  [17097.997544] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/bsg/3:0:0:0 (bsg)
    UDEV  [17097.997942] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/block/sdc (block)
    UDEV  [17098.002902] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/scsi_disk/3:0:0:0 (scsi_disk)
    UDEV  [17098.003962] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0/scsi_device/3:0:0:0 (scsi_device)
    UDEV  [17098.008742] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/scsi_host/host3 (scsi_host)
    UDEV  [17098.009598] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0/3:0:0:0 (scsi)
    UDEV  [17098.011223] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3/target3:0:0 (scsi)
    UDEV  [17098.012596] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0/host3 (scsi)
    UDEV  [17098.013663] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2/5-2:1.0 (usb)
    UDEV  [17098.015614] remove   /devices/pci0000:00/0000:00:10.0/usb5/5-2 (usb)
    UDEV  [17111.602933] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1 (usb)
    UDEV  [17111.607610] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0 (usb)
    UDEV  [17111.612332] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4 (scsi)
    UDEV  [17111.615282] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4/scsi_host/host4 (scsi_host)
    UDEV  [17112.599876] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4/target4:0:0 (scsi)
    UDEV  [17112.603856] add      /devices/virtual/bdi/8:32 (bdi)
    UDEV  [17112.606806] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4/target4:0:0/4:0:0:0 (scsi)
    UDEV  [17112.610118] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4/target4:0:0/4:0:0:0/scsi_device/4:0:0:0 (scsi_device)
    UDEV  [17112.612651] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4/target4:0:0/4:0:0:0/scsi_disk/4:0:0:0 (scsi_disk)
    UDEV  [17112.619929] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4/target4:0:0/4:0:0:0/bsg/4:0:0:0 (bsg)
    UDEV  [17112.621523] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4/target4:0:0/4:0:0:0/scsi_generic/sg3 (scsi_generic)
    UDEV  [17112.740809] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4/target4:0:0/4:0:0:0/block/sdc (block)
    UDEV  [17112.851644] add      /devices/pci0000:00/0000:00:10.0/usb5/5-1/5-1:1.0/host4/target4:0:0/4:0:0:0/block/sdc/sdc1 (block)