Skip to content

Instantly share code, notes, and snippets.

@teknoraver
Created July 13, 2023 13:17
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 teknoraver/2f77a0a40b7294bf1b90f04b177382fb to your computer and use it in GitHub Desktop.
Save teknoraver/2f77a0a40b7294bf1b90f04b177382fb to your computer and use it in GitHub Desktop.
Given a partitioned block device, return the device representing the whole disk
#!/bin/sh
dev=$1
dev=$(realpath "$dev")
dev=$(basename "$dev")
sys="/sys/class/block/$dev"
if [ -f "$sys/partition" ]; then
dev=$(realpath "$sys/..")
dev=$(basename "$dev")
fi
echo "/dev/$dev"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment