{"slug": "motherboard-first-pci-slot-mapper", "title": "Motherboard-First PCI Slot Mapper", "summary": "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.", "body_md": "physical_pci_tree.sh\n\n      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.\n      \nLearn more about bidirectional Unicode characters\n\n \n    Show hidden characters\n\n#!\n/bin/bash\n\n#\n Ensure root privileges\n\nif\n [ \n\"\n$EUID\n\"\n \n-ne\n 0 ]\n;\n \nthen\n\n \necho\n \n\"\nPlease run as root (sudo).\n\"\n\n \nexit\n 1\n\nfi\n\necho\n \n\"\n==========================================================================================\n\"\n\necho\n \n\"\n🌐 MOTHERBOARD PCI SLOT TREE & STATUS\n\"\n\necho\n \n\"\n==========================================================================================\n\"\n\n#\n Temporary files to hold processed blocks\n\ntmp_block=\n\"\n/tmp/dmi_block.txt\n\"\n\nrm -f \n\"\n$tmp_block\n\"\n\n#\n Read dmidecode output and split by Handle (individual slot blocks)\n\ndmidecode -t slot \n|\n \nwhile\n IFS= \nread\n -r line\n;\n \ndo\n\n \nif\n [[ \n\"\n$line\n\"\n \n=~\n ^Handle\n\\ \n ]] \n||\n [[ \n-z\n \n\"\n$line\n\"\n ]]\n;\n \nthen\n\n \n#\n Process the previous block if it exists\n\n \nif\n [ \n-s\n \n\"\n$tmp_block\n\"\n ]\n;\n \nthen\n\n \n#\n Extract variables\n\n            slot_name=\n$(\ngrep \n\"\nDesignation:\n\"\n \n\"\n$tmp_block\n\"\n \n|\n cut -d\n'\n:\n'\n -f2- \n|\n xargs\n)\n\n            slot_type=\n$(\ngrep \n\"\nType:\n\"\n \n\"\n$tmp_block\n\"\n \n|\n cut -d\n'\n:\n'\n -f2- \n|\n xargs\n)\n\n            slot_usage=\n$(\ngrep \n\"\nCurrent Usage:\n\"\n \n\"\n$tmp_block\n\"\n \n|\n cut -d\n'\n:\n'\n -f2- \n|\n xargs\n)\n\n            bus_addr=\n$(\ngrep \n\"\nBus Address:\n\"\n \n\"\n$tmp_block\n\"\n \n|\n cut -d\n'\n:\n'\n -f2- \n|\n xargs\n)\n\n \n#\n Standardize bus address to match lspci format (domain:bus:dev.fn -> bus:dev.fn)\n\n \n#\n Example: 0000:01:00.0 becomes 01:00.0\n\n            pci_addr=\n$(\necho \n\"\n$bus_addr\n\"\n \n|\n sed \n'\ns/^[0-9a-fA-F]\\{4\\}://\n'\n)\n\n \n#\n Render Tree Structure\n\n \necho\n \n\"\n├── 🔲 Slot: \n$slot_name\n\"\n\n \necho\n \n\"\n│   ├── Type:  \n$slot_type\n\"\n\n \n\n \nif\n [ \n\"\n$slot_usage\n\"\n \n=\n \n\"\nIn Use\n\"\n ] \n&&\n [ \n-n\n \n\"\n$pci_addr\n\"\n ] \n&&\n [ \n\"\n$pci_addr\n\"\n \n!=\n \n\"\n00:00.0\n\"\n ]\n;\n \nthen\n\n \necho\n \n\"\n│   ├── Status: ✅ POPULATED (\n$pci_addr\n)\n\"\n\n \n\n \n#\n Fetch device details and format as sub-branches\n\n                lspci -s \n\"\n$pci_addr\n\"\n \n|\n \nwhile\n \nread\n -r dev_line\n;\n \ndo\n\n \necho\n \n\"\n│   │   └── Device: \n${dev_line\n#*:\n[0-9a-fA-F][0-9a-fA-F].\n*\n }\n\"\n\n \ndone\n\n \n\n \n#\n Append full detail tree from lspci -v for this specific device\n\n                lspci -v -s \n\"\n$pci_addr\n\"\n \n|\n grep -E \n\"\n(Kernel driver|Capabilities|LnkSta:)\n\"\n \n|\n \nwhile\n \nread\n -r cap_line\n;\n \ndo\n\n \necho\n \n\"\n│   │       └── \n$(\necho \n\"\n$cap_line\n\"\n \n|\n xargs\n)\n\"\n\n \ndone\n\n \nelse\n\n \necho\n \n\"\n│   └── Status: ❌ EMPTY\n\"\n\n \nfi\n\n \necho\n \n\"\n│\n\"\n\n \n\n \n#\n Clear block for next record\n\n \n>\n \n\"\n$tmp_block\n\"\n\n \nfi\n\n \nfi\n\n \n\n \n#\n Append line to current block if inside a slot entry\n\n \nif\n [[ \n-n\n \n\"\n$line\n\"\n ]] \n&&\n [[ \n!\n \n\"\n$line\n\"\n \n=~\n ^\n#\n ]]; then\n\n \necho\n \n\"\n$line\n\"\n \n>>\n \n\"\n$tmp_block\n\"\n\n \nfi\n\ndone\n\necho\n \n\"\n└── [End of Component Mapping]\n\"\n\necho\n \n\"\n==========================================================================================\n\"\n\n#\n Cleanup\n\nrm \n-f\n \n\"\n$tmp_block\n\"", "url": "https://wpnews.pro/news/motherboard-first-pci-slot-mapper", "canonical_source": "https://gist.github.com/Tranquility2/745bebf54c60f253c31c467b1c89ba8f", "published_at": "2026-05-22 17:48:51+00:00", "updated_at": "2026-05-22 21:36:17.693347+00:00", "lang": "en", "topics": ["hardware", "developer-tools", "open-source"], "entities": [], "alternates": {"html": "https://wpnews.pro/news/motherboard-first-pci-slot-mapper", "markdown": "https://wpnews.pro/news/motherboard-first-pci-slot-mapper.md", "text": "https://wpnews.pro/news/motherboard-first-pci-slot-mapper.txt", "jsonld": "https://wpnews.pro/news/motherboard-first-pci-slot-mapper.jsonld"}}