Introduction
The Raspberry Pi is a versatile single-board computer with a myriad of uses for DIY tech projects, media centers, network appliances, and more. As the Pi supports various methods for attaching additional devices through its GPIO pins, USB ports, wired networking, Bluetooth, and WiFi connectivity - users will likely want to interface it with everything from keyboards and mice to external hard drives and wireless peripherals.
Having the ability to clearly identify connected devices to your Raspberry Pi is crucial for effectively developing and maintaining projects built around the Pi. Whether you need to troubleshoot why a device isn't working, check for free space on attached storage drives, ensure the right peripherals are communicating with the board on startup, or closely monitor hardware access and events - there are a range of Linux terminal commands that provide detailed insight into connected device information and activity on this single-board computer.
Read on as we cover several highly utilitarian commands for checking connected USB and integrated devices on the Raspberry Pi. These will help you more deeply understand the breadth of your Pi's connectivity and how to parse the critical details.
Examining Attached USB Devices In-Depth with lsusb
The lsusb terminal command lists details on USB devices connected to the Raspberry Pi, whether through the Pi's onboard USB ports or an attached USB hub. Used without any options or arguments, lsusb provides a brief overview of connected USB device identities, displaying each device on a separate line including assigning a "bus" and "device" number. For example:
lsusb
Bus 001 Device 004: ID 04f2:b307 Chicony Electronics Co., Ltd
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
This output indicates there are currently 4 USB devices attached to the Raspberry Pi. Each one is mapped to the root USB hub controller under its own unique bus and device numbering scheme.
To garner more verbose and descriptive info on the USB products connected to the Pi, utilize lsusb with the "-v" parameter to produce multi-lineVerbose Output detailing the USB device descriptors:
lsusb -v
Bus 001 Device 004: ID 04f2:b307 Chicony Electronics Co., Ltd
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x04f2 Chicony Electronics Co., Ltd
idProduct 0x0489
bcdDevice 2.11
iManufacturer 1 KYE Systems Corp.
iProduct 2 HP Basic USB Keyboard
iSerial 0
bNumConfigurations 1
...
Now there is expanded info like the vendor ID, product ID, USB spec level supported, maximum packet size for the default endpoint zero, and descriptive strings for the manufacturer name, product name, and serial number - in this instance showing a basic HP-branded USB keyboard attached to our Pi.
Running lsusb with its "-t" option will generate a handy Tree Output view that presents the USB device connection hierarchy across controllers, hubs, and devices in an properly indented layout for easy understanding:
lsusb -t
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=musb-hdrc/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 1: Dev 3, If 0, Driver=smsc95xx, 480M
|__ Port 3: Dev 4, If 0, Driver=usbhid, 1.5M
In this structured view, you can clearly identify that our Raspberry Pi's root USB hub controller is connecting through a second USB hub device, with the Ethernet adapter on one port and USB keyboard on another downstream port of that hub. Taking the time to routinely view your Pi's USB configuration in this manner enables you to verify device associations and available bandwidth, as well ensure the expected devices appear at startup.
read more : How to work with Raspberry pi remotely
Auditing All Mounted Drives & Filesystems on the Raspberry Pi
Beyond externally connected peripherals themselves, users will often attach complete USB storage devices to the Raspberry Pi such as portable hard drives and flash media. The df command provides a quick report detailing all currently mounted drives and filesystems visible to the Raspberry Pi, including any externally attached storage.
Used by itself, df shows the filesystem device identifiers, total size, used space, available free space, capacity percentage utilized, and where each is mounted:
df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 1436052 133932 1242136 10% /
devtmpfs 475708 0 475708 0% /dev
tmpfs 485376 0 485376 0% /dev/shm
tmpfs 485376 8504 476872 2% /run
tmpfs 5120 4 5116 1% /run/lock
/dev/mmcblk0p1 258095 14927 243168 6% /boot
This provides a comprehensive overview of the storage volumes directly available to the Pi, spanning its primary OS filesystem, memory-based tmpfs volumes, and the boot partition on the microSD card where the Pi OS image resides.
To filter df command output to just show details on externally attached non-root volumes, pass the "-h" parameter to produce human readable file sizes and pipe to the grep command to filter for "/media" mount point prefixes typically used for attached drives:
df -h | grep /media
/dev/sda1 457G 33M 457G 1% /media/pi/EXTERNAL_DRIVE
Now the extraneous system volume entries are removed, allowing you to validate that your attached USB hard disk mounted properly with the correct size and availability. Carefully monitoring disk utilization over time will ensure you have adequate capacity for the data generated by your projects and applications running on the Raspberry Pi.
Examining The Raspberry Pi's Hardware Configuration Profile
While lsusb helps identify USB devices, to procure a complete hardware profile inventory - including details on the Pi board itself as well as integrated input devices, storage, graphics, networking, and more - employ the lshw command.
In its default standard output mode, lshw produces lengthy multi-page output displaying the Linux hardware description tree:
lshw
rpi ~$ lshw
raspberrypi
description: Computer
width: 64 bits
*-core
description: Motherboard
physical id: 0
*-memory
description: System memory
physical id: 0
size: 944MiB
*-cpu
product: ARMv7 Processor rev 4 (v7l)
vendor: ARM
physical id: 1
bus info: cpu@0
size: 700MHz
capacity: 700MHz
*-usb
description: USB controller
product: VL805 USB controller
...
This exposes very comprehensive details on each piece of hardware detected within the Pi system, spanning everything from the ARM processor model and clock speed to the video core GPU, mass storage identifiers, USB controllers, wireless circuitry, and more. To instead view a brief high-level hardware summary, use lshw with "-short" parameter:
lshw -short
H/W path Device Class Description
==================================================
system Raspberry Pi 4 Model B
/0/100 bus Raspberry Pi 4 SDRAM
/0/1000 memory LPDDR4 SDRAM
...
This truncated view provides quick confirmation of integrated hardware components without an overwhelming level of detail. The hierarchical device paths plainly lay out the association between connected memory chips, controllers, buses, and the Pi 4 motherboard itself.
Parsing Hardware Interactions & Events In Linux /proc/ Filesystem
Beyond querying hardware state with utilities like lsusb and lshw discussed above, the proc pseudo-filesystem provides a window into kernel managed device interactions in real-time. The /proc directory surfaces system information dynamically from the Linux kernel, without a persistent backing store.
So monitoring the /proc filesystem enables you to observe hardware events as they occur on your Pi:
watch -n 1 'ls -l /proc/bus/input/devices'
Every 1.0s: ls -l /proc/bus/input/devices
total 0
crw-rw---- 1 root input 13, 64 Dec 21 15:02 event0
crw-rw---- 1 root input 13, 65 Dec 21 15:02 mice
crw-rw---- 1 root input 13, 63 Dec 21 15:02 mouse0
This live view of /proc/bus/input/devices shows new mice and other input devices as they are connected and disconnected from the Pi's USB ports, using the "watch" command to rerun the ls command every 1 second to capture state changes.
Similarly, stripping away the root hub controller, you can monitor just changes to downstream USB devices:
watch -n 1 'ls -l /proc/bus/usb/001/'
Every 1.0s: ls -l /proc/bus/usb/001/
total 0
dr-xr-xr-x 2 root root 0 Dec 21 15:12 001
dr-xr-xr-x 2 root root 0 Dec 21 15:12 002
Here the /proc enumeration of USB bus 001 which represents the USB controller directly on the Pi board is inspected once a second, showing new device connection entries appearing as USB peripherals are attached.
This method can even enable detailed debugging by matching USB device log entries in /var/log/messages to a monitored device stubs within /proc/bus/usb numbered directories.
Conclusion
The Raspberry Pi is often the centerpiece of electronic projects that involve a menagerie of USB and integrated peripherals, external storage drives, sensors collecting field data, and other attached components. Without visibility into the identity, connectivity associations, and live activity of these devices - troubleshooting issues, ensuring data is flowing to the right locations, and understanding bandwidth usage would prove extremely difficult. Hopefully, this overview gives you a head start on precisely monitoring your Pi's hardware environment. Leveraging these detailed Linux commands within your administration scripts and applications will take your Raspberry Pi projects to the next level!