Motherboard-First PCI Slot Mapper This article presents a Bash script that maps PCI slots on a motherboard by parsing `dmidecode` output to display slot names, types, and usage status. The script also integrates `lspci` data to show populated slots with device details, kernel drivers, and capabilities in a tree-like format. It requires root privileges to run and outputs a hierarchical view of physical PCI slot configurations. physical pci tree.sh This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters /bin/bash Ensure root privileges if " $EUID " -ne 0 ; then echo " Please run as root sudo . " exit 1 fi echo " ========================================================================================== " echo " 🌐 MOTHERBOARD PCI SLOT TREE & STATUS " echo " ========================================================================================== " Temporary files to hold processed blocks tmp block= " /tmp/dmi block.txt " rm -f " $tmp block " Read dmidecode output and split by Handle individual slot blocks dmidecode -t slot | while IFS= read -r line ; do if " $line " =~ ^Handle \ || -z " $line " ; then Process the previous block if it exists if -s " $tmp block " ; then Extract variables slot name= $ grep " Designation: " " $tmp block " | cut -d ' : ' -f2- | xargs slot type= $ grep " Type: " " $tmp block " | cut -d ' : ' -f2- | xargs slot usage= $ grep " Current Usage: " " $tmp block " | cut -d ' : ' -f2- | xargs bus addr= $ grep " Bus Address: " " $tmp block " | cut -d ' : ' -f2- | xargs Standardize bus address to match lspci format domain:bus:dev.fn - bus:dev.fn Example: 0000:01:00.0 becomes 01:00.0 pci addr= $ echo " $bus addr " | sed ' s/^ 0-9a-fA-F \{4\}:// ' Render Tree Structure echo " ├── 🔲 Slot: $slot name " echo " │ ├── Type: $slot type " if " $slot usage " = " In Use " && -n " $pci addr " && " $pci addr " = " 00:00.0 " ; then echo " │ ├── Status: ✅ POPULATED $pci addr " Fetch device details and format as sub-branches lspci -s " $pci addr " | while read -r dev line ; do echo " │ │ └── Device: ${dev line : 0-9a-fA-F 0-9a-fA-F . } " done Append full detail tree from lspci -v for this specific device lspci -v -s " $pci addr " | grep -E " Kernel driver|Capabilities|LnkSta: " | while read -r cap line ; do echo " │ │ └── $ echo " $cap line " | xargs " done else echo " │ └── Status: ❌ EMPTY " fi echo " │ " Clear block for next record " $tmp block " fi fi Append line to current block if inside a slot entry if -n " $line " && " $line " =~ ^ ; then echo " $line " " $tmp block " fi done echo " └── End of Component Mapping " echo " ========================================================================================== " Cleanup rm -f " $tmp block "