1 | #!/bin/bash␊ |
2 | ␊ |
3 | echo "==============================================="␊ |
4 | echo "Check the Partition Scheme"␊ |
5 | echo "******************************************"␊ |
6 | ␊ |
7 | # Receives passed value for the Target Disk␊ |
8 | # for example: /dev/disk0s2␊ |
9 | # Then looks for the following:␊ |
10 | # First 8 bytes of the GPTdiskGPTHeader to identify a GUID partition table.␊ |
11 | # Byte number 450 of the GPTdiskProtectiveMBR to identify ID of 'EE' to identify a GPT partition.␊ |
12 | # Byte numbers 466, 482 & 498 of the GPTdiskProtectiveMBR to identify further partitions.␊ |
13 | ␊ |
14 | if [ "$#" -eq 1 ]; then␊ |
15 | ␉targetDisk="$1"␊ |
16 | ␉echo "DEBUG: passed argument = $targetDisk"␊ |
17 | fi␊ |
18 | ␊ |
19 | ␊ |
20 | partitiontable=$( dd 2>/dev/null if="$targetDisk" count=1 skip=1 | dd 2>/dev/null count=8 bs=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )␊ |
21 | if [ "${partitiontable:0:16}" == "4546492050415254" ]; then␉␊ |
22 | ␉partitiontable=$( dd 2>/dev/null if="$targetDisk" count=1 | dd 2>/dev/null count=64 bs=1 skip=446 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )␊ |
23 | ␉if [ "${partitiontable:8:2}" == "ee" ]; then␊ |
24 | ␉␉echo "Found System ID 'EE' to identify GPT Partition"␊ |
25 | ␉␉if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then␊ |
26 | ␉␉␉echo "Found System ID '00' for each remaining possible partition"␊ |
27 | ␉␉␉partitiontable="GPT"␊ |
28 | ␉ ␉else␊ |
29 | ␉␉␉partitiontable="GPT/MBR"␊ |
30 | ␉␉fi␊ |
31 | ␉fi␊ |
32 | else␊ |
33 | ␉partitiontable="MBR"␊ |
34 | fi␊ |
35 | ␊ |
36 | echo "${partitiontable} found."␊ |
37 | echo "-----------------------------------------------"␊ |
38 | echo ""␊ |
39 | ␊ |
40 | exit 0 |