Chameleon

Chameleon Svn Source Tree

Root/branches/blackosx/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
37echo "Found System ID 'EE' to identify GPT Partition"
38
39if [ "${partitiontable:40:2}" == "00" ] && [ "${partitiontable:72:2}" == "00" ] && [ "${partitiontable:104:2}" == "00" ]; then
40echo "Found System ID '00' for each remaining possible partition"
41partitiontable="GPT"
42echo "${partitiontable} found."
43echo "-----------------------------------------------"
44echo ""
45#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT."
46exit 1
47 else
48partitiontable="GPT/MBR"
49echo "${partitiontable} found."
50echo "-----------------------------------------------"
51echo ""
52#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using a GPT/MBR."
53exit 2
54fi
55fi
56else
57partitiontable="MBR"
58echo "${partitiontable} found."
59echo "-----------------------------------------------"
60echo ""
61#"$scriptDir"InstallLog.sh "${targetVolume}" "${targetDisk} is using MBR."
62exit 3
63fi
64
65echo "No partition table found."
66echo "-----------------------------------------------"
67echo ""
68
69"$scriptDir"InstallLog.sh "${targetVolume}" "NOTE: No partition table found."
70
71exit 0

Archive Download this file

Revision: 1579