bootinfo

  1. #!/bin/bash
  2. VERSION=0.54
  3. DATE="February 14th, 2010"
  4. #to use this script:
  5. #
  6. #     sudo bash boot_info_script054.sh
  7. #or
  8. #     su -
  9. #     bash boot_info_script054.sh
  10. #
  11. #
  12. ### last-modified
  13. #
  14. #author  Ulrich Meierfrankenfeld (aka meierfra.)
  15. # with  contributions from caljohnsmith
  16. # (both members of ubuntuforums.org)
  17. # and Gert Hulselmans
  18. #
  19. #hosted at: http://sourceforge.net/projects/bootinfoscript/
  20. #
  21. #The birth of the boot info script:
  22. #   http://ubuntuforums.org/showthread.php?t=837791
  23. #
  24. #Looks at all MBRs and identifies the boot loader.
  25. #   For Grub and Supergrub:  displays the controlling partition.
  26. #   If the  MBR is unknown, displays the whole MBR.
  27. #Looks at all  partitions:
  28. #   Determines their type
  29. #   Identifies their boot sectors.
  30. #         For grub: displays the controlling partition and the offset
  31. #         of the stage2 file as recorded in the boot sector.
  32. #         For NTFS and Fat, examines the Boot Parameter Block for errors.
  33. #   Identifies the operating system
  34. #   Lists  boot programs.
  35. #   Displays the partition table
  36. #   Displays "blkid -c /dev/null"
  37. #   Finds  boot directories and displays their contents.
  38. #   Looks in "/" and "NST" for  bootpart codes  and displays the offset
  39. #                and boot drive it is trying to chainload
  40. #   Looks on "/" and "/NST" for stage1 files and displays the offset
  41. #         and bootdrive of the stage 2  files is trying to chainload.
  42. #   Displays  boot configuration files.
  43. #   Is able to search LVM partitions if  the LVM2 package is install
  44. #      ("apt-get install lvm2"  in debian based  distros)
  45. #   Is able to search Linux Software Raid partitions (MD Raids) if
  46. #       the "mdadm" package is installed.
  47. #   If dmraid is installed, searches all raid drives, detected by dmraid.
  48. #All information is written to the file "RESULTS.txt" in the
  49. #    same folder as the script. But  when run from /bin, /sbin, /usr/bin,
  50. #    or  other system folder the file "RESULTS.txt" is written to the
  51. #    home directory of the user who runs this script.
  52.  
  53.  
  54. ###### Display version and date of the script when asked:
  55. # ./boot_info_script -v
  56. # ./boot_info_script -V
  57. # ./boot_info_script --version
  58. if [ x"$1" = x'-v' ] || [ x"$1" = x'-V' ] || [ x"$1" = x'--version' ] ;
  59. then
  60.     echo "boot_info_script version $VERSION"
  61.     echo "Dated , $DATE"
  62.     exit 0
  63. fi
  64.  
  65.  
  66. ###### Check if all necessary programs are available
  67.  
  68. Programs="
  69.    awk
  70.    basename
  71.    blkid
  72.    cat
  73.    dd
  74.    dirname
  75.    expr
  76.    fdisk
  77.    filefrag
  78.    fold
  79.    grep
  80.    hexdump
  81.    losetup
  82.    ls
  83.    mkdir
  84.    mount
  85.    pwd
  86.    rm
  87.    sed
  88.    sort
  89.    umount
  90.    wc
  91.    whoami"
  92.  
  93. Check_Prog=1;
  94.  
  95. for Program in $Programs ; do
  96.  
  97.     if ! type $Program > /dev/null 2>&1 ; then
  98.     echo \"$Program\" could not be found. >&2
  99.     Check_Prog=0;
  100.     fi
  101. done
  102.  
  103. if [ $Check_Prog -eq 0 ];
  104. then
  105.    echo "Please install the  missing program(s) and run boot_info_script again." >&2
  106.    exit 1;
  107. fi;
  108.  
  109.  
  110.  
  111.  
  112. ###### check whether user is root
  113.  
  114. if [ $(whoami) != "root" ];
  115. then
  116.    echo  Please use \"sudo\" or become \"root\" to run this script. >&2;
  117.    exit 1;
  118. fi;  
  119.  
  120. ########  List of folders which might contained files used for chainloading
  121. Boot_Codes_Dir="
  122.    /
  123.    /NST/
  124.    "
  125. #################  List of folders whose content will be displayed
  126. ################# Since all the important files in these folder are already displayed
  127. ################# it doesn't seem necessary to display the contents of these folders.
  128. #Boot_Dir="
  129. #   /Boot
  130. #    /boot
  131. #    /BOOT
  132. #    /boot/grub
  133. #    /grub
  134. #    /ubuntu/disks
  135. #    /ubuntu/disks/boot/
  136. #    /ubuntu/disks/boot/grub
  137. #    /ubuntu/disks/install/boot
  138. #    /ubuntu/disks/boot/grub
  139. #    /NST
  140. #    "
  141.  
  142.  
  143. ##############  List of files whose names will be displayed (if they exists)
  144. Boot_Prog_Normal="
  145.     /bootmgr /BOOTMGR
  146.     /boot/bcd /BOOT/bcd /Boot/bcd  /boot/BCD /BOOT/BCD  /Boot/BCD
  147.     /Windows/System32/winload.exe /WINDOWS/system32/winload.exe /WINDOWS/SYSTEM32/winload.exe /windows/system32/winload.exe
  148.     /Windows/System32/Winload.exe /WINDOWS/system32/Winload.exe /WINDOWS/SYSTEM32/Winload.exe /windows/system32/Winload.exe
  149.     /grldr /GRLDR
  150.     /ntldr /NTLDR
  151.     /NTDETECT.COM    /ntdetect.com
  152.     /NTBOOTDD.SYS    /ntbootdd.sys
  153.     /wubildr.mbr    /ubuntu/winboot/wubildr.mbr
  154.     /wubildr    /ubuntu/winboot/wubildr
  155.     /ubuntu/disks/root.disk
  156.     /ubuntu/disks/home.disk
  157.     /ubuntu/disks/swap.disk
  158.     /core.img   /grub/core.img     /boot/grub/core.img
  159.     /boot/map      /map
  160.     /DEFAULT.MNU /default.mnu
  161.     /IO.SYS /io.sys
  162.     /MSDOS.SYS /msdos.sys
  163.     /COMMAND.COM /command.com
  164.     "
  165. Boot_Prog_Fat="
  166.      /bootmgr
  167.     /boot/bcd
  168.     /Windows/System32/winload.exe
  169.     /grldr
  170.     /ntldr
  171.     /NTDETECT.COM
  172.     /NTBOOTDD.SYS
  173.     /wubildr.mbr
  174.     /wubildr  
  175.     /ubuntu/winboot/wubildr
  176.     /ubuntu/winboot/wubildr.mbr
  177.     /ubuntu/disks/root.disk
  178.     /ubuntu/disks/home.disk
  179.     /ubuntu/disks/swap.disk
  180.     /core.img   /grub/core.img     /boot/grub/core.img
  181.     /boot/map      /map
  182.     /DEFAULT.MNU
  183.     /IO.SYS
  184.     /MSDOS.SYS
  185.     /COMMAND.COM
  186.     "
  187.  
  188.  
  189.  
  190. ############### List of files whose contents will be displayed.
  191. Boot_Files_Normal="
  192.    /boot/grub/menu.lst /grub/menu.lst  /NST/menu.lst    /menu.lst
  193.    /grub.cfg    /grub/grub.cfg    /boot/grub/grub.cfg
  194.    /ubuntu/disks/boot/grub/menu.lst /ubuntu/disks/install/boot/grub/menu.lst /ubuntu/winboot/menu.lst
  195.    /boot/grub/grub.conf    /grub/grub.conf    /grub.conf
  196.    /boot.ini  /BOOT.INI
  197.    /etc/fstab
  198.    /etc/lilo.conf  /lilo.conf
  199.    "
  200.  
  201. Boot_Files_Fat="
  202.    /boot/grub/menu.lst /grub/menu.lst  /NST/menu.lst    /menu.lst
  203.    /grub.cfg    /grub/grub.cfg    /boot/grub/grub.cfg
  204.    /ubuntu/disks/boot/grub/menu.lst /ubuntu/disks/install/boot/grub/menu.lst /ubuntu/winboot/menu.lst
  205.    /boot/grub/grub.conf    /grub/grub.conf    /grub.conf
  206.    /boot.ini  
  207.    /etc/fstab
  208.    /etc/lilo.conf  /lilo.conf
  209.    "
  210.  
  211. ############### List of files whose end point (in GB) will be displayed.
  212. GrubError18_Files="
  213.    boot/grub/menu.lst    grub/menu.lst    menu.lst /NST/menu.lst
  214.    ubuntu/disks/boot/grub/menu.lst
  215.    boot/grub/grub.conf    grub/grub.conf    grub.conf
  216.    grub.cfg    grub/grub.cfg    boot/grub/grub.cfg
  217.    core.img    grub/core.img   boot/grub/core.img
  218.    boot/grub/stage2    grub/stage2    stage2
  219.    boot/vmlinuz*  vmlinuz*    ubuntu/disks/boot/vmlinuz*
  220.    boot/initrd*  initrd*    ubuntu/disks/boot/initrd*
  221.    boot/kernel*.img
  222.    initramfs* boot/initramfs*
  223.    "
  224.  
  225.  
  226. #######  Directory containing the script.
  227.  
  228. Dir=$(cd "$(dirname "$0")";pwd);
  229.  
  230. # Set $Dir to the home folder of the current user if the script is in one of the
  231. # system folders
  232. # This allows placement of the script in /bin, /sbin, /usr/bin, ...
  233. # while still having a normal location to write the output file.
  234. for systemdir in /bin /boot /cdrom /dev /etc /lib /lost+found /opt /proc /sbin /selinux /srv /sys /usr /var; do
  235.     if [ $(expr "$Dir" : $systemdir) -ne 0 ]; then
  236.         Dir="$HOME"
  237.         break
  238.     fi
  239. done
  240.  
  241. ########  To avoid overwriting existing files, look for a non-existing file
  242. ########  RESULT.txt RESULTS1.txt  RESULTS2.txt ...
  243.  
  244. LogFile="${Dir}/RESULTS"
  245. while ( [ -e "${LogFile}${j}.txt" ] )
  246.     do
  247.        if [ "j" = "" ]; then j=0; fi;
  248.        j=$((j+1));
  249.       wait;
  250.     done
  251. LogFile="${LogFile}${j}.txt"  #### The RESULTS file.
  252.  
  253. ######  Redirect stdout to RESULT File
  254. #exec 6>&1  
  255. #exec > "$LogFile"
  256.  
  257. ########### Create previously non-existing  folder of the form
  258. ##########  /tmp/BootInfo  /tmp/BootInfo1, /tmp/BootInfo2 ...
  259.  
  260. Folder=/tmp/BootInfo
  261. i=0;
  262. while (! mkdir ${Folder}${i} 2>/dev/null)
  263.     do  
  264.       i=$((i+1));
  265.       wait;
  266.     done
  267. Folder=${Folder}${i}
  268.  
  269. cd $Folder
  270. Log=$Folder/Log                 #File to record the summary.
  271. Log1=$Folder/Log1               #  Most of the information which is not part of
  272.                                 #the summary is recorded in this file.
  273. Error_Log=$Folder/Error_Log     #  File to catch all unusal Standar Errors
  274. Trash=$Folder/Trash             #  File to catch all usual Standard Errors
  275.                                 #     these messagges will not be included in the RESULTS      
  276. Mount_Error=$Folder/Mount_Error # File to catch Mounting Errors
  277. Unknown_MBR=$Folder/Unknown_MBR # File to record all unknown MBR and Boot sectors.
  278. Tmp_Log=$Folder/Tmp_Log         # File to temporarily hold some information.
  279. PartitionTable=$Folder/PT       # File to store the Partition   Table
  280. FakeHardDrives=$Folder/FakeHD   # File to list devices which seem to have  no corresponding drive.
  281. BLKID=$Folder/BLKID             # File to store the output of blkid
  282. exec 2>$Error_Log               #Redirect all standard error to the file Error_Log
  283.  
  284. All_Hard_Drives=$(ls /dev/hd? /dev/sd? 2>>$Trash );   ### List of all Hard drives.
  285.  
  286.  
  287. if type dmraid >>$Trash 2>>$Trash;
  288. then
  289.   InActiveDMRaid=$(dmraid -si -c);
  290.   if  [ "$InActiveDMRaid" = "no raid disks" ];
  291.   then
  292.       InActiveDMRaid="";
  293.   fi;
  294.   if  [ "$InActiveDMRaid" != "" ];
  295.   then
  296.       dmraid -ay $InActiveDMRaid >>$Trash;
  297.   fi;
  298.   if [ "$(dmraid -sa -c)" != "no raid disks" ];
  299.   then
  300.        All_DMRaid=$(dmraid -sa -c|awk '{print "/dev/mapper/"$0}');
  301.        All_Hard_Drives=${All_Hard_Drives}" "${All_DMRaid};
  302.   fi;  
  303. fi;
  304.  
  305. ####Arrays to hold information about Partitions: name, starting sector, ending sector, size in sector, Partition Type, Filesystem typ, UUID, Kind(Logical, Primary, Extended), HardDrive, boot flag,  parent (for logical partitions), label, system(the partition id according the partition table), the device associate to the partition.
  306.  
  307. declare -a NamesArray StartArray EndArray SizeArray TypeArray  FileArray UUIDArray KindArray DriveArray BootArray ParentArray LabelArray SystemArray DeviceArray  
  308.  
  309.  
  310. #####Arrays to hold information about the harddrives.
  311. declare -a HDName  FirstPartion LastPartition  HDSize HDMBR HDHead HDTrack HDCylinder HDPT HDStart HDEnd HDUUID;
  312.  
  313. ####Array for Hard drives formated as Filesystem
  314. declare -a FilesystemDrives;
  315.  
  316.  
  317. PI=-1 ## Counter for the identification number of a partition. (each partition gets unique number)
  318. HI=0 ## Counter for the identification number of a hard drive. (each hard drive gets unique number)
  319. PTFormat='%-10s %4s%14s%14s%14s %3s %s\n';  ### standard format to use for Partition table,
  320.  
  321.  
  322. ####  fdisk -s seems to malfunction sometimes. So use sfdisk -s if available
  323. function fdisks (){
  324. if type sfdisk >>$Trash 2>>$Trash
  325. then
  326.    sfdisk -s "$1" 2>>$Trash;
  327. else
  328.    fdisk -s "$1" 2>>$Trash;
  329. fi;
  330. }
  331.    
  332.  
  333.  
  334. #####  A function which checks whether a file is on a mounted partition
  335. MountPoints=$(mount | grep -e ^/dev |awk '{print $3}' |grep -v  ^/$); ##list of mountpoints for devices
  336.  
  337. function FileNotMounted (){
  338. local File=$1 curmp=$2;      
  339. for mp in $MountPoints;
  340. do
  341.  if [ $(expr match "$File" "$mp""/" ) -ne 0 ] && [ "$mp" != "$curmp" ]
  342.  then
  343.    return 1;
  344.  fi;
  345. done;
  346. return 0;
  347. }
  348.  
  349. ##### A function which converts the  two digit hexcode of a partition type
  350. # The following list is taken from sfdisk -T  and
  351. #  http://www.win.tue.nl/~aeb/partitions/partition_types-1.html
  352. #  work in progress
  353. function HexToSystem () {
  354. local type=$1 system
  355. case $type in
  356. 0) system="Empty";;
  357. 1) system="FAT12";;
  358. 2) system="XENIX root";;
  359. 3) system="XENIX usr";;
  360. 4) system="FAT16 <32M";;
  361. 5) system="Extended";;
  362. 6) system="FAT16";;
  363. 7) system="HPFS/NTFS";;
  364. 8) system="AIX";;
  365. 9) system="AIX bootable";;
  366. a) system="OS/2 Boot Manager";;
  367. b) system="W95 FAT32";;
  368. c) system="W95 FAT32 (LBA)";;
  369. e) system="W95 FAT16 (LBA)";;
  370. f) system="W95 Ext d (LBA)";;
  371. 10) system="OPUS";;
  372. 11) system="Hidden FAT12";;
  373. 12) system="Compaq diagnostics";;
  374. 14) system="Hidden FAT16 <32M";;
  375. 16) system="Hidden FAT16";;
  376. 17) system="Hidden HPFS/NTFS";;
  377. 18) system="AST SmartSleep";;
  378. 1b) system="Hidden W95 FAT32";;
  379. 1c) system="Hidden W95 FAT32 (LBA)";;
  380. 1e) system="Hidden W95 FAT16 (LBA)";;
  381. 24) system="NEC DOS";;
  382. 27) system="Hidden HPFS/NTFS";;
  383. 32) system="NOS";;
  384. 35) system="JFS on OS2";;
  385. 38) system="Theos";;
  386. 39) system="Plan 9";;
  387. 3a) system="Theos";;
  388. 3b) system="Theos Extended";;
  389. 3c) system="PartitionMagic recovery";;
  390. 40) system="Venix 80286";;
  391. 41) system="PPC PReP Boot";;
  392. 42) system="SFS";;
  393. 45) system="Boot-US boot manager";;
  394. 4d) system="QNX4.x";;
  395. 4e) system="QNX4.x 2nd part";;
  396. 4f) system="QNX4.x 3rd part";;
  397. 50) system="OnTrack DM";;
  398. 51) system="OnTrack DM6 Aux1";;
  399. 52) system="CP/M";;
  400. 53) system="OnTrack DM6 Aux3";;
  401. 54) system="OnTrackDM6";;
  402. 55) system="EZ-Drive";;
  403. 56) system="Golden Bow";;
  404. 5c) system="Priam Edisk";;
  405. 61) system="SpeedStor";;
  406. 63) system="GNU HURD or SysV";;
  407. 64) system="Novell Netware 286";;
  408. 65) system="Novell Netware 386";;
  409. 70) system="DiskSecure Multi-Boot";;
  410. 75) system="PC/IX";;
  411. 80) system="Old Minix";;
  412. 81) system="Minix / old Linux";;
  413. 82) system="Linux swap / Solaris";;
  414. 83) system="Linux";;
  415. 84) system="OS/2 hidden C: drive";;
  416. 85) system="Linux extended";;
  417. 86) system="NTFS volume set";;
  418. 87) system="NTFS volume set";;
  419. 88) system="Linux plaintext";;
  420. 8e) system="Linux LVM";;
  421. 93) system="Amoeba/Accidently Hidden Linux";;
  422. 94) system="Amoeba BBT";;
  423. 9f) system="BSD/OS";;
  424. a0) system="IBM Thinkpad hibernation";;
  425. a5) system="FreeBSD";;
  426. a6) system="OpenBSD";;
  427. a7) system="NeXTSTEP";;
  428. a8) system="Darwin UFS";;
  429. a9) system="NetBSD";;
  430. ab) system="Darwin boot";;
  431. af) system="HFS";;
  432. b0) sytem="Boot Star";;
  433. b1 | b2 | b3 | b4 | b6) system="SpeedStor";;
  434. b7) system="BSDI fs";;
  435. b8) system="BSDI swap";;
  436. bb) system="Boot Wizard hidden";;
  437. bc) system="Acronis BackUp";;
  438. be) system="Solaris boot";;
  439. bf) system="Solaris";;
  440. c0) system="CTOS";;
  441. c1) system="DRDOS/sec (FAT-12)";;
  442. c2) system="Hidden Linux/PowerBoot";;
  443. c3) system="Hidden Linux Swap /PowerBoot";;
  444. c4) system="DRDOS/sec (FAT-16 < 32M)";;
  445. c6) system="DRDOS/sec (FAT-16)";;
  446. c7) system="Syrinx";;
  447. cb) system="DR-DOS  FAT32 (CHS)";;
  448. cc) system="DR-DOS  FAT32 (LBA)";;
  449. cd) system="CTOS Memdump?";;
  450. ce) system="DR-DOS FAT16X (LBA)";;
  451. cf) system=" DR-DOS EXT DOS (LBA)";;
  452. d0) system=" REAL/32 secure big partition";;
  453. da) system="Non-FS data";;
  454. db) system="CP/M / CTOS / ...";;
  455. dd) system="Dell Media Direct";;
  456. de) system="Dell Utility";;
  457. df) system="BootIt";;
  458. e1) system="DOS access";;
  459. e3) system="DOS R/O";;
  460. e4) system="SpeedStor";;
  461. eb) system="BeOS fs";;
  462. ee) system="GPT";;
  463. ef) system="EFI (FAT-12/16/32)";;
  464. f0) system="Linux/PA-RISC boot";;
  465. f1) system="SpeedStor";;
  466. f4) system="SpeedStor";;
  467. f2) system="DOS secondary";;
  468. fb) system="VMware VMFS";;
  469. fc) system="VMware VMKCORE";;
  470. fd) system="Linux raid autodetect";;
  471. fe) system="LANstep";;
  472. ff) system="BBT";;
  473.  *) system="Unknown";;
  474. esac;
  475. echo $system;
  476. }
  477.  
  478. ##### Function to convert GPT's Partition Type.
  479. ####  ABCDEFGH-IJKL-MNOP-QRST-UVWXYZabcdef is stored as
  480. ####  GHEFCDAB-KLIJ-OPMN-QRST-UVWXYZabcdef (without the dashes)
  481. function UUIDToSystem() {
  482. local type=$1 system
  483. case $type in
  484.     00000000000000000000000000000000)  system="Empty";;
  485.     41ee4d02e733d3119d690008c781f39f)  system="MBR partition scheme";;
  486.     28732ac11ff8d211ba4b00a0c93ec93b)  system="System/Boot Partition";;
  487.     a2a0d0ebe5b9334487c068b6b72699c7)  system="Linux or Data";;
  488.     6dfd5706aba4c44384e50933c84b4f4f)  system="Linux Swap";;
  489.     16e3c9e35c0bb84d817df92df00215ae)  system="Microsoft Windows";;
  490.     79d3d6e607f5c244a23c238f2a3df928)  system="LVM";;
  491.     005346480000aa11aa1100306543ecac)  system="HFS+";;
  492.     4861682149646f6e744e656564454649)  system="Bios Boot Partition";;
  493.                                    *)  system="-";
  494.                                        echo Unknown GPT Partiton Type>>$Unknown_MBR;
  495.                                        echo  $type >>$Unknown_MBR;;  
  496. esac;
  497. echo $system;
  498.    }
  499.  
  500. ##### Function which insert a comma every  third digit of a number
  501. function InsertComma () {
  502. echo $1 |sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'
  503. }
  504.  
  505. ##### Function to read 4 bytes starting at $1 of device $2 and convert to decimal.
  506. function Read4Bytes () {
  507. echo $(hexdump -v -s  $1  -n 4 -e '4 "%u"'  $2);
  508. }
  509.  
  510. ##### Function to read 8 bytes starting at $1 of device $2 and convert to decimal.
  511. function Read8Bytes () {
  512. local start=$1 device=$2;
  513. local first4 second4;
  514. first4=$(hexdump -v -s  $start  -n 4 -e '4 "%u"'  $device);
  515. second4=$(hexdump -v -s  $((start+4))  -n 4 -e '4 "%u"'  $device);
  516. echo $((second4*1073741824+first4));
  517. }
  518.  
  519. #### Functions to pretty print blkid output ######
  520. BlkidFormat='%-16s %-38s %-10s %-30s\n'
  521. BlkidTag (){
  522. echo $(blkid -c /dev/null -s $2 -o value $1 2>>$Trash)
  523. }
  524.  
  525. PrintBlkid (){
  526. local part=$1;
  527. if  [  "$(blkid -c /dev/null $part  2>$Tmp_Log)"  != "" ];
  528. then
  529. printf "$BlkidFormat" "$part"  "$(BlkidTag $part UUID)"  "$(BlkidTag  $part TYPE)" "$(BlkidTag $part LABEL)">>$BLKID;
  530. else blkid  -p "$part"  2>&1 |grep "$part" >>$BLKID; #blkid -p is not avaible all all systems. This contructs makes sure the "usage" message is not displayed, but catches the "ambivalent" error.
  531. fi;
  532. }
  533.  
  534.  
  535. ## Reads and display the  a partition table of an extended partitons    ###########
  536. #############  and check the partition  check for errors         #####################
  537. #  This function can be applied iteratively  to read the extended partiton table          
  538. # Variable 1:  HI of hard drive
  539. # Variable 2:  Start Sector of the extended Partition,
  540. # Variable 3:  Number of partitions in table (4 for regular PT, 2 for logical
  541. # Variable 4:  File for storing the partitions table.
  542. # Variable 5:  Format to use for displaying the partition table.  
  543. # Variable 6:  PI of the primary extended partition containing the extended partition.
  544. #              ( equals ""  for hard drive)
  545. # Variable 7:  Last Linux Index assigned (the number in sdXY).
  546.  
  547. ReadPT (){
  548. local HI=$1 StartEx=$2   N=$3 PT_file=$4 format=$5  EPI=$6 Base_Sector  
  549. local   LinuxIndex=$7  boot  size   start end type drive system;
  550. local i=0  boot_hex label limit MBRSig
  551. drive=${HDName[$HI]};
  552. limit=${HDSize[$HI]};
  553. $(dd if=$drive skip=$StartEx of=$Tmp_Log count=1 2>>$Trash);
  554. MBRSig=$(hexdump -v -s 510  -n 2 -e '"%x"'  $Tmp_Log);
  555. [[ "$MBRSig" != "aa55" ]]  && echo  Invalid MBR Signature found >> $PT_file;
  556. if [[ $StartX -lt $limit ]];
  557. then  # set Base_Sector to 0 for HardDrive, and to the start
  558.       # sector  of primary extended partition otherwise
  559.     [[ "$EPI" = "" ]] && Base_Sector=0 || Base_Sector=${StartArray[$EPI]}
  560.     for (( i=0; i < N; i++ ));
  561.     do
  562.         $(dd if=$drive skip=$StartEx of=$Tmp_Log count=1 2>>$Trash);
  563.         boot_hex=$(hexdump -v -s  $((446+16*i))  -n  1 -e '"%02x"'  $Tmp_Log)
  564.         case $boot_hex  in
  565.             00) boot=" ";;
  566.             80) boot="* ";;
  567.             *) boot="?";;
  568.         esac;
  569.         start=$(hexdump -v -s  $((454+16*i))  -n 4 -e '4 "%u"'  $Tmp_Log);
  570.         size=$(hexdump -v -s  $((458+16*i))  -n 4 -e '4 "%u"'  $Tmp_Log);
  571.         type=$(hexdump -v  -s  $((450+16*i))  -n 1 -e '4 "%x"' $Tmp_Log);
  572.         if  [[ $size != 0 ]];
  573.         then
  574.             if  [[ ( "$type" = "5" || "$type" = "f" )  && $Base_Sector != 0 ]];
  575.             then
  576.                 start=$((start+Base_Sector))  #start sector of an extended partition is
  577.                 # relative to the start sector of an primary extended partition.
  578.                if [[  $i = 0 ]];
  579.                    then
  580.                       echo "Extended  partition  linking to another extended partition" >>$PT_file;
  581.                    fi;
  582.                 ReadPT $HI $start  2  $PT_file "$format"  $EPI $LinuxIndex;
  583.             else  
  584.                 ((PI++))  
  585.                 if  [[ "$type" = "5" || "$type" = "f" ]];
  586.                 then
  587.                     KindArray[$PI]="E";
  588.                 else
  589.                     start=$((start+StartEx)); #Start sector of a logical partition is
  590.             # relative to the start sector of directly assocated  extented partition.
  591.                     [[ $Base_Sector = 0 ]] && KindArray[$PI]="P" || KindArray[$PI]="L";
  592.                 fi;
  593.                 LinuxIndex=$((LinuxIndex+1));
  594.                 end=$((start+size-1));
  595.                 [[ "${HDPT[$HI]}"  = "BootIt"  ]] &&  label="${NamesArray[$EPI]}""_" || label=$drive;
  596.                 system=$(HexToSystem $type)
  597.  
  598.                 printf "$format" "$label$LinuxIndex" "$boot" $(InsertComma $start) "$(InsertComma $end)"  "$(InsertComma $size)"  "$type" "$system" >> $PT_file;
  599.                 NamesArray[$PI]="$label"$LinuxIndex;
  600.                 StartArray[$PI]=$start;
  601.                 EndArray[$PI]=$end;
  602.                 TypeArray[$PI]=$type;
  603.                 SystemArray[$PI]="$system";
  604.                 SizeArray[$PI]=$size;
  605.                 BootArray[$PI]="$boot";
  606.                 DriveArray[$PI]=$HI;
  607.                 ParentArray[$PI]=$EPI;
  608.                 ( [[ "$EPI" = "" ]] || [[ ${DeviceArray[$EPI]} != "" ]] ) && DeviceArray[$PI]=$drive$LinuxIndex;
  609.  
  610.                 if [[ "$type" = "5" || "$type" = "f" ]];
  611.                 then
  612.                       ReadPT $HI $start  2  $PT_file "$format"  $PI 4;
  613.                 fi;
  614.             fi;
  615.        
  616.         elif [[ $Base_Sector != 0  &&  $i = 0  ]];
  617.         then
  618.             echo "Empty Partition">>$PT_file;
  619.         else
  620.             LinuxIndex=$((LinuxIndex+1));
  621.         fi;
  622.     done;
  623. else
  624.     echo "EBR refers to a  location outside the Hard drive" >>$PT_file;
  625. fi;  
  626. }
  627. ############### Read partition table of type GPT (GUID, EFI)##########################
  628. ######  Variable 1:  HI of hard drive
  629. ######  Variable 2:  File to store the PartitionTable
  630. function ReadEFI() {
  631.     local HI=$1 drive file=$2 Size N=0 i=0  format Label PRStart Start End  Type Size System;
  632.     drive="${HDName[$HI]}";
  633.     format='%-10s %14s%14s%14s %s\n';
  634.     printf "$format"  Partition Start End Size  System >> $file;
  635.     HDStart[$HI]=$(Read8Bytes  552   $drive);
  636.       HDEnd[$HI]=$(Read8Bytes  560   $drive);
  637.      HDUUID[$HI]=$(hexdump -v -s 568   -n 16 -e '/1 "%02x"'  $drive);
  638.          PRStart=$(Read8Bytes  584    $drive);
  639.                N=$(Read4Bytes  592   $drive);
  640.           PRStart=$((PRStart*512));
  641.           PRSize=$(Read4Bytes 596    $drive);
  642.     for (( i = 0; i< N; i++ ))
  643.     do
  644.         Type=$(hexdump -v -s $((PRStart+PRSize*i))  -n 16 -e '/1 "%02x"'  $drive);
  645.     if [ "$Type" != "00000000000000000000000000000000" ];
  646.     then
  647.         ((PI++))
  648.         Start=$(Read8Bytes $((PRStart+32+PRSize*i))   $drive);
  649.           End=$(Read8Bytes $((PRStart+40+PRSize*i))   $drive);
  650.         Size=$((End-Start+1));
  651.         System=$(UUIDToSystem $Type);
  652.         Label=$drive$((i+1));
  653.         printf "$format"  "$Label"  "$(InsertComma $Start)" "$(InsertComma $End)" "$(InsertComma $Size)"  "$System"  >>$file;
  654.         NamesArray[$PI]=$Label;
  655.         DeviceArray[$PI]=$Label;
  656.         StartArray[$PI]=$Start;
  657.         TypeArray[$PI]=$Type;
  658.         SizeArray[$PI]=$Size;
  659.         SystemArray[$PI]=$System;
  660.         EndArray[$PI]=$End;
  661.         DriveArray[$PI]=$HI;
  662.         KindArray[$PI]="P";
  663.         ParentArray[$PI]="";
  664.      fi;        
  665.      done;
  666. }
  667.  
  668. ############### Read the Master Partition Table of  BootIt NG##########################
  669. ######  Variable 1:  HI of hard drive
  670. ######   Variable 2:  File to store the MPT.
  671. function ReadEMBR() {
  672.     local HI=$1 drive MPT_file=$2 Size N=0 i=0  BINGIndex  Label   Start End  Type BINGUnknown format Size System StoredPI FirstPI=FirstPartition[$1] LastPI=$PI New;
  673.     drive="${HDName[$HI]}";
  674.     format='%-18s %4s%14s%14s%14s %3s %-15s %3s %2s\n';
  675.     printf "$format"  Partition Boot Start End Size Id System  Ind "?">> $MPT_file;
  676.     N=$(hexdump -v -s 534  -n 1 -e  '"%u"' $drive);
  677.     while [[ $i -lt "$N" ]]
  678.         do
  679.         New=1;
  680.         BINGUnknown=$(hexdump -v -s  $((541+28*i))  -n 1 -e '"%x"'  $drive)
  681.         Start=$(hexdump -v -s  $((542+28*i))  -n 4 -e '4 "%u"'  $drive);
  682.           End=$(hexdump -v -s  $((546+28*i))  -n 4 -e '4 "%u"'  $drive);
  683.         BINGIndex=$(hexdump -v -s  $((550+28*i))  -n 1 -e '"%u"'  $drive);
  684.         Type=$(hexdump -v -s  $((551+28*i))  -n 1 -e '"%x"'  $drive);
  685.         Size=$((End-Start+1));
  686.         Label=$(hexdump -v -s  $((552+28*i))  -n 15 -e '"%_u"'  $drive| sed -e  s/nul[^$]*//);
  687.         System=$(HexToSystem $Type);
  688.         printf "$format"  "$Label" "-" "$(InsertComma $Start)" "$(InsertComma $End)" "$(InsertComma $Size)" "$Type" "$System"  "$BINGIndex" "$BINGUnknown">>$MPT_file;
  689.          StoredPI=$PI;
  690.          for ((j = FirstPI; j<=LastPI; j++ ));
  691.            do
  692.               if (( ${StartArray[$j]} == $Start ));
  693.               then
  694.                     PI=$j;
  695.                     New=0;
  696.                     break;
  697.               fi;
  698.            done;
  699.          
  700.          if (( $New  == 1 ));
  701.          then
  702.            ((PI++));
  703.            StoredPI=$PI;
  704.            StartArray[$PI]=$Start;
  705.            TypeArray[$PI]=$Type;
  706.            SizeArray[$PI]=$Size;
  707.            SystemArray[$PI]=$System;
  708.            EndArray[$PI]=$End;
  709.            DriveArray[$PI]=$HI;
  710.          fi;
  711.          NamesArray[$PI]=$Label;
  712.  
  713.          if [[ $Type = "f" || $Type = "5" ]];
  714.             then
  715.                  KindArray[$PI]="E";
  716.                  ParentArray[$PI]=$PI;
  717.                  ReadPT $HI  $Start  2  $MPT_file "$format"  $PI  4 ;  
  718.             else
  719.                 KindArray[$PI]="P";
  720.                 ParentArray[$PI]="";
  721.             fi;
  722.           PI=$StoredPI;
  723.          ((i++));
  724.         done;
  725. }
  726.  
  727. #################   Check partition table for errors  ################################
  728. ###  
  729. ###  This function checks whether any two partitions  overlap
  730. ###  and the logical partitions are inside the extended partition.
  731. ###  Variable 1:        PI of First partition to consider
  732. ###  Variable 2:        PI of Last Partition to consider
  733. ###  Variable 3:        File for the error messages.
  734. ###  Variable 4:        HI of containing hard drive
  735.  CheckPT () {
  736.     local  first=$1 last=$2 file=$3;  hi=$4;
  737.     local  Si Ei Sj Ej Ki  Kj i j k cyl track head cyl_bound sec_bound
  738.     cyl=${HDCylinder[$hi]};
  739.     track=${HDTrack[$hi]};
  740.     head=${HDHead[$hi]};
  741.     cyl_bound=$((cyl*track*head));
  742.     sec_bound=${HDSize[$hi]};
  743.     for (( i=$first; i <= last; i++ ));
  744.     do
  745.          Si=${StartArray[$i]};
  746.          Ei=${EndArray[$i]};
  747.          Ki=${KindArray[$i]};
  748.          Ni=${NamesArray[$i]};
  749.          if [[ "$Ei" -gt "$sec_bound"  ]];
  750.          then
  751.              echo $Ni  ends after the last sector of ${HDName[$hi]}>>$file;
  752.          elif  [[ "$Ei" -gt "$cyl_bound"  ]]
  753.          then
  754.              echo $Ni ends after the last cylinder of ${HDName[$hi]}>>$Trash;
  755.          fi;
  756.          if [[ $Ki = "L" ]];
  757.          then
  758.              k=${ParentArray[$i]};
  759.             Sk=${StartArray[$k]};
  760.             Ek=${EndArray[$k]};
  761.             Nk=${NamesArray[$k]};
  762.             [[ $Si -le $Sk || $Ei -gt $Ek ]] &&  echo  the logical partition  $Ni is not contained in the extended partition  $Nk>>$file;
  763.          fi;
  764.          for (( j = i+1; j <= last; j++ ));
  765.          do
  766.             Sj=${StartArray[$j]};
  767.             Ej=${EndArray[$j]};
  768.             Kj=${KindArray[$j]};
  769.             Nj=${NamesArray[$j]};
  770.             [[ !( ( $Ki = "L" && $Kj = "E"  )  || ( $Ki = "E" && $Kj = "L"  ) ) && ( ( $Si -lt $Sj &&   $Sj  -lt $Ei )  || ($Sj  -lt $Si && $Si -lt $Ej ) )]] && echo   $Ni overlaps with   $Nj >>$file;
  771.           done;
  772.     done
  773. }
  774.  
  775. #############################################################################################
  776. ##########  Determine the embeded location of stage 2  in a stage 1 file,
  777. ##########  look  for the stage 2 and, if found, determine the
  778. #########$  the location and the path of the embedded menu.lst
  779.  
  780. stage2_loc (){
  781.   local stage1=$1 hi;
  782.   offset=$(hexdump -v -s 68 -n 4 -e '4 "%u"' $stage1 2>>$Trash);
  783.   dr=$(hexdump -v -s 64 -n 1 -e '"%d"' $stage1);
  784.   pa="T"
  785.   Grub_Version="";
  786.   for hi in ${!HDName[@]};
  787.   do
  788.      hdd=${HDName[$hi]};
  789.      if [ $offset -lt  ${HDSize[hi]}  ];
  790.      then
  791.          tmp=$(dd if=$hdd skip=$offset count=1 2>>$Trash | hexdump -v    -n 4 -e '"%x"');
  792.          if [[ "$tmp" = 3be5652 || "$tmp" =  bf5e5652  ]];  ###  If stage2 files was found.
  793.          then
  794.               dd if=$hdd skip=$((offset+1)) count=1 of=$Tmp_Log 2>>$Trash;
  795.               pa=$(hexdump -v  -s 10  -n 1 -e '"%d"' $Tmp_Log);
  796.               stage2_hdd=$hdd;
  797.               Grub_String=$(hexdump -v -s 18 -n 94 -e '"%_u"' $Tmp_Log);
  798.               Grub_Version=$(echo $Grub_String|sed -e  s/nul[^$]*//);
  799.               BL=$BL$Grub_Version;
  800.               menu=$(echo $Grub_String |sed -e  s/[^\/]*// -e s/nul[^$]*//);
  801.               menu=${menu%% *};
  802.          fi;
  803.      fi;
  804.  done;
  805.  dr=$((dr-127))
  806.  Stage2_Msg=$(echo  looks at sector $offset )        
  807.  if [ "$dr" = 128 ];
  808.  then
  809.       Stage2_Msg=$(echo $Stage2_Msg of the same hard drive)
  810.  else
  811.       Stage2_Msg=$(echo $Stage2_Msg on boot drive \#$dr)
  812.  fi;
  813.  Stage2_Msg=$(echo $Stage2_Msg for the stage2 file);
  814.                    
  815.  if [ "$pa" = "T"  ]   #### no stage 2 file found.
  816.  then
  817.       Stage2_Msg=$(echo $Stage2_Msg, but no stage2 files can be found at this location.);
  818.  else
  819.      pa=$((pa+1))
  820.      Stage2_Msg=$(echo $Stage2_Msg.  A stage2 file is at  this location on $stage2_hdd.  Stage2 looks on )                      
  821.      if [ "$pa" = 256 ];
  822.      then
  823.          Stage2_Msg=$(echo $Stage2_Msg the same partition)
  824.      else
  825.          Stage2_Msg=$(echo $Stage2_Msg  partition \#$pa )
  826.      fi;
  827.      Stage2_Msg=$(echo $Stage2_Msg for  $menu.)
  828.   fi;
  829. }
  830. #######################################################################################
  831.  
  832. #############################################################################################
  833. ##########  Determine the embeded location of core.img  for a Grub2 boot.img file,
  834. ##########  look  for the core.img and,  the path of the Grub Folder.
  835. #############################################################################
  836.  
  837. core_loc (){
  838.   local stage1=$1  grub2_version=$2  hi offset_loc dr_loc dir_loc;
  839.   case $grub2_version in
  840.   1.96) offset_loc=68;  dr_loc=76; dir_loc=32;;
  841.   1.97) offset_loc=92;  dr_loc=91; dir_loc=28;;
  842.   esac;
  843.   offset=$(hexdump -v -s $offset_loc -n 4 -e '4 "%u"' "$stage1" 2>>$Trash);
  844.   dr=$(hexdump -v -s $dr_loc -n 1 -e '"%d"' "$stage1");
  845.   pa="T"
  846.     for hi in ${!HDName[@]};
  847.   do
  848.      hdd=${HDName[$hi]};
  849.      if [ $offset -lt  ${HDSize[hi]}  ];
  850.      then
  851.          tmp=$(dd if="$hdd" skip=$offset count=1 2>>$Trash | hexdump -v    -n 4 -e '"%x"');
  852.          if [ "$tmp" = 1bbe5652 ];  ###  If conf.img  file was found.
  853.          then
  854.               dd if=$hdd skip=$((offset+1)) count=1 of=$Tmp_Log 2>>$Trash;
  855.               pa=$(hexdump -v  -s 20  -n 1 -e '"%d"' $Tmp_Log);
  856.               core_hdd=$hdd;
  857.               Grub_String=$(hexdump -v -s $dir_loc -n 64 -e '"%_u"' $Tmp_Log);
  858.               Core_Dir=$(echo  $Grub_String | sed s/nul[^$]*//);
  859.          fi;
  860.      fi;
  861.  done;
  862.  Core_Msg=$(echo  looks at sector $offset of the same hard drive for core.img)
  863.  
  864.  if [ "$pa" = "T"  ]  
  865.  then  #### core.img not  found.
  866.      Core_Msg=$(echo $Core_Msg, but core.img can not be found at this location.);
  867.  else  #### core.img  found.            
  868.      pa=$((pa+1))
  869.      Core_Msg=$(echo $Core_Msg,  core.img is  at this location on $core_hdd and looks  )                      
  870.      if [ "$pa" = 255 ];
  871.      then
  872.          Core_Msg=$(echo $Core_Msg for $Core_Dir.)
  873.      else
  874.          Core_Msg=$(echo $Core_Msg on  partition \#$pa  for  $Core_Dir.)
  875.      fi;
  876.  
  877.   fi;
  878. }
  879. #######################################################################################
  880.  
  881. ###############  Get_Partition_Info search a partition for information relevant for booting.
  882. ####Variables:
  883. ####  log         $1  local version of RESULT.txt####  log1        $2  local version of log1
  884. ####  part        $3  device for the partition
  885. ####  name        $4  descriptive name for the partition
  886. ####  mountname   $5  path where  partition will be mounted.
  887. ###   kind        $6  kind of the partition
  888. ###   start       $7  starting sector of the partition
  889. ###   end         $8  ending sector of the partition
  890. ###   system      $9  system of the partition
  891. ###   pi          $10  pi of the partition, (equal to "" if not a regular partition.
  892. Get_Partition_Info(){
  893. local Log="$1" Log1="$2" part="$3" name="$4" mountname="$5"  kind="$6"  start="$7"  end="$8" system="$9" pi="${10}";
  894. local size=$((end-start)) BST=""  BSI=""  BFI=""  OS="" BootFiles="";
  895.  
  896.  
  897.        echo "Searching $name for information... ";
  898.        PrintBlkid $part;
  899.        type=$(BlkidTag $part TYPE);  ##### type of file system according to blkid
  900.  
  901.        [[ "$system" == "Bios Boot Partition" ]] && type="Bios Boot Partition"
  902.        [[ $pi != "" ]] && FileArray[$pi]=$type;
  903.       echo "$name: _________________________________________________________________________" >>"$Log"; echo>> "$Log"
  904.       mkdir -p "$mountname"    ####  Directory where the partition will be mounted.
  905.       if [[ "$kind" = "E"  &&  "$type" = "" ]] ;  #### Check for extended partion.
  906.          then
  907.          type="Extended Partition";
  908.          cat $Tmp_Log>>$Trash;  ### Don't display  the error message from blkid for extended partition
  909.          else
  910.          cat $Tmp_Log>>$Error_Log
  911.       fi;
  912.       echo "    File system:       "$type>>"$Log";  ### Display the File System Type
  913.  
  914.      
  915.           Bytes8081=$(hexdump -v -s 128 -n  2 -e '/1 "%x"'  $part)   #### Use bytes 0x80,81 to idendtify Boot sectors
  916.           case    $Bytes8081    in
  917.              10f) BST="HP Recovery";;
  918.              19d)  BST="BSD4.4: Fat32";;
  919.              211) BST="Dell Utility: Fat16";;
  920.              734)  BST=Dos_1.0;;
  921.              745)  BST="Vista:  Fat 32";;
  922.              89e)  BST="MSDOS5.0: Fat 16";;
  923.              8cd) BST="Windows XP";;
  924.              488) BST="Grub 2's core.img";;
  925.              b60) BST="Dell Utility: Fat16";;
  926.              bd0) BST="MSWIN4.1: Fat 32";;
  927.              e00) BST="Dell Utility: Fat16";;
  928.             2d5e) BST=Dos_1.1;;
  929.             3a5e) BST="Recovery:Fat 32";;
  930.             4445) BST="DEll Restore: Fat32";;
  931.             55aa) BST="Windows Vista/7";;
  932.             55cd) BST="Fat32";;
  933.             6616) BST=Fat16;;
  934.             696e) BST=Fat16;;
  935.             6974) BST="BootIt: Fat16";;
  936.             6f65) BST="BootIt: Fat16";;
  937.             6f74) BST=Fat32;;
  938.             6f6e) BST="-";;  #MSWIN4.1: Fat 32"
  939.             7815) BST=Fat32;;
  940.             7cc6) BST="MSWIN4.1: Fat 32";;
  941.           # 7cc6) BST=Win_98;;
  942.             8a56) BST="Acronis SZ: Fat32";;
  943.             8ec0) BST="Windows XP";;
  944.             8ed0) BST="DEll Recovery: Fat32";;
  945.             b6d1) BST="Windows XP: Fat32";;
  946.             e2f7) BST="Fat32, Non Bootable";;
  947.             e9d8) BST="Windows Vista/7";;
  948.             fa33) BST="Windows XP";;
  949.                ####### if Grub, Grub 2 or Lilo  is  in the boot sector,  ########
  950.                ####### investigate the embedded information              ########
  951.             48b4) BST="Grub 1.96";    
  952.                   core_loc $part 1.96;
  953.                   BSI=$(echo $BSI Grub 1.96 is installed in the boot sector of $name  and $Core_Msg);;
  954.             7c3c) BST="Grub 2";    
  955.                   core_loc $part 1.97;
  956.                   BSI=$(echo $BSI Grub 2 is installed in the boot sector of $name  and $Core_Msg);;
  957.      aa75 | 5272) BST=Grub;
  958.                   stage2_loc $part;
  959.                   BSI=$(echo $BSI Grub $Grub_Version is installed in the boot sector of $name  and $Stage2_Msg);;
  960.      #############  If Lilo look for map file  ##############################################
  961.             8053) BST=LILO;
  962.                    offset=$(hexdump -v -s 32 -n 4 -e '"%u"' $part);  ### 0x20-23 contains the offset
  963.                                                                     #####  of  /boot/map        
  964.                    BSI=$(echo $BSI" "LILO  is installed in boot sector of $part and looks at sector $offset of $drive for the \"map\"  file,);
  965.                    if [ $offset -lt  $size ];   ### check whether offset
  966.                                                                     #### is on the had drive.
  967.                    then
  968.                          tmp=$(dd if=$drive skip=$offset count=1 2>>$Trash | hexdump -v -s 508  -n 4 -e '"%_p"');                    
  969.                          if [[ "$tmp" = "LILO" ]];
  970.                          then
  971.                              BSI=$(echo $BSI" "and the \"map\" file was found at this location.);
  972.                          else
  973.                              BSI=$(echo $BSI" "but the \"map\" file was not found at this location.);
  974.                          fi;
  975.                     else
  976.                         BSI=$(echo $BSI" "but the \"map\" file was not found at this location.);
  977.                     fi;;
  978.      #########################################################################################
  979.               00)   sig2=$(hexdump -v -s 128 -n  2 -e '/1 "%x"'  $part)
  980.                       if [ "$sig2" = 00 ];    #### If the first two bytes are zero, the boot sector does not contain any boot loader.
  981.                       then
  982.                       BST="-";
  983.                       else   ###### Otherwise, display the boot sector, so we that we might identify it and add it to the list of known boot sectors.
  984.                       BST="Unknown"
  985.                       echo "Unknown BootLoader  on $name" >> $Unknown_MBR;
  986.                       echo >> $Unknown_MBR;
  987.                       hexdump  -n 512 -C $part >> $Unknown_MBR;
  988.                       echo >> $Unknown_MBR;
  989.                   fi;;
  990.                 *) BST="Unknown"
  991.                    echo "Unknown BootLoader  on $name" >> $Unknown_MBR;
  992.                    echo >> $Unknown_MBR;
  993.                    hexdump -n 512 -C $part >> $Unknown_MBR;
  994.                    echo >> $Unknown_MBR;
  995.             esac;
  996. ######################   Display the boot sector type.
  997.            echo "    Boot sector type:  "$BST>>"$Log"
  998.  
  999. ####################### Investigate the Boot Parameter Block of an NTFS partition.
  1000.  
  1001.            if [[ "$type" = "ntfs" ]]
  1002.            then
  1003.            offset=$(hexdump -v -s 28 -n 4 -e '"%u"' $part);
  1004.            BPB_Part_Size=$(hexdump -v -s 40 -n 4 -e '"%u"' $part)
  1005.            Comp_Size=$(( (BPB_Part_Size - size)/256 ))
  1006.            SectorsPerCluster=$(hexdump -v -s 13 -n 1 -e '"%d"' $part);
  1007.            MFT_Cluster=$(hexdump -v -s 48 -n 4 -e '"%d"' $part);
  1008.            MFT_Sector=$(( MFT_Cluster * SectorsPerCluster ));
  1009.          #  Track=$(hexdump -v -s 24 -n 2 -e '"%u"' $part)''  ### Number of sectors per track.
  1010.          #  Heads=$(hexdump -v -s 26 -n 2 -e '"%u"' $part)''  ### Number of heads
  1011.          #  if [[ "$Heads" != 255  || "$Track" != 63 ]]
  1012.          #  then
  1013.          #     BSI=$(echo $BSI" "Geometry: $Heads Heads and $Track sectors per Track.)
  1014.          #  fi;          
  1015.            if [[ "$MFT_Sector" -lt "$size" ]];
  1016.            then
  1017.                MFT_FILE=$(dd if=$part skip=$MFT_Sector count=1 2>>$Trash | hexdump -v    -n 4 -e '"%_u"');              
  1018.            else
  1019.                MFT_FILE="";
  1020.            fi;
  1021.            MFT_Mirr_Cluster=$(hexdump -v -s 56 -n 4 -e '"%d"' $part);
  1022.            MFT_Mirr_Sector=$(( MFT_Mirr_Cluster * SectorsPerCluster ));
  1023.            if [[ "$MFT_Mirr_Sector" -lt "$size" ]];
  1024.            then
  1025.                 MFT_Mirr_FILE=$(dd if=$part skip=$MFT_Mirr_Sector count=1 2>>$Trash | hexdump -v    -n 4 -e '"%_u"');
  1026.  
  1027.            else
  1028.                MFT_Mirr_FILE="";
  1029.            fi;
  1030.            if [[ "$offset" = "$start"  && "$MFT_FILE" = "FILE"  && "$MFT_Mirr_FILE" = "FILE"  && "$Comp_Size" = "0"  ]];
  1031.             then
  1032.                BSI=$(echo $BSI" "No errors found in the  Boot Parameter Block.);
  1033.            else
  1034.             if [[ "$offset" != "$start" ]]
  1035.             then
  1036.                 BSI=$(echo $BSI"  "According to the info in the boot sector, $name starts at sector $offset.)
  1037.                 if [[ "$offset" != "63" && "$offset" != "2048"  && "offset" != "0" ||  "$kind" != "L" ]]
  1038.                 then
  1039.                     BSI=$(echo $BSI" "But according to the info  from fdisk, $name starts at sector   $start.);
  1040.                  fi;
  1041.             fi;
  1042.             if  [[ "$MFT_FILE" != "FILE"  ]];
  1043.             then
  1044.                 BSI=$(echo $BSI" "The info in boot sector  on  the starting sector of the MFT is wrong.);
  1045.                 echo MFT Sector of $name >> $Unknown_MBR;
  1046.                 echo >> $Unknown_MBR
  1047.                 dd if=$part skip=$MFT_Sector count=1 2>>$Trash| hexdump -C >>$Unknown_MBR;
  1048.              fi;
  1049.              if [[ "$MFT_Mirr_FILE" != "FILE" ]];
  1050.              then
  1051.                  BSI=$(echo $BSI" "The info in the boot sector on  the starting sector of the MFT Mirror  is wrong.);
  1052.              fi;
  1053.  
  1054.              if  [[ "$Comp_Size" != "0"  ]];
  1055.              then  
  1056.                    BSI=$(echo $BSI"  "According to the info in the boot sector, $name has    $BPB_Part_Size sectors, but according to the info  from fdisk, it has  $size sectors.);
  1057.              fi;
  1058.            fi;
  1059.           fi;
  1060.  
  1061. ######################## Investigate the Boot Parameter Block (BPB)of some Fat partitions
  1062.  #####  Identifies Fat Bootsectors which are used for booting.
  1063.  
  1064. ##  if [[ "$Bytes8081" = "7cc6" ||  "$Bytes8081" = "7815"  ||  "$Bytes8081" = "B6D1"  || "$Bytes8081" =  "7405" || "$Bytes8081" = "6974" || "$Bytes8081" = "bd0" ||  "$Bytes8081" =  "89e"  ]] ;
  1065.  
  1066.         if [[ "$type" = "vfat" ]];
  1067.            then
  1068.            offset=$(hexdump -v -s 28 -n 4 -e '"%d\n"' $part); #### Starting sector the partition  according to BPP
  1069.            BPB_Part_Size=$(hexdump -v -s 32 -n 4 -e '"%d"' $part); ### Partition Size in sectors accoring to BPB
  1070.            Comp_Size=$(( (BPB_Part_Size - size)/256 )) ### This number will be unequal to zero  if the two partions size  differ by more than 255 sectors.  
  1071.            #Track=$(hexdump -v -s 24 -n 2 -e '"%u"' $part)''  ### Number of sectors per track.
  1072.            #Heads=$(hexdump -v -s 26 -n 2 -e '"%u"' $part)''  ### Number of heads
  1073.            #if [[ "$Heads" != 255  || "$Track" != 63 ]] ###  Checks for an usual geometry.
  1074.            #then
  1075.            #   BSI=$(echo $BSI" "Geometry: $Heads Heads and $Track sectors per Track.)  ### Report unusal geometry
  1076.            #fi;    
  1077.            if [[ "$offset" = "$start" && "$Comp_Size" = "0"  ]];  ### Check whether Partitons starting sector  and  the Partition Size of BPB and fdisk agree.
  1078.             then
  1079.                BSI=$(echo $BSI" "No errors found in the  Boot Parameter Block.);  ##If they agreee
  1080.             else      ######   if they  don't agree
  1081.             if [[ "$offset" != "$start" ]]   ###  if partition starting sector disagree
  1082.             then
  1083.                 BSI=$(echo $BSI"  "According to the info in the boot sector, $name starts at sector $offset.)   ### display the starting sector accoding to BPB
  1084.                 if [[ "$offset" != "63" && "$offset" != "2048" ||  "$kind" != "L" ]]  ### check whether partition is logcial partition and starting sector is a 63.
  1085.                 then  ### if not, display starting sector according to fdisk.
  1086.                     BSI=$(echo $BSI" "But according to the info  from fdisk, $name starts at sector   $start.);
  1087.                 fi; ### If not, don't display.  (This is quite common occurence, and only matters if one tries to boot Windows from a logical partition. So I decided not to display a warning message in this case.
  1088.             fi;  
  1089. #### If Partition sizes from BPB and FDISK differ by more than 255 sector, display both sizes.      
  1090.             if [[ "$Comp_Size" != "0"  ]];
  1091.             then    
  1092.                 BSI=$(echo $BSI"  "According to the info in the boot sector, $name has    $BPB_Part_Size sectors.)
  1093.                 if [[ "$BPB_Part_Size" != 0 ]];
  1094.                 then
  1095.                 BSI=$(echo "$BSI"." " But according to the info  from the partition table , it has  $size sectors.);
  1096.                 fi;  ## Don't display warning message in the common case BPB_Part_Size=0.
  1097.             fi;
  1098.              
  1099.             fi;   #### End of BPB Error if then else
  1100.           fi;   ###### End of Investigation of the BPB of vfat partitions.
  1101. ################################################################################################
  1102.       #####  Display boot sector info
  1103.       echo -n "    Boot sector info:  ">>"$Log"
  1104.       echo $BSI | fold -s -w 55 |  sed -e '2~1s/.*/                       &/'>>"$Log"
  1105.  
  1106.       ####Exclude Partitions which contain no information,     #########
  1107.       ##### or which we (currently) don't know how to  accces. #########  
  1108.       if [ "$type" != "swap" ]  && [ "$type" != "Extended Partition"  ] && [ "$type" != "unknown volume type" ] && [ "$type" != "LVM2_member" ]  && [ "$type" != "linux_raid_member" ] && [ "$type" != "crypto_Luks" ] && [ "$system" != "Bios Boot Partition" ] ;
  1109.       then    
  1110.  
  1111.          CheckMount=$(mount| grep "$part " |sed '2,$ d');
  1112.          CheckMount=${CheckMount% type*};
  1113.          CheckMount=${CheckMount#* on };  
  1114.           ### Check whether partition is already mounted
  1115.          if  [ "$CheckMount" != "" ] ;
  1116.          then
  1117.              if  [ "$CheckMount" = "/" ];
  1118.              then mountname="";
  1119.              else
  1120.                 mountname=$CheckMount;  #### if yes,use existing mount point.
  1121.              fi;
  1122.          fi;
  1123.          if  [ "$CheckMount" != "" ] || mount -r  -t "$type" $part "$mountname" 2>>$Mount_Error  || ( [ "$type" = ntfs ] &&  ntfs-3g -o ro  $part "$mountname" 2>>$Mount_Error )   ;     ####### Try to mount partition
  1124.          then     ############  if partition is  mounted.
  1125.          #####Try to identify the Operating  System (OS) by  looking for files specific to the OS
  1126.        OS=""
  1127.  
  1128.         grep -q "W.i.n.d.o.w.s. .V.i.s.t.a"  "$mountname"/{windows,Windows,WINDOWS}/{System32,system32}/{Winload,winload}.exe 2>>$Trash && OS="Windows Vista";
  1129.  
  1130.        grep -q "W.i.n.d.o.w.s. .7" "$mountname"/{windows,Windows,WINDOWS}/{System32,system32}/{Winload,winload}.exe 2>>$Trash && OS="Windows 7";
  1131.        for  WinOS in  "MS-DOS"  "MS-DOS 6.22" "MS-DOS 6.21" "MS-DOS 6.0" "MS-DOS 5.0" "MS-DOS 4.01" "MS-DOS 3.3" "Windows 98" "Windows 95"; do grep -q "$WinOS" "$mountname"/{IO.SYS,io.sys} 2>>$Trash && OS="$WinOS"; done;
  1132.        
  1133.  
  1134.        [ -s "$mountname/Windows/System32/config/SecEvent.Evt" ] ||  [ -s "$mountname/WINDOWS/system32/config/SecEvent.Evt" ] || [ -s "$mountname/WINDOWS/system32/config/secevent.evt" ] || [ -s "$mountname/windows/system32/config/secevent.evt" ] && OS="Windows XP";
  1135.  
  1136.        [ -s "$mountname/etc/issue" ] && OS=$(sed -e 's/\\. //g' -e 's/\\.//g' -e 's/^[ \t]*//' "$mountname"/etc/issue);
  1137.  
  1138.         [ -s "$mountname/etc/slackware-version" ] && OS=$(sed -e 's/\\. //g' -e 's/\\.//g' -e 's/^[ \t]*//' "$mountname"/etc/slackware-version);
  1139.  
  1140.  
  1141. ####################################  search for  the files in $Bootfiles   ########################
  1142. #################################### and if found, display there contained ########################
  1143.        BootFiles=""
  1144.        if [ "$type" = "vfat" ];
  1145.        then
  1146.            Boot_Files=$Boot_Files_Fat;
  1147.        else
  1148.            Boot_Files=$Boot_Files_Normal;  
  1149.        fi;
  1150.        
  1151.        for file in $Boot_Files;
  1152.        do
  1153.            if [ -f "$mountname"$file ] && [ -s "$mountname"$file ] && FileNotMounted "$mountname"$file "$mountname"
  1154.            then
  1155.                BootFiles=$(echo $BootFiles"  "$file);
  1156.               if ! [ -h "$mountname"$file ];  ### check whether file is  symlink
  1157.               then                            ### if not a symlink, display content.
  1158.                  titlebar_gen "$name" $file; ##generates a titlebar above each file/dir listed      
  1159.                  cat "$mountname"$file  >> "$Log1";
  1160.               fi;
  1161.            fi;
  1162.        done;
  1163. ################# Search for Wubi partitions  ###################################
  1164. if [ -f "$mountname""/ubuntu/disks/root.disk" ];
  1165.       then          
  1166.           Wubi=$(losetup -a|awk '$3 ~ "(/host/ubuntu/disks/root.disk)"{print $1; exit}'|sed s/.$//)
  1167.                     #check whether Wubi already has a loop device.
  1168.           if [[ "$Wubi" = "" ]];
  1169.           then
  1170.               Wubi=$(losetup -f --show  "$mountname""/ubuntu/disks/root.disk" );
  1171.               WubiDev=0;
  1172.           else
  1173.               WubiDev=1;
  1174.           fi;
  1175.           if [ "$Wubi" != "" ];
  1176.           then
  1177.               Get_Partition_Info "$Log"x "$Log1"x "$Wubi" "$name""/Wubi" "Wubi/""$mountname" "Wubi" 0 0 "Wubi" "";
  1178.           [[ $WubiDev = 0 ]] && losetup -d "$Wubi";  #delete Wubu loop device, if created by BIS
  1179.           else
  1180.              echo "Found Wubi on $name. But could not create a loop device">>$Error_Log;
  1181.           fi;      
  1182.         fi;            
  1183.                    
  1184.                      
  1185.              
  1186. #################################### Search for the programs in $Boot_Prog, ###############
  1187. ################################### if found displays their names.           ###############
  1188.         if [ "$type" = "vfat" ];
  1189.        then
  1190.            Boot_Prog=$Boot_Prog_Fat;
  1191.        else
  1192.            Boot_Prog=$Boot_Prog_Normal;  
  1193.        fi;
  1194.  
  1195.        for file in $Boot_Prog;  
  1196.        do
  1197.            if [ -f "$mountname"$file ] && [ -s "$mountname"$file ]  && FileNotMounted "$mountname"$file "$mountname";
  1198.               then
  1199.               BootFiles=$(echo $BootFiles"  "$file);          
  1200.            fi;
  1201.        done;
  1202.  
  1203.  
  1204. ################### Search for the directories related to Booting ########################
  1205. ##################, if found display the list of files             #######################
  1206.  
  1207. #       for file in $Boot_Dir;  #directories in that directory.
  1208. #       do
  1209. #          if [ -d "$mountname"$file ];
  1210. #          then
  1211. #             BootFiles=$(echo $BootFiles"  "$file);
  1212. #              titlebar_gen "$name" $file       ##generates a titlebar above each file/dir listed
  1213. #              ls -la  "$mountname"$file >> "$Log1" ;
  1214. #            
  1215. #         fi;
  1216. #       done;
  1217.  
  1218. ####################  Search for files containing boot codes #################################
  1219.  
  1220.        for file in $Boot_Codes_Dir    #####  loop through all directories which might contain boot_code files
  1221.        do
  1222.            if [ -d "$mountname"$file ] && FileNotMounted "$mountname"$file "$mountname";   ##### if such directory exist
  1223.            then  
  1224.                for loader in $( ls  "$mountname"$file );  ##### look at the content of that directory
  1225.                do
  1226.                   if [ -f "$mountname$file$loader" ] && [ -s "$mountname$file$loader" ];  ####  it its a file
  1227.                   then               
  1228.                       sig=$(hexdump -v -s 257 -n 8  -e '8/1 "%_p"' "$mountname"$file$loader);
  1229.                       if [ "$sig"  = "BootPart" ]    ##### Bootpart code has "BootPart" written at0x101
  1230.                       then
  1231.                           offset=$(hexdump -v -s 241 -n 4 -e '"%d"' "$mountname"$file$loader);
  1232.                               dr=$(hexdump -v -s 111 -n 1 -e '"%d"' "$mountname"$file$loader);
  1233.                               dr=$((dr -127))
  1234.                           BFI=$(echo $BFI "  "BootPart in the file $file$loader is trying to chain load sector \#$offset on boot drive \#$dr);
  1235.                       fi;
  1236.                       sig=$(hexdump -v -s 383 -n 4  -e '4/1 "%_p"' "$mountname"$file$loader);
  1237.                       if [ "$sig"  = "GRUB" ];   ##### Grub and Grub1.96  have "Grub" written at 0x17f
  1238.                       then
  1239.                           sig2=$(hexdump -v -n  2 -e '/1 "%x"' "$mountname"$file$loader);
  1240.                           if [[ "$sig2" = "eb48" ]] ### distinguish Grub and Grub 2 by the
  1241.                                                     ##### first two bytes.
  1242.                           then
  1243.                                stage2_loc  "$mountname"$file$loader;
  1244.                                BFI=$(echo $BFI" "Grub $Grub_Version in the file  $file$loader $Stage2_Msg);
  1245.                           else
  1246.                                core_loc  "$mountname"$file$loader 1.96;
  1247.                                BFI=$(echo $BFI" "Grub 1.96  in the file  $file$loader $Core_Msg);
  1248.                           fi;    
  1249.                       fi;
  1250.                       sig=$(hexdump -v -s 392 -n 4  -e '4/1 "%_p"' "$mountname"$file$loader);#### Grub1.97 has "Grub" writtem at 0x188
  1251.                       if [ "$sig"  = "GRUB" ];   ##### Grub 2  have "Grub" written at 0x188
  1252.                       then  
  1253.                           core_loc  "$mountname"$file$loader 1.97;
  1254.                           BFI=$(echo $BFI" "Grub 2  in the file  $file$loader $Core_Msg);
  1255.                       fi;
  1256.                      
  1257.                   fi;
  1258.                 done; ## End of loop through the files in a particular  Boot_Code_Directory
  1259.             fi;
  1260.         done   ## End of the loop through the Boot_Code_Directories.
  1261.  
  1262. ######### Determine the end point of all files in the GrubError18_Files list
  1263.    
  1264.      echo >$Tmp_Log;
  1265.      counter=0;
  1266.      cd "$mountname"/;
  1267.      for file in $(ls $GrubError18_Files 2>>$Trash);
  1268.      do
  1269.      if [[ -f $file ]] && [[ -s $file ]] && FileNotMounted "$mountname""/"$file "$mountname"
  1270.      then
  1271.          EndGB="??";
  1272.          BlockSize=$(filefrag -v $file| grep "Blocksize" |awk '{print $6}');
  1273.          if [ "$BlockSize" != "" ];
  1274.          then
  1275.              LastBlock=$(filefrag -v "$file"| grep "Last block"  |awk '{print $3}');
  1276.              if [ "$LastBlock" != "" ];
  1277.              then
  1278.                       EndGB=$(echo $(((BlockSize*LastBlock + 512*start)/100000000 ))|sed 's/\(.\)$/\.\1/')
  1279.              fi;  
  1280.          fi;
  1281.          BlockSize=$(filefrag -v "$file"| grep "blocksize" |awk '{print $NF}'| sed 's/)//');
  1282.          if [ "$BlockSize" != "" ];
  1283.          then
  1284.              LastBlock=$(filefrag -v "$file" | grep 'eof'  |awk '{print $3}');
  1285.              if [ "$LastBlock" != "" ];
  1286.              then
  1287.                 EndGB=$(echo $(((BlockSize*LastBlock + 512*start)/100000000 ))|sed 's/\(.\)$/\.\1/')
  1288.              fi;  
  1289.          fi;
  1290.          printf "%6sGB: %-s\n" $EndGB "$file" >>$Tmp_Log;
  1291.          ((counter++));
  1292.      fi;
  1293.      done;
  1294.      cd $Folder;
  1295.      if [ $counter != 0 ];
  1296.      then
  1297.           titlebar_gen "$name"  ": Location of files loaded by Grub";
  1298.           cat $Tmp_Log>>"$Log1";
  1299.      fi;
  1300.      echo >$Tmp_Log;
  1301.  
  1302.       if [[ $BFI != "" ]];
  1303.       then
  1304.           echo -n "    Boot file info:     ">>"$Log"
  1305.           echo $BFI | fold -s -w 55 |  sed -e '2~1s/.*/                       &/'>>"$Log"
  1306.       fi;
  1307.       echo "    Operating System:  "$OS | fold -s -w 55 | sed -e '2~1s/.*/                       &/'>>"$Log"    
  1308.       echo -n "    Boot files/dirs:   ">>"$Log"
  1309.       echo $BootFiles | fold -s -w 55 |  sed -e '2~1s/.*/                       &/'>>"$Log"
  1310.      
  1311.         if [ "$CheckMount" = "" ];  ## if partition was mounted by the script
  1312.         then
  1313.             umount "$mountname" || umount -l "$mountname";          
  1314.         fi;
  1315.      else     ############### if partition failed to mount  
  1316.        echo "    Mounting failed:">>"$Log";  
  1317.        cat $Mount_Error>>"$Log";
  1318.      fi;  ### end of Mounting "if then else"
  1319.      fi;  ### end of Partition Type "if then else"
  1320.      echo>>"$Log";
  1321.      if [[ -e "$Log"x ]];
  1322.      then cat "$Log"x>>"$Log";
  1323.           rm "$Log"x;
  1324.      fi;
  1325.      if [[ -e "$Log1"x ]];
  1326.      then cat "$Log1"x>>"$Log1";
  1327.           rm "$Log1"x;
  1328.      fi;
  1329.  
  1330.       }  ## end Get_Partition_Info function
  1331.  
  1332.  
  1333.  
  1334. ## "titlebar_gen" generates the $name$file title bar to always be either 79 or 80 chars total in length:
  1335. titlebar_gen () {
  1336.                 name_file="$1$2:"; name_file_length=${#name_file}
  1337.                 equal_signs_line_length=$(((80-name_file_length)/2-1)); equal_signs_line=""
  1338.                 for length in $(seq $equal_signs_line_length); do
  1339.                         equal_signs_line='='$equal_signs_line
  1340.                 done;
  1341.                 echo >> "$Log1";
  1342.                 echo "$equal_signs_line $name_file $equal_signs_line" >> "$Log1";
  1343.                 echo >> "$Log1";
  1344.                 }
  1345.  
  1346.  
  1347. echo "                    Boot Info Script $VERSION of  $DATE                         ">>"Log";
  1348. echo>>"Log";
  1349. echo '============================= Boot Info Summary: =============================='>>"$Log";
  1350. echo>>"$Log";
  1351.  
  1352. #####   Search  for  hard drives which don't exist,have a  corrupted partition table
  1353. #####  or  don't have a parition table(whole drive is a file system)
  1354. #####  Information on all  hard drives which a valid partition table are stored in the
  1355. #####  Hard drives arrays: HD?????
  1356. FSD=0;  #id for Filesystem Drives
  1357. for drive in  $All_Hard_Drives;
  1358. do
  1359.      size=$(fdisks $drive);        
  1360.      if [ 0 -lt $size 2>>$Trash ];
  1361.      then
  1362.           if  [ "$(blkid  $drive)" = "" ] || [ "$(blkid  | grep $drive:)" = "" ]; #Check whether drive is a filesystem
  1363.           then  #if drive is  not a filesytem
  1364.              size=$((2*size));
  1365.  # (not used) Hard_Drives=$Hard_Drives" "$drive;
  1366.             HDName[$HI]=$drive;
  1367.             HDSize[$HI]=$size;
  1368.             geometry=$(fdisk  -lu $drive 2>>$Trash | grep "head");
  1369.             HDHead[$HI]=$(echo $geometry | awk '{print $1}');
  1370.             HDTrack[$HI]=$(echo $geometry | awk '{print $3}');
  1371.             HDCylinder[$HI]=$(echo $geometry | awk '{print $5}');
  1372.  ###Look at the first 4 bytes of the second sector to identify type of partition table;
  1373.             case $(hexdump -v -s 512 -n 4 -e '"%_u"' $drive) in
  1374.             "EMBR")  HDPT[$HI]="BootIt";;
  1375.             "EFI ")  HDPT[$HI]="EFI";;
  1376.                  *)  HDPT[$HI]="MSDos";;
  1377.             esac;
  1378.             HI=$((HI+1));
  1379.           else   #if drive is  filesystem
  1380.               if [ $( expr match "$(BlkidTag "$drive" TYPE)" '.*raid') -eq 0 ] || [ "$(BlkidTag "$drive" UUID)" != "" ];
  1381.               then
  1382.                    FilesystemDrives[$FSD]="$drive";
  1383.                    ((FSD++));
  1384.               fi;
  1385.           fi;
  1386.       else
  1387.             echo -n "$(basename $drive) " >>$FakeHardDrives;
  1388.       fi;
  1389. done;
  1390. ############ Identify the MBR of each  hard drive.
  1391. echo "Identifying MBRs..." ;
  1392. for hi in ${!HDName[@]};
  1393.   do
  1394.     drive="${HDName[$hi]}";
  1395.     Message=$(echo is installed in the MBR of $drive)
  1396.     case $(hexdump -v -n  2 -e '/1 "%x"' $drive) in   ####Look at the first two bytes of the hard drive  to identify the boot code installed in the MBR
  1397.  
  1398. ################################ If Grub is in the MBR   #########################
  1399.  
  1400.         eb48) offset=$(hexdump -v -s 68 -n 4 -e '"%u"' $drive);### 0x44 contains the offset of the next stage
  1401.               if  [ "$offset" != 1 ];   ###if  Grub is installed without stage1.5 files
  1402.               then
  1403.                   stage2_loc $drive;
  1404.                   Message=$(echo $Message and  $Stage2_Msg)
  1405.               else                         ### if grub is installed with stage1.5 files
  1406.                   Grub_String=$(hexdump -v -s 1042 -n 94 -e '"%_u"' $drive);
  1407.                   Grub_Version=${Grub_String%%nul*};
  1408.                   tmp='/'${Grub_String#*/};
  1409.                   tmp=${tmp%%nul*};
  1410.                   stage=$(echo $tmp| awk '{print $1}');
  1411.                   menu=$(echo $tmp| awk '{print $2}');
  1412.                   [[ "$menu" = "" ]] || stage=$(echo $stage and $menu);
  1413.                   part_info=$((1045 + ${#Grub_Version}));
  1414.                   pa=$(hexdump -v -s $part_info  -n 1 -e '"%d"' $drive);
  1415.                   part_info=$((part_info+1));
  1416.                   dr=$(hexdump -v -s $part_info -n 1 -e '"%d"' $drive);
  1417.                   dr=$((dr-127));
  1418.                   pa=$((pa+1));
  1419.                   if [ $dr = 128 ];
  1420.                   then
  1421.                        Message=$(echo $Message and looks on the same drive in partition \#$pa for $stage.)
  1422.                   else
  1423.                       Message=$(echo $Message and looks  on boot drive \#$dr in partition \#$pa for $stage.)
  1424.               fi;
  1425.             fi;
  1426.               BL="Grub "$Grub_Version;;
  1427. ###############################  If Grub 1.96 is in the MBR   #####################################
  1428.  
  1429.         eb4c ) BL="Grub 1.96";
  1430.               offset=$(hexdump -v -s 68 -n 4 -e '"%u"' $drive);### 0x44 contains the offset of the next stage
  1431.               if  [ "$offset" != 1 ];   ###if  Grub2 is  installed without  Core.
  1432.               then
  1433.                   core_loc $drive 1.96;
  1434.                   Message=$(echo $Message and  $Core_Msg)
  1435.               else                      ### if Grub2  is installed with Core
  1436.                   Grub_String=$(hexdump -v -s 1056 -n 64 -e '"%_u"' $drive);
  1437.                   Core_Dir=$(echo  $Grub_String | sed s/nul[^$]*//);
  1438.                   pa=$(hexdump -v -s 1044  -n 1 -e '"%d"' $drive);
  1439.                   dr=$(hexdump -v -s 77  -n 1 -e '"%d"' $drive);
  1440.                   dr=$((dr-127));
  1441.                   pa=$((pa+1));
  1442.                   if [ $dr = 128 ];
  1443.                   then
  1444.                        Message=$(echo $Message and looks on the same drive in partition \#$pa for $Core_Dir.)
  1445.                   else
  1446.                       Message=$(echo $Message and looks  on boot drive \#$dr in partition \#$pa for $Core_Dir.)
  1447.               fi;
  1448.             fi;;
  1449.  
  1450. ################### If  Grub 2 in the MBR###################################
  1451.         eb63 ) BL="Grub 2"
  1452.              offset=$(hexdump -v -s 92 -n 4 -e '"%u"' $drive);### 0x5c contains the offset of the core
  1453.              if  [ "$offset" != 1 ];   ###if  Grub2 is  installed without embeded  Core.
  1454.              then
  1455.                  core_loc $drive 1.97;
  1456.                   Message=$(echo $Message and  $Core_Msg)
  1457.              else                      ### if Grub2  is installed with Core
  1458.                   Grub_String=$(hexdump -v -s 1052 -n 64 -e '"%_u"' $drive);
  1459.                   Core_Dir=$(echo  $Grub_String | sed s/nul[^$]*//);
  1460.                   pa=$(hexdump -v -s 1044  -n 1 -e '"%d"' $drive);
  1461.                   dr=$(hexdump -v -s 77  -n 1 -e '"%d"' $drive);
  1462.                   dr=$((dr-127));
  1463.                   pa=$((pa+1));
  1464.                   if [ $pa = 255 ];
  1465.                   then
  1466.                       Message=$(echo $Message and looks  for $Core_Dir.)
  1467.                   else
  1468.                        Message=$(echo $Message and looks on the same drive in partition \#$pa for $Core_Dir.)
  1469.                  
  1470.                   fi;
  1471.             fi;;
  1472. ##############################################################################################
  1473.          ebe) BL=ThinkPad;;
  1474.         31c0) BL="Acer 3";;
  1475.         33c0) BL=Windows;;
  1476.         33ff) BL='HP/Gateway';;
  1477.         b800) BL=PloP;;
  1478.         ea1e) BL="Truecrypt Boot Loader";;
  1479.         eb04) BL=Solaris;;
  1480.         eb31) BL=Paragon;;
  1481.         eb5e) case $(hexdump -v -n  3 -e '/1 "%x"' $drive) in   ####Look at the first three bytes of the hard drive to identify the boot code installed in the MBR
  1482.                 eb5e00) BL=fbinst;;
  1483.                 eb5e80) BL=Grub4Dos;;
  1484.               esac;;
  1485.         fa31) case $(hexdump -v -n  3 -e '/1 "%x"' $drive) in   ####Look at the first tree bytes of the hard drive to identify the boot code installed in the MBR
  1486.                 fa31c0) BL=Syslinux;;
  1487.                 fa31c9) BL="Master Boot LoaDeR";;  
  1488.               esac;;
  1489.  
  1490.         fa33) BL="No boot loader";;
  1491.         fab8) BL="No boot loader";;  
  1492.         fabe) BL="No boot loader?";;
  1493.         faeb) BL=Lilo;;
  1494.         fc31) BL=Testdisk;;
  1495.         fc33) BL=GAG;;
  1496.         fceb) BL="BootIt NG";;
  1497.           00) BL="No boot loader";;
  1498.            *) BL="No known boot loader"
  1499.               echo "Unknown MBR on $drive" >> $Unknown_MBR;
  1500.               echo >> $Unknown_MBR;
  1501.               hexdump -v -n 512 -C $drive >> $Unknown_MBR;
  1502.               echo >> $Unknown_MBR;;
  1503.         esac;
  1504.         ##Output message at beginning of summary that gives MBR info for each drive:
  1505.         echo -n " => ">>"$Log"
  1506.         echo "$BL $Message" | fold -s -w 75 | sed -e '2~1s/.*/    &/' >>"$Log"  
  1507.         HDMBR[$hi]=$BL;
  1508.     done;
  1509.     echo>>"$Log";
  1510. ######################################################################################
  1511. #############   Store and Display all the partitions tables.##########################
  1512. for HI in ${!HDName[@]};
  1513.     do
  1514.     drive=${HDName[$HI]};
  1515.     echo "Computing Partition Table of $drive...";
  1516.     FP=$((PI+1)); #used if non-MS_DOS partition table is not in use.
  1517.     FirstPartition[$HI]=$FP;
  1518.     PTType=${HDPT[$HI]};
  1519.     HDPT[$HI]="MSDos";
  1520.     echo "Drive: $(basename $drive ) ___________________ _____________________________________________________" >>$PartitionTable;
  1521.     fdisk  -lu $drive 2>>$Trash |sed '/omitting/ d'|sed '6,$ d' >>$PartitionTable;
  1522.     echo >>$PartitionTable;
  1523.     printf "$PTFormat" "Partition" "Boot" "Start" "End"  "Size"  "Id" "System">>$PartitionTable;
  1524.     echo >>$PartitionTable;
  1525.     ReadPT $HI 0  4 $PartitionTable "$PTFormat" "" 0;
  1526.     echo >>$PartitionTable;
  1527.     LastPartition[$HI]=$PI;
  1528.     LP=$PI;
  1529.     CheckPT  ${FirstPartition[$HI]} ${LastPartition[$HI]}  $PartitionTable $HI;
  1530.     echo >>$PartitionTable;
  1531.     HDPT[$HI]=$PTType;
  1532.     case $PTType in
  1533.       BootIt)  echo -n  BootIt NG Partition Table detected>>$PartitionTable;
  1534.               [[ "${HDMBR[$HI]}" = "BootIt NG" ]] && echo . >>$PartitionTable || echo , but does not seem to be used. >>$PartitionTable;
  1535.               echo>>$PartitionTable;
  1536.               ReadEMBR  $HI $PartitionTable;
  1537.               echo >>$PartitionTable;
  1538.               if [ "${HDMBR[$HI]}" = "BootIt NG" ];
  1539.               then
  1540.                    LastPartition[$HI]=$PI;
  1541.                    CheckPT  ${FirstPartition[$HI]} ${LastPartition[$HI]}  $PartitionTable $HI;
  1542.               else
  1543.                    FirstPartition[$HI]=$FP;
  1544.               fi;;
  1545.          EFI) FirstPartition[$HI]=$((PI+1));
  1546.               EFIee=$(hexdump -v -s 450 -n 1 -e '"%x"' $drive);
  1547.               echo -n  GUID Partition Table detected>>$PartitionTable;
  1548.               [[ "$EFIee" = "ee" ]] && echo . >>$PartitionTable || echo , but does not seem to be used. >>$PartitionTable ;
  1549.               echo >>$PartitionTable;
  1550.               ReadEFI  $HI $PartitionTable;
  1551.               echo >>$PartitionTable;
  1552.               if [ "$EFIee" = "ee" ];
  1553.               then
  1554.                    LastPartition[$HI]=$PI;
  1555.                    CheckPT  ${FirstPartition[$HI]} ${LastPartition[$HI]}  $PartitionTable $HI;
  1556.               else
  1557.                    FirstPartition[$HI]=$FP;
  1558.               fi;;
  1559.       esac;    
  1560. done;
  1561.  
  1562. for hi in ${!HDName[@]};  ############Loop through all Hard Drives
  1563.  do
  1564.  drive=${HDName[$hi]}
  1565. for (( pi = FirstPartition[$hi]; pi <= LastPartition[$hi]; pi++ ));  ## And then loop through                                                                      ###the partitions  on that drive
  1566. do
  1567.          
  1568.       part_type=${TypeArray[$pi]};  #### Type of the partition according to fdisk
  1569.       start=${StartArray[$pi]};
  1570.       size=${SizeArray[$pi]};
  1571.       end=${EndArray[$pi]};
  1572.       kind=${KindArray[$pi]};
  1573.       system=${SystemArray[$pi]};
  1574.       if [[ "${DeviceArray[$pi]}" = "" ]];
  1575.       then
  1576.           name="${NamesArray[$pi]}";
  1577.           mountname=$(basename $drive)"_"$pi;
  1578.           part=$(losetup -f --show  -o $((start*512)) $drive);
  1579.          #### --sizelimit $((size*512))    --sizelimit seems to be a recently added option for losetup.  Failed on Hardy
  1580.       else
  1581.           part="${DeviceArray[$pi]}";
  1582.           name=$(basename $part);  ####  Name of the partition (/dev/sda8 -> sda8)
  1583.           mountname=$name;      
  1584.       fi;
  1585.  
  1586.       Get_Partition_Info "$Log" "$Log1" "$part" "$name" "$mountname" "$kind" "$start" "$end" "$system" "$pi";
  1587.      
  1588.      [[ "${DeviceArray[$pi]}" = ""  ]] && losetup -d $part;
  1589.      done;  ### end of partition loop
  1590.      done;  ### end of hard drive loop
  1591.  
  1592.  
  1593. ################ Deactivate dmraid's activated by the script#############
  1594.  
  1595. if [ "$InActiveDMRaid" != "" ];
  1596. then
  1597.    dmraid -an $InActiveDMRaid
  1598. fi;
  1599.  
  1600. ##################### Search LVM partitions for information.             #########
  1601. ##################### only works if the "LVM2"-package is installed     #########
  1602. if type lvscan >>$Trash 2>>$Trash && type lvdisplay >>$Trash 2>>$Trash && type lvchange >>$Trash 2>>$Trash;
  1603.  
  1604. then   ###  if LVM2 is installed
  1605.    
  1606.    LVM_Partitions=$(lvscan| awk '{print $2}'| awk -F / '{print "/dev/mapper" "/" $3 "-" $4}'|sed s/.$//)
  1607.  
  1608.    for LVM in $LVM_Partitions;
  1609.    do
  1610.       LVM_Size=$(lvdisplay -c $LVM  |awk -F : '{print $7}');
  1611.       LVM_Status=$(lvdisplay $LVM |grep "LV Status"|awk '{print $3}');
  1612.       lvchange -ay $LVM;
  1613.       name=${LVM:12};
  1614.       mountname="LVM/""$name";
  1615.       kind="LVM";
  1616.       start=0;
  1617.       end=$LVM_Size;
  1618.       system="";
  1619.       pi="";
  1620.      
  1621.       Get_Partition_Info "$Log" "$Log1" "$LVM" "$name" "$mountname" "$kind" "$start" "$end" "$system" "$pi";
  1622.      
  1623.   [[ "$LVM_Status" = "NOT" ]] && lvchange -an "$LVM";
  1624.                          #deactivate all LVM's,which were not active.
  1625.  
  1626.      
  1627.     done;
  1628. fi;
  1629.  
  1630.  
  1631. ####################### Search MDRaid Partitons for Information##############################
  1632. ######################  Only works if "mdadm" is installed     #############################
  1633. if type mdadm >>$Trash 2>>$Trash;
  1634. then
  1635.     MD_Active_Array=$(mdadm --detail --scan |awk '{print $2}');
  1636.                    ## all arrays which are already assembled
  1637.     mdadm --assemble  --scan  #assemble all arrays
  1638.     MD_Array=$(mdadm --detail --scan|awk '{print $2}');
  1639.                     ## all arrays.
  1640.     for MD in $MD_Array;
  1641.     do
  1642.         MD_Size=$(fdisks $MD); #size in blocks
  1643.         MD_Size=$((2*MD_Size)); #size in sectors
  1644.         MD_Active=0;
  1645.         for MDA in $MD_Active_Array;  ## check whether MD is active
  1646.         do
  1647.           if [[ "$MDA" = "$MD" ]]
  1648.           then
  1649.               MD_Active=1;
  1650.               break;
  1651.           fi;
  1652.         done;
  1653.       name=${MD:5};
  1654.       mountname="MDRaid/""$name";
  1655.       kind="MDRaid";
  1656.       start=0;
  1657.       end=$MD_Size;
  1658.       system="";
  1659.       pi="";
  1660.      
  1661.       Get_Partition_Info "$Log" "$Log1" "$MD" "$name" "$mountname" "$kind" "$start" "$end" "$system" "$pi";
  1662.      
  1663.   [[ "$MD_Active" = 0 ]] && mdadm --stop $MD
  1664.  
  1665.                          #deactivate all MD_Raid's,which were not active.
  1666.    done;
  1667. fi;
  1668.  
  1669. ####################### Search Filessystem hard drive for information########################
  1670.  
  1671.     for FD  in ${FilesystemDrives[@]};
  1672.     do
  1673.       FD_Size=$(fdisks $FD); #size in blocks
  1674.       FD_Size=$((2*FD_Size)); #size in sectors
  1675.       name=${FD:5};
  1676.       mountname="FD/""$name";
  1677.       kind="FD";
  1678.       start=0;
  1679.       end=$FD_Size;
  1680.       system="";
  1681.       pi="";
  1682.      
  1683.       Get_Partition_Info "$Log" "$Log1" "$FD" "$name" "$mountname" "$kind" "$start" "$end" "$system" "$pi";
  1684.     done;
  1685.  
  1686.  
  1687. ###############################################################################################
  1688.  
  1689. echo '=========================== Drive/Partition Info: ============================='>>"$Log";
  1690. echo>>"$Log";
  1691.  
  1692. [ -e $PartitionTable ] && cat $PartitionTable>>"$Log" || echo no valid partition table found>>"$Log";
  1693.  
  1694.  
  1695. echo "blkid -c /dev/null: ____________________________________________________________">>"$Log";
  1696. echo>>"$Log";
  1697. printf "$BlkidFormat" Device  UUID TYPE LABEL>>"$Log";
  1698. echo>>"$Log"
  1699. for dev in $(blkid -o device);do PrintBlkid $dev;done;
  1700. sort -u $BLKID>>"$Log";
  1701. echo>>"$Log";
  1702.  
  1703. if [ $(ls -R /dev/mapper 2>>$Trash | wc -l) -gt 2 ]
  1704. then
  1705.  
  1706.   echo '=============================== "ls -R /dev/mapper/" output: ==============================='>>"$Log";
  1707.    ls -R /dev/mapper>>$Log
  1708.   echo>>"$Log";
  1709. fi;
  1710.          
  1711.  
  1712.  
  1713.  
  1714.  
  1715. echo '============================ "mount | grep ^/dev  output: ==========================='>>"$Log";
  1716. MountFormat='%-16s %-24s %-10s %s\n';
  1717. Fis=':x:x:x:x:'
  1718. echo>>"$Log";
  1719. printf "$MountFormat" "Device" "Mount_Point"  "Type"  "Options" >>"$Log";
  1720. echo>>"$Log";
  1721. mount | grep ' / '| grep -v '^/'| sed  's/ on /'$Fis'/' |sed 's/ type /'$Fis'/'|sed  's/ (/'$Fis'(/'|awk -F $Fis '{printf "'"$MountFormat"'", $1, $2, $3, $4 }'>>"$Log";
  1722. mount | grep '^/dev'|sed  's/ on /'$Fis'/' |sed 's/ type /'$Fis'/' |sed  's/ (/'$Fis'(/'|awk -F $Fis '{printf "'"$MountFormat"'", $1, $2, $3, $4 }'>>"$Log";
  1723. echo>>"$Log";
  1724.  
  1725.  
  1726. #################   Write the content of Log1 to the log file
  1727. [ -e "$Log1" ] && cat "$Log1">>"$Log";
  1728.  
  1729. if [ -e $Unknown_MBR ];
  1730. then
  1731.  echo "=========================== Unknown MBRs/Boot Sectors/etc =======================">>"$Log";
  1732.  echo>>"$Log";
  1733.  cat $Unknown_MBR>>"$Log";
  1734.  echo>>"$Log";
  1735. fi;
  1736.  
  1737. if [ -e $FakeHardDrives ];
  1738. then
  1739.  echo "=======Devices which don't seem to have a corresponding hard drive==============">>"$Log";
  1740.  echo>>"$Log";
  1741.  cat $FakeHardDrives>>"$Log";
  1742.  echo>>"$Log";
  1743. fi;
  1744.  
  1745.  
  1746. #####################  Write the Error Log to the log file
  1747. if [ -s $Error_Log ];
  1748. then
  1749.     echo "=============================== StdErr Messages: ===============================">>"$Log";
  1750.     echo>>"$Log";
  1751.     cat $Error_Log>>"$Log";
  1752. fi;
  1753.  
  1754. #####   Copy the  Log file to RESULTS file and make the  user the owner of Result file
  1755. cp "$Log" "$LogFile"
  1756. chown $(basename ~) "$LogFile";  
  1757.  
  1758. #######  Reset the Standard Output to the Terminal
  1759. #exec 1>&-;
  1760. #exec 1>&6;
  1761. #exec 6>&-;
  1762.  
  1763. echo Finished. The results are in the file $(basename "$LogFile") located in "$Dir";
  1764. exit
  1765.  

"bootinfo" Yapıştırmasına Cevap

Yukarıdaki yapıştırmaya buradan cevap yazabilirsiniz

Bir snipurl oluştur

Özel Yap

Akıllı hissediyor musunuz? Bazı gelişmiş ayarları yapın.