Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/blackosx/trunk/PackageBuilder/Main_Package_Elements/Scripts/CheckPartitionScheme.sh

  • Property svn:executable set to *
1#!/bin/bash
2
3echo "==============================================="
4echo "Check the Partition Scheme: GPT, GPT/MBR or MBR?"
5echo "************************************************"
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
17if [ "$#" -eq 1 ]; then
18targetDisk="$1"
19echo "DEBUG: passed argument = $targetDisk"
20else
21echo "Error - wrong number of values passed"
22exit 9
23fi
24
25
26partitiontable=$( 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}' )
27if [ "${partitiontable:0:16}" == "4546492050415254" ]; then
28partitiontable=$( 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}' )
29if [ "${partitiontable:8:2}" == "ee" ]; then
30echo "Found System ID 'EE' to identify GPT Partition"
31if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then
32echo "Found System ID '00' for each remaining possible partition"
33partitiontable="GPT"
34echo "${partitiontable} found."
35echo "-----------------------------------------------"
36echo ""
37exit 1
38 else
39partitiontable="GPT/MBR"
40echo "${partitiontable} found."
41echo "-----------------------------------------------"
42echo ""
43exit 2
44fi
45fi
46else
47partitiontable="MBR"
48echo "${partitiontable} found."
49echo "-----------------------------------------------"
50echo ""
51exit 3
52fi
53
54echo "No partition table found."
55echo "-----------------------------------------------"
56echo ""
57exit 0

Archive Download this file

Revision: 255