Advertisement
tolikpunkoff

findwin (find Windows loaders from linux)

Mar 26th, 2019
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. find_loader()
  4. {  
  5.     TMPMOUNT=0
  6.    
  7.     #check mountpoint
  8.     MOUNTPOINT=`mount|grep -w "$1"|awk '{print $3}'`
  9.    
  10.     if [ -z "$MOUNTPOINT" ]; then #not mount, mounting in temp mountpoint
  11.     mkdir -p "/tmp/tmpmount"
  12.     mount -t "$2" "$1" "/tmp/tmpmount"
  13.     if [ $? -ne 0 ]; then
  14.         echo "$1 not mounted"
  15.         return
  16.     fi
  17.     MOUNTPOINT="/tmp/tmpmount"
  18.     TMPMOUNT=1
  19.     fi
  20.    
  21.     #find loader
  22.    
  23.     #bootmg - Win Vista and newer
  24.     FOUND=`find "$MOUNTPOINT" -maxdepth 1 -iname "bootmgr"`
  25.     if [ -n "$FOUND" ];then
  26.     echo "$1: found bootmgr (Windows Vista and newer)"
  27.     else
  28.     #ntldr - Win XP and older
  29.     FOUND=`find "$MOUNTPOINT" -maxdepth 1 -iname "ntldr"`
  30.     if [ -n "$FOUND" ];then
  31.         echo "$1: found ntldr (Windows XP and older)"
  32.     else
  33.         echo "$1: Windows loader not found"
  34.     fi
  35.     fi
  36.    
  37.     if [ $TMPMOUNT -eq 1 ]; then
  38.     sleep 1
  39.     umount "/tmp/tmpmount"
  40.     fi
  41. }
  42.  
  43. echo "Find Windows loaders..."
  44.  
  45. IFS=$'\n'
  46.  
  47. for DEVDATA in $(blkid); do
  48.     VOL=`echo "$DEVDATA" |sed -n 's/\(.*:\).* TYPE=\"\([^\"]*\)\".*/\1\2/p'`
  49.    
  50.     VOLNAME=`echo "$VOL"|awk -F ":" '{print $1}'`
  51.     VOLFS=`echo "$VOL"|awk -F ":" '{print $2}'`
  52.    
  53.     if [ -n "$VOLFS" ]; then
  54.     if [[ "$VOLFS" == "ntfs" || "$VOLFS" == "vfat" ]];then
  55.         find_loader $VOLNAME  $VOLFS
  56.     else
  57.         echo "$VOLNAME not windows volume"
  58.     fi
  59.     fi
  60. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement