Advertisement
tolikpunkoff

check partition boot flag

Apr 21st, 2019
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.82 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ -z "$1" ]; then
  4.    
  5.     echo -n "Use " `basename $0` "<device>"
  6.     echo
  7.     echo "<device> - e.g. /dev/sda1"
  8. fi
  9.  
  10. DEV=`echo "$1" | sed 's/[0-9]\+$//'`
  11. PART=`echo "$1"|sed 's/[^0-9]//g'`
  12.  
  13. if [ -z "$DEV" ];then
  14.     echo "Bad device!"
  15.     exit 1
  16. fi
  17.  
  18. if [ -z "$PART" ];then
  19.     echo "Bad partition!"
  20.     exit 1
  21. else
  22.     if [ "$PART" -eq 0 ];then
  23.     echo "Bad partition!"
  24.     exit 1
  25.     fi
  26. fi
  27.  
  28. PARTREC=$(dd if=$DEV bs=1 count=16 status=none skip=$((0x1BE + 16 * ($PART - 1) )) | od -t x1 -A n |awk '{print $1}')
  29.  
  30. if [ -z "$PARTREC" ];then
  31.     echo "Data error"
  32.     exit 1
  33. fi
  34.  
  35. case "$PARTREC" in
  36.     00)
  37.     echo "$DEV$PART is NOT active partition ($PARTREC)"
  38.     ;;
  39.     80)
  40.     echo "$DEV$PART is ACTIVE partition ($PARTREC)"
  41.     ;;
  42.     *)
  43.     echo "$DEV$PART Result unknow ($PARTREC)"
  44.     ;;
  45. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement