Create a symlink in /dev using /etc/udev/rules
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 use99-
~90-
SUBSYSTEM=="usb", SYMLINK+="myusb"
too genericIt 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).
Related videos on Youtube
Mokum
I am a ubuntu enthousiast, learning every day how linux works. Also interested in grub 2 to use different or more distros all to learn more about linux.regards Harry.
Updated on September 18, 2022Comments
-
Mokum over 1 year
I am studying for a Linux certification from the Linux foundation but I have some questions about one lab. Here is the lab:
- Create and implement a rule on your system that will create a symlink called myusb when a USB device is plugged in.
- 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.
- Get a listing of the /dev directory and see if your symlink was created.
- Remove the USB device. (If it is a drive you should always umount it first for safety.)
- See if your symbolic link still exists in /dev.
what i did in terminal;
Create a file named
/etc/udev/rules.d/75-myusb.rules
sudo vim /etc/udev/rules.d/75-myusb.rules
and have it include just one line of content:
SUBSYSTEM=="usb", SYMLINK+="myusb"
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?
-
steeldriver almost 8 yearsI suggest you review the learning material for the module, or search here for similar questions e.g. SYMLINK in udev rule
-
Mokum almost 8 yearsthanx but i found no answer .
-
Mokum almost 8 yearsI 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.
-
steeldriver almost 8 yearsIt's right there in the link I posted (probably by someone doing the exact same assignment as you):
SUBSYSTEM=="usb", SYMLINK+="myusb"
-
Mokum almost 8 yearsok thanx steeldriver
-
user.dz almost 8 years@user23324, I saw your deleted entry below, could you edit your question and update it.
-
Mokum almost 8 years@Sneetsher i tried deleting the answer , i did not work.
-
user.dz almost 8 years@user23324, it's ok , it already deleted, it can seen only by you and 10K users.
-
Mokum almost 8 yearsOk thats very helpfull, i used :Bus 001 Device 005: ID 0471:0325 Philips (or NXP) SPC 200NC PC Camera
-
user.dz almost 8 years@user23324, yes web cameras create node in
/dev
checkls -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 "
-
Mokum almost 8 yearsthanx that worked fine! @Sneetsher
-
Mokum almost 8 yearsyes off course just did that. Thanx again !