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 | # Exit with value 1 for GPT, 2 for GPT/MBR and 3 for MBR. ␊ |
15 | # Exit with value 0 if nothing is found - this shouldn't happen.?␊ |
16 | ␊ |
17 | if [ "$#" -eq 1 ]; then␊ |
18 | ␉targetDisk="$1"␊ |
19 | ␉echo "DEBUG: passed argument = $targetDisk"␊ |
20 | fi␊ |
21 | ␊ |
22 | ␊ |
23 | 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}' )␊ |
24 | if [ "${partitiontable:0:16}" == "4546492050415254" ]; then␉␊ |
25 | ␉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}' )␊ |
26 | ␉if [ "${partitiontable:8:2}" == "ee" ]; then␊ |
27 | ␉␉echo "Found System ID 'EE' to identify GPT Partition"␊ |
28 | ␉␉if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then␊ |
29 | ␉␉␉echo "Found System ID '00' for each remaining possible partition"␊ |
30 | ␉␉␉partitiontable="GPT"␊ |
31 | ␉␉␉echo "${partitiontable} found."␊ |
32 | ␉␉␉echo "-----------------------------------------------"␊ |
33 | ␉␉␉echo ""␊ |
34 | ␉␉␉exit 1␊ |
35 | ␉ ␉else␊ |
36 | ␉␉␉partitiontable="GPT/MBR"␊ |
37 | ␉␉␉echo "${partitiontable} found."␊ |
38 | ␉␉␉echo "-----------------------------------------------"␊ |
39 | ␉␉␉echo ""␊ |
40 | ␉␉␉exit 2␊ |
41 | ␉␉fi␊ |
42 | ␉fi␊ |
43 | else␊ |
44 | ␉partitiontable="MBR"␊ |
45 | ␉echo "${partitiontable} found."␊ |
46 | ␉echo "-----------------------------------------------"␊ |
47 | ␉echo ""␊ |
48 | ␉exit 3␊ |
49 | fi␊ |
50 | ␊ |
51 | echo "No partition table found."␊ |
52 | echo "-----------------------------------------------"␊ |
53 | echo ""␊ |
54 | exit 0 |