12

How can I find out when a device is connected to my FreeBSD machine? Lets say I plug in a USB device, HDMI device, Bluetooth or something like that.

Can I have a console output to say [device] and gives some output about the device?

5 Answers5

6

All other answers are good, if you want only to check if a device is connected (checking kernel messages with dmesg, check in /var/log files and use some tools like usbconfig, pciconf or camcontrol).

But, if you want more (handle a message and execute a program or something like that when you plug your device), you can use devd.

When you connect a device, FreeBSD kernel will generate messages:

  • when you plug your device, an attach message is generated
  • when you unplug your device, a detach message is generated
  • and more (see devd.conf man page if you want more information).

FreeBSD uses devd by default, and its configuration is stored in /etc/devd/ and /etc/devd.conf. If you use linux, the same features exist with devfs and udev.

You can find some examples in /usr/share/examples/etc/devd.conf.

Jens
  • 1,752
  • 4
  • 18
  • 36
5

The lshal command will give you the DMI/SMBIOS hardware information (dmidecode under Linux)

You can list your connected USB device through:

camcontrol devlist 

Or :

usbconfig

To list pci devices:

pciconf -l

Also you can use the lsusb command under FreeBSD after Installing the usbutils package :

pkg install usbutils
GAD3R
  • 66,769
2

dmesg | grep -i USB will give you the list of connected

To get information about USB devices. usbconfig can help give it a try.

or

pciconf -lv pciconf diagnostic utility for the PCI bus

AReddy
  • 3,172
  • 5
  • 36
  • 76
1

You can output the kernel log with dmesg. The full log is in /var/log/messages. There you will find information when new devices are detected or have disappeared, and log entries about some other actions.

If you want to integrate scripts or programs, you can take a look at /etc/devd.conf (man page). This is a text file containing rules with match expressions and actions. In this way you can load modules and execute binaries/scripts when devices are registered.

0

You will always find info about new connected devices in dmesg and /var/log/messages.

For bluetooth you can check with: hcitool dev

For usb devices, try lsusb (-v).

Other useful commands: lshw (-short), hwinfo (--short) (if installed), lspci (-v), lsblk, df -h, fdisk -l, multipath -ll, mount, dmidecode, cat /proc/scsi/scsi, hdparm -i /dev/sda. There are multiple variations of these commands depending on your needs.

Future
  • 179
  • 1
    Is there a way to get console output without constantly rescanning the log messages? Isn't there some built in system so when a device is attached some type of notification is fired? I mean okay, how does the device get written to /var/log/messages. Can I intercept the call that writes the device to the log and just output it to the console instead? – user1610950 Sep 13 '16 at 07:36
  • 1
    You can use watch. For example: watch "grep usb /var/log/messages | tail -20" and watch "dmesg | grep usb | tail -15". Of course you can make a script to send an email for example when a change is detected (an usb is plugged/unplugged). See this thread for more info: http://unix.stackexchange.com/questions/116536/usb-connect-disconnect-notification – Future Sep 13 '16 at 08:01
  • 1
    @Futur'Fusionneur First you need to install usbutils to be allowed to use lsusb. – GAD3R Sep 16 '16 at 09:16