How to get serial numbers of Linux devices?

To get a serial number we can use this command:

udevadm info -a -n /dev/ttyUSB0 | grep '{serial}' | head -n1

udevadm info -a -n /dev/disk/by-id/ata-OCZ-AGILITY3_OCZ-ABF89Y0W7J4E333X

After this we get CEK509 and we add to:

cat /etc/udev/rules.d/51-android.rules

example

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="1d6b", ATTRS{serial}=="CEK509", SYMLINK+="arduino"

tty – that can be for example usb

Other numbers we can get from command:

szymon@szymon:~$ lsusb
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 04f2:b1e5 Chicony Electronics Co., Ltd
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 002: ID 0b05:1788 ASUSTek Computer, Inc. BT-270 Bluetooth Adapter
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 093a:2521 Pixart Imaging, Inc. Optical Mouse
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

after this reload udev:

udevadm control --reload-rules && udevadm trigger

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *