Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch_Modules/package/Scripts/Sub/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# Looks for the first 8 bytes of the GPTdiskGPTHeader to identify a GUID partition table.
8# Byte number 450 of the GPTdiskProtectiveMBR to identify ID of 'EE' to identify a GPT partition.
9# Byte numbers 466, 482 & 498 of the GPTdiskProtectiveMBR to identify further partitions.
10#
11# Exit with value 1 for GPT, 2 for GPT/MBR and 3 for MBR.
12# Exit with value 0 if nothing is found - this shouldn't happen.?
13
14# Receives targetDisk: for example, /dev/disk0s2
15# Receives targetVolume: Volume to install to.
16# Receives scriptDir: The location of the main script dir.
17
18
19if [ "$#" -eq 3 ]; then
20targetDisk="$1"
21targetVolume="$2"
22scriptDir="$3"
23echo "DEBUG: passed argument = $targetDisk"
24echo "DEBUG: passed argument for targetVolume = $targetVolume"
25echo "DEBUG: passed argument for scriptDir = $scriptDir"
26else
27echo "Error - wrong number of values passed"
28exit 9
29fi
30
31
32partitiontable=$( 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}' )
33if [ "${partitiontable:0:16}" == "4546492050415254" ]; then
34partitiontable=$( 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}' )
35
36if [ "${partitiontable:8:2}" == "ee" ]; then
37#echo "DEBUG: Found System ID 'EE' to identify GPT Partition"
38
39if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then
40#echo "DEBUG: Found System ID '00' for each remaining possible partition"
41partitiontable="GPT"
42#echo "DEBUG: ${partitiontable} found."
43#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT."
44exit 1
45 else
46partitiontable="GPT/MBR"
47#echo "DEBUG: ${partitiontable} found."
48#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT/MBR."
49exit 2
50fi
51fi
52else
53partitiontable="MBR"
54#echo "DEBUG: ${partitiontable} found."
55#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using MBR."
56exit 3
57fi
58
59#echo "DEBUG: No partition table found."
60"$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: No partition table found."
61
62exit 0

Archive Download this file

Revision: 2238