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?
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?
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:
attach message is generateddetach message is generated 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.
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
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
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.
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.
usbutils to be allowed to use lsusb.
– GAD3R
Sep 16 '16 at 09:16
dmesgdisplays the same whether device was plugged in or not – Abel Melquiades Callejo Jun 04 '21 at 12:25