Skip to content

Instantly share code, notes, and snippets.

@ngandrass
Created February 18, 2023 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngandrass/187d0db66a90ed702a187592367963e8 to your computer and use it in GitHub Desktop.
Save ngandrass/187d0db66a90ed702a187592367963e8 to your computer and use it in GitHub Desktop.
Map GPTID to disk / device identifier (e.g. ada0)
#!/bin/bash
# Create associative mapping array
declare -A GPTID_TO_DISKID
while read -r row; do
gptid=$(echo "$row" | cut -d ' ' -f1)
diskid=$(echo "$row" | cut -d ' ' -f3 | rev | cut -d 'p' -f2 | rev)
if [[ "$gptid" = "gptid"* ]]; then
GPTID_TO_DISKID[$gptid]=$diskid
fi
done < <(glabel status | tail -n +2 | tr -s ' ')
# Verbose logging
echo "Detected GPTID to disk identifier mappings:"
for gptid in "${!GPTID_TO_DISKID[@]}"; do
echo "-> [$gptid]=${GPTID_TO_DISKID[$gptid]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment