cd /news/hardware/motherboard-first-pci-slot-mapper Β· home β€Ί topics β€Ί hardware β€Ί article
[ARTICLE Β· art-10066] src=gist.github.com β†— pub= topic=hardware verified=true sentiment=Β· neutral

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.

read2 min views18 publishedMay 22, 2026

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/[1]{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 "


  1. 0-9a-fA-F β†©οΈŽ

── more in #hardware 4 stories Β· sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/motherboard-first-pc…] indexed:0 read:2min 2026-05-22 Β· β€”