I am studying for a Linux certification from the Linux foundation but I have some questions about one lab. Here is the lab:

  1. Create and implement a rule on your system that will create a symlink called myusb when a USB device is plugged in.
  2. Plug in a USB device to your system. It can be a pendrive, mouse, webcam, etc. Note: If you are running a virtual machine under a hypervisor, you will have to make sure the USB device is seen by the guest, which usually is just a mouse click which also disconnects it from the host.
  3. Get a listing of the /dev directory and see if your symlink was created.
  4. Remove the USB device. (If it is a drive you should always umount it first for safety.)
  5. See if your symbolic link still exists in /dev.

what i did in terminal;

  1. Create a file named /etc/udev/rules.d/75-myusb.rules

    sudo vim /etc/udev/rules.d/75-myusb.rules
  2. and have it include just one line of content:

    SUBSYSTEM=="usb", SYMLINK+="myusb"
  3. restart udev service and check

    sudo /etc/init.d/udev restart    
    ls -lF /dev | grep myusb

But than no output from last command, no listing at all.

How can I check if the symlink was created?

  • 2
    I suggest you review the learning material for the module, or search here for similar questions e.g. SYMLINK in udev rule – steeldriver Jun 6 '16 at 5:05
  • thanx but i found no answer . – Mokum Jun 6 '16 at 6:52
  • I found this on Hackaday, hackaday.com/2009/09/18/how-to-write-udev-rules/#comments udev does not run these programs on any active terminal, and it does not execute them under the context of a shell. Be sure to ensure your program is marked executable, if it is a shell script ensure it starts with an appropriate shebang (e.g. #!/bin/sh), and do not expect any standard output to appear on your terminal. hmmm still confusing I would appreciate some help. – Mokum Jun 7 '16 at 2:01
  • 1
    It's right there in the link I posted (probably by someone doing the exact same assignment as you): SUBSYSTEM=="usb", SYMLINK+="myusb" – steeldriver Jun 7 '16 at 2:10
  • ok thanx steeldriver – Mokum Jun 7 '16 at 2:17

Few points

  • Used 75-, the rules run in order. There is a chance that your rule may overridden by next rules from /lib/udev/rules.d/, prefer to use 99- ~ 90-

  • SUBSYSTEM=="usb", SYMLINK+="myusb" too generic

    It match all event actions add, remove & change. Beside all USB devices. May be you should make it more strict.

    Check using lsusb

    Bus 003 Device 003: ID 0461:4d81 Primax Electronics, Ltd Dell N889 Optical Mouse

    and add them:

    ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0461", ATTRS{idProduct}=="4d81", SYMLINK+="myusb"
  • Not all devices create a node in /dev. (Could you mention what type of devices you have used)

  • Bonus :), even so the rule still broad concerning tree device nodes. When you plug camera there is not only one node created but many from tree root to the leaf (leaf is in most cases the wanted one). Check:

    udevadm info -a /dev/video0

    The previous modified rule may match two last nodes (not the leaf).

  • 1
    Ok thats very helpfull, i used :Bus 001 Device 005: ID 0471:0325 Philips (or NXP) SPC 200NC PC Camera – Mokum Jun 8 '16 at 10:41
  • @user23324, yes web cameras create node in /dev check ls -l /dev/video* your symlink will point to one of results. For easy testing plug & unplug run this on terminal and watch : watch "ls -l /dev/video* /dev/myusb " – user.dz Jun 8 '16 at 10:48
  • 1
    thanx that worked fine! @Sneetsher – Mokum Jun 8 '16 at 10:52
  • yes off course just did that. Thanx again ! – Mokum Jun 8 '16 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.