SHARE
TWEET

get syslinux MBR ID and partition ID

tolikpunkoff Jun 15th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. #get syslinux MBR ID and partition ID
  4.  
  5. SL_ID=""
  6.  
  7. get_slid() #$1 - device name (e.g. /dev/sda1)
  8. {
  9.     #get base name
  10.     T_BN=`basename $1`
  11.    
  12.     #get volume number
  13.     T_VOLNUM=`echo "$T_BN" | sed 's/^[a-z]*//'`
  14.    
  15.     #get disk name
  16.     T_DSKNAM=`echo "$1"|sed 's/[0-9]\+$//'`
  17.     if [ -z "$T_DSKNAM" ]; then
  18.         return 1 #error
  19.     fi
  20.    
  21.     #get MBR ID
  22.     #T_MBRID=`fdisk -l "$T_DSKNAM" | grep "Disk identifier"|awk '{print $3}'`
  23.     T_MBRID=`hexdump -s 440 -n 4 -e '"0x%08x\n"' "$T_DSKNAM"`
  24.    
  25.     SL_ID="mbr:$T_MBRID $T_VOLNUM"
  26.  
  27. }
  28.  
  29. if [ -z "$1" ]; then
  30.     echo "Use "`basename $0` "<device>"
  31.     exit
  32. fi
  33.  
  34. get_slid "$1"
  35.  
  36. if [ "$?" -ne 0 ];then
  37.     echo "Error!"
  38. else
  39.     echo "$1: $SL_ID"
  40. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top