Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1553