Chameleon

Chameleon Commit Details

Date:2011-10-19 09:23:13 (12 years 6 months ago)
Author:blackosx
Commit:1636
Parents: 1635
Message:Make changes for checking previous installations.
Changes:
M/branches/blackosx/package/Scripts/Sub/UnMountEFIvolumes.sh
M/branches/blackosx/package/Scripts/Sub/CheckPreviousChameleon.sh

File differences

branches/blackosx/package/Scripts/Sub/CheckPreviousChameleon.sh
3333
3434
3535
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
36
37
38
39
40
5641
5742
5843
......
8671
8772
8873
74
8975
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
90106
91107
92108
93
94
95
109
110
111
112
96113
97
98
114
115
99116
100
101
102
103
104
105
106
107
117
118
119
120
121
122
123
124
108125
109126
110127
111128
112129
113130
114
115
131
132
116133
117134
118
119
135
136
120137
121138
122139
123140
124141
125142
126
143
144
127145
128146
129
147
130148
131149
132150
133
134
135
136
137
138
139
140
141
142
143
144
145
146
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
147178
148
149
179
180
150181
151182
152183
153184
154185
155
156
186
187
157188
158189
159190
160191
161192
162193
163
164
165
166
167
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
168217
169218
170219
171
220
221
172222
223
224
173225
174226
175227
228
176229
177230
178231
exit 9
fi
# Check for existing Chameleon installations on a different
# partition of the same target disk.
#echo "DEBUG: Checking for existing Chameleon installations on ${targetDisk#/dev/}..."
sliceNumber=$( echo ${targetDeviceRaw#*disk*s} )
# strip slice from end
targetDiskRawNoSlice=$( echo ${targetDeviceRaw%$sliceNumber} )
# Are there any other partitions on the disk?
# How many actual partitions are there?
numSlices=$(( $( diskutil list | grep $( echo ${targetDisk#/dev/} ) | sed -n '$=' ) -2 ))
# Only check the disk for Chameleon installations if there is more than one partition.
if [ $numSlices -gt 1 ]; then
# If a GPT is used then we are going to have the check the EFI system partition
# for the stage 2 'boot' file. As this script is called from the Main EFI
# postinstall script, so lets mount the EFI system partition here instead.
# ===============================================
# Functions
# ===============================================
mountESP()
{
if [ "${partitiontable}" = "GUID_partition_scheme" ]; then
# Unmount ALL mounted volumes named EFI
exit 2
fi
fi
}
# ===============================================
# Prepare some vars
# ===============================================
sliceNumber=$( echo ${targetDeviceRaw#*disk*s} )
# strip slice from end
targetDiskRawNoSlice=$( echo ${targetDeviceRaw%$sliceNumber} )
# Are there any other partitions on the disk?
# How many actual partitions are there?
numSlices=$(( $( diskutil list | grep $( echo ${targetDisk#/dev/} ) | sed -n '$=' ) -2 ))
# ===============================================
# Checking the disk for existing Chameleon installations
# if there is more than one partition on the disk.
# ===============================================
if [ $numSlices -gt 1 ]; then
#echo "DEBUG: Checking for existing Chameleon installations on ${targetDisk#/dev/}..."
"$scriptDir"InstallLog.sh "${installerVolume}" "LineBreak"
"$scriptDir"InstallLog.sh "${installerVolume}" "Checking for previous chameleon installations on ${targetDisk#/dev/}"
# If a GPT is used then we are going to have the check the EFI system partition
# for the stage 2 'boot' file. As this script is called from the Main EFI
# postinstall script, so lets mount the EFI system partition here instead.
mountESP
#Scan all partitions for Chameleon code
for (( i=1; i <= $numSlices; i++ ));
do
stageExistence=0
stage0FirstBootable=0
previousExistence="NONE"
stagesFound=0
stage0type=0
stage1Existence="NONE"
stage2Existence=0
targetDiskRaw=$targetDiskRawNoSlice$i
# Check for existing stage 0 boot file (same code as CheckDiskMicrocode.sh script)
# Check for existing stage 0 boot file (code from CheckDiskMicrocode.sh script)
stage0type=$( dd 2>/dev/null if="$targetDisk" count=3 bs=1 skip=105 | xxd | awk '{print $2$3}' )
if [ "${stage0type}" == "0b807c" ] || [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ] || [ "${stage0type}" == "742b80" ]; then
#echo "DEBUG: stage 0 loader found on $targetDisk"
(( stageExistence++ ))
# While here, check just for either existing boot0hfs, boot0md or boot0md (dmazar's boot0workV2)
if [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ] || [ "${stage0type}" == "742b80" ]; then
stage0FirstBootable=1
fi
if [ "${stage0type}" == "0a803c" ] || [ "${stage0type}" == "ee7505" ] || [ "${stage0type}" == "742b80" ]; then
#echo "DEBUG: stage 0 (hfs) loader found on $targetDisk"
(( stagesFound++ ))
stage0type=2
elif [ "${stage0type}" == "0b807c" ]; then
#echo "DEBUG: stage 0 (active) loader found on $targetDisk"
(( stagesFound++ ))
stage0type=1
fi
# Check for existence of a bootable partition boot sector containing either boot1h or boot1f32
boot1Search=$( dd 2>/dev/null if="$targetDiskRaw" count=1 | perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ "${boot1Search:0:16}" == "fa31c08ed0bcf0ff" ] && [ "${boot1Search:1020:2}" == "55" ]; then
#echo "DEBUG: boot1h found on "$targetDiskRaw
(( stageExistence++ ))
previousExistence="boot1"
(( stagesFound++ ))
stage1Existence="boot1h"
elif [ "${boot1Search:0:4}" == "e962" ] && [ "${boot1Search:180:12}" == "424f4f542020" ] && [ "${boot1Search:1020:2}" == "55" ]; then
#echo "DEBUG: boot1f32 found on "$targetDiskRaw
(( stageExistence++ ))
previousExistence="boot1f32"
(( stagesFound++ ))
stage1Existence="boot1f32"
fi
# Check for existing stage 2 boot file.
# Include checking the EFI system partition if it exists and is mounted.
if [ -e "$( df | grep ${targetDisk}s${i} | awk '{ print $6 }' )"/boot ]; then
#echo "DEBUG: boot found on $targetDiskRaw"
(( stageExistence++ ))
(( stagesFound++ ))
stage2Existence=1
fi
if [ $stageExistence -ge 2 ] && [ "$previousExistence" != "NONE" ] && [ $i -ne $sliceNumber ]; then
if [ $stagesFound -ge 2 ] && [ "$stage1Existence" != "NONE" ] && [ $i -ne $sliceNumber ]; then
# There is previous Chameleon stage 1 code on a partition boot sector,
# and either a complete or incomplete installation (ie. boot0 or boot are missing).
if [ $stageExistence == 3 ]; then
"$scriptDir"InstallLog.sh "${installerVolume}" "INFO: There is already an existing Chameleon installation on $targetDiskRaw."
if [ $i -lt $sliceNumber ]; then
"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: And that installation will still be used as it's on an earlier partition."
else
"$scriptDir"InstallLog.sh "${installerVolume}" "INFO: but won't interfere as you're installing to an earlier partition."
fi
else
"$scriptDir"InstallLog.sh "${installerVolume}" "INFO: $previousExistence already exists at ${targetDisk}s${i}"
# A b1f:error or boot0:error could result if the following conditions are true:
# A) Boot0hfs, Boot0md or Boot0md (dmazar's Boot0workV2) is being used.
# B) The previous stage 1 code is on a lower partiton than the one being installed to now.
# C) boot is missing from that partition.
if [ $stagesFound == 3 ] && [ $i -lt $sliceNumber ]; then
# Exisitng installation found which will still be default.
message="************************** TAKE NOTE *****************************
**** There is an existing Chameleon installation on $targetDiskRaw
**** and that installation will still be the default loader as it's
**** on an earlier partition. If you want this new installation on
**** $installerVolume to be default then you will need to remove the
**** boot file from $targetDiskRaw and re-run this installer.
**************************************************************"
"$scriptDir"InstallLog.sh "${installerVolume}" "${message}"
fi
if [ $stagesFound == 3 ] && [ $i -gt $sliceNumber ]; then
# Exisitng installation found which will no longer be default.
message="NOTE: There is an existing Chameleon installation on $targetDiskRaw
NOTE: but this installation on $targetDevice will be the default loader
NOTE: because you're installing to an earlier partition on the disk."
"$scriptDir"InstallLog.sh "${installerVolume}" "${message}"
fi
# User could see a b1f:error or boot0:error if the following conditions are true:
# A) Boot0hfs, Boot0md or Boot0md (dmazar's Boot0workV2) is being used.
# B) The previous stage 1 code is on a lower partiton than the one being installed to now.
# C) boot is missing from that partition.
if [ $stagesFound == 2 ] && [ $stage2Existence == 0 ]; then
# Exisitng boot0 and boot1 only found - missing boot
"$scriptDir"InstallLog.sh "${installerVolume}" "INFO: Found $stage1Existence installed to ${targetDisk}s${i}"
# stage0FirstBootable=1 is used to know if 'A' is true.
if [ $stage0FirstBootable == 1 ]; then
# stage0type=2 is used to know if 'A' is true.
if [ $stage0type == 2 ]; then
# i = current slice we're checking, slicenumber = slice trying to install to.
if [ $i -lt $sliceNumber ]; then
"$scriptDir"InstallLog.sh "${installerVolume}" "WARN: Conditions point to the possibility of a boot failure"
# Fix by making previous paritionboot sector un-bootable
# Change Byte 01FExh to 00 (510 decimal)
mesaageToPost="---
# Change Byte 01FExh to 00 (510 decimal)
message="---
FIX: Make ${targetDisk}s${i} boot sector un-bootable by changing byte 1FEh to 00.
NOTE: Any Extra folder you had there will still be there. If you want to use
NOTE: ${targetDisk}s${i} again as your boot partition then re-run this installer
NOTE: selecting it as the target, ONLY choosing the 'Chameleon Bootloader' option
NOTE: and NONE of the other options.
---"
"$scriptDir"InstallLog.sh "${installerVolume}" "${mesaageToPost}"
dd if=${targetDisk}s${i} count=1 bs=512 of=/tmp/originalBootSector
cp /tmp/originalBootSector /tmp/newBootSector
dd if="$scriptDir/patch" of=/tmp/newBootSector bs=1 count=1 seek=510 conv=notrunc
dd if=/tmp/newBootSector of=${targetDisk}s${i} count=1 bs=512
"$scriptDir"InstallLog.sh "${installerVolume}" "${message}"
if [ $i == 1 ]; then
umount /Volumes/EFI
fi
if [ "$( fstyp "${targetDisk}"s1 | grep hfs )" ]; then
#echo "DEBUG: HFS - changing byte 1FEh to 00"
dd if=${targetDisk}s${i} count=2 bs=512 of=originalBootSector
cp originalBootSector newBootSector
dd if="patch" of=newBootSector bs=1 count=1 seek=510 conv=notrunc
dd if=newBootSector of=${targetDisk}s${i} count=2 bs=510
fi
if [ "$( fstyp "${targetDisk}"s1 | grep msdos )" ]; then
#echo "DEBUG: MSDOS - changing byte 1FEh to 00"
dd if=${targetDisk}s${i} count=1 bs=512 of=/tmp/originalBootSector
cp /tmp/originalBootSector /tmp/newBootSector
dd if="$scriptDir/patch" of=/tmp/newBootSector bs=1 count=1 seek=510 conv=notrunc
dd if=/tmp/newBootSector of=${targetDisk}s${i} count=1 bs=512
fi
mountESP
else
"$scriptDir"InstallLog.sh "${installerVolume}" "INFO: but won't interfere as you're installing to an earlier partition."
fi
else
elif [ $stage0type == 1 ]; then
# boot0 was found which looks for boot1 on the first active partition.
"$scriptDir"InstallLog.sh "${installerVolume}" "NOTE: so select to boot that partition (if used) with active flag."
#else
#echo "DEBUG: Boot0 not found"
fi
fi
fi
done
#else
#echo "DEBUG: Just one slice"
branches/blackosx/package/Scripts/Sub/UnMountEFIvolumes.sh
2424
2525
2626
27
28
27
28
2929
3030
3131
attempts=1
while [ "$( df | grep EFI )" ] && [ $attempts -lt 5 ]; do
#echo "DEBUG: Unmounting $( df | grep EFI | awk '{print $1}' )"
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Find and unmount any volume named 'EFI':"
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "$( df | grep EFI | awk '{print $1}' )"
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Volume named 'EFI' is mounted..."
"$scriptDir"InstallLog.sh "${targetVolumeChosenByUser}" "Unmounting $( df | grep EFI | awk '{print $1}' )"
umount -f $( df | grep EFI | awk '{print $1}' )
(( attempts++ ))
done

Archive Download the corresponding diff file

Revision: 1636