From f17155490f0b886fe08c8b72f00e728cce76ed18 Mon Sep 17 00:00:00 2001 From: "Oritorius(Denis Rykov)" Date: Wed, 9 Jul 2025 23:56:42 +0500 Subject: [PATCH] Update IOMMU-Groups.sh Add IOMMU-Groups.sh: List PCI devices grouped by IOMMU group This script scans IOMMU groups on the system and lists all associated PCI devices in a clear format. Features: - Lists each IOMMU group numerically. - Displays detailed device info using lspci. - Safe globbing with nullglob enabled. - Works in headless and minimal environments (no color output). Useful for troubleshooting PCIe passthrough setups in KVM/Proxmox environments. --- tools/IOMMU-Groups.sh | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/tools/IOMMU-Groups.sh b/tools/IOMMU-Groups.sh index 32544af..b9ce965 100755 --- a/tools/IOMMU-Groups.sh +++ b/tools/IOMMU-Groups.sh @@ -1,19 +1,35 @@ #!/bin/bash -# +# # Script: IOMMU-Groups.sh -# Goal: List PCI devices in IOMMU Groups -# +# Goal: List PCI devices in IOMMU Groups (no color output) +# # Author: Gabriel Luchina # https://luchina.com.br -# 20211118T0010 +# Original: 20211118T0010 +# Updated: 2025-04-05 +# + +# Check for root privileges +if [ "$EUID" -ne 0 ]; then + echo "Warning: It is recommended to run as root for full access." + echo "Press Enter to continue as a regular user, or CTRL+C to exit..." + read -r +fi shopt -s nullglob -for group in `ls /sys/kernel/iommu_groups/ | sort -V` -do - echo "IOMMU Group ${group##*/}:" - for device in /sys/kernel/iommu_groups/$group/devices/* - do - echo -e "\t$(lspci -nns ${device##*/})" +echo "IOMMU Group Devices:" + +for group in $(ls /sys/kernel/iommu_groups/ | sort -V); do + group_num=$(echo "$group" | sed 's/[^0-9]*//g') + echo "Group $group_num:" + for device in /sys/kernel/iommu_groups/$group/devices/*; do + dev_id="${device##*/}" + info=$(lspci -nns "$dev_id" 2>/dev/null || true) + if [[ -z "$info" ]]; then + echo -e "\t$dev_id (Unable to get info)" + else + echo -e "\t$info" + fi done done