]>
code.delx.au - refind/blob - install.sh
3 # Linux/MacOS X script to install rEFInd
9 # The "esp" option is valid only on Mac OS X; it causes
10 # installation to the EFI System Partition (ESP) rather than
11 # to the current OS X boot partition. Under Linux, this script
12 # installs to the ESP by default.
14 # This program is copyright (c) 2012 by Roderick W. Smith
15 # It is released under the terms of the GNU GPL, version 3,
16 # a copy of which should be included in the file COPYING.txt.
20 # 0.3.3.1 -- Fixed OS X 10.7 bug; also works as make target
21 # 0.3.2.1 -- Check for presence of source files; aborts if not present
22 # 0.3.2 -- Initial version
24 # Note: install.sh version numbers match those of the rEFInd package
25 # with which they first appeared.
30 # Functions used by both OS X and Linux....
33 # Abort if the rEFInd files can't be found.
34 # Also sets $ConfFile to point to the configuration file, and
35 # $IconsDir to point to the icons directory
37 # Note: This check is satisfied if EITHER the 32- or the 64-bit version
38 # is found, even on the wrong platform. This is because the platform
39 # hasn't yet been determined. This could obviously be improved, but it
40 # would mean restructuring lots more code....
41 if [[ ! -f $RefindDir/refind_ia32.efi
&& ! -f $RefindDir/refind_x64.efi
]] ; then
42 echo "The rEFInd binary file is missing! Aborting installation!"
46 if [[ -f $RefindDir/refind.conf-sample
]] ; then
47 ConfFile
=$RefindDir/refind.conf-sample
48 elif [[ -f $ThisDir/refind.conf-sample
]] ; then
49 ConfFile
=$ThisDir/refind.conf-sample
51 echo "The sample configuration file is missing! Aborting installation!"
55 if [[ -d $RefindDir/icons
]] ; then
56 IconsDir
=$RefindDir/icons
57 elif [[ -d $ThisDir/icons
]] ; then
58 IconsDir
=$ThisDir/icons
60 echo "The icons directory is missing! Aborting installation!"
62 #|| ! -f $RefindDir/refind.conf-sample || ! -d $RefindDir/icons
65 # Copy the rEFInd files to the ESP or OS X root partition.
66 # Sets Problems=1 if any critical commands fail.
68 mkdir
-p $InstallPart/$TargetDir &> /dev
/null
69 if [[ $Platform == 'EFI32' ]] ; then
70 cp $RefindDir/refind_ia32.efi
$InstallPart/$TargetDir
71 if [[ $?
!= 0 ]] ; then
74 Refind
="refind_ia32.efi"
75 elif [[ $Platform == 'EFI64' ]] ; then
76 cp $RefindDir/refind_x64.efi
$InstallPart/$TargetDir
77 if [[ $?
!= 0 ]] ; then
80 Refind
="refind_x64.efi"
82 echo "Unknown platform! Aborting!"
85 echo "Copied rEFInd binary file $Refind"
87 if [[ -d $InstallPart/$TargetDir/icons
]] ; then
88 rm -rf $InstallPart/$TargetDir/icons-backup
&> /dev
/null
89 mv -f $InstallPart/$TargetDir/icons
$InstallPart/$TargetDir/icons-backup
90 echo "Notice: Backed up existing icons directory as icons-backup."
92 cp -r $IconsDir $InstallPart/$TargetDir
93 if [[ $?
!= 0 ]] ; then
96 if [[ -f $InstallPart/$TargetDir/refind.conf
]] ; then
97 echo "Existing refind.conf file found; copying sample file as refind.conf-sample"
98 echo "to avoid collision."
100 cp -f $ConfFile $InstallPart/$TargetDir
101 if [[ $?
!= 0 ]] ; then
105 echo "Copying sample configuration file as refind.conf; edit this file to configure"
108 cp -f $ConfFile $InstallPart/$TargetDir/refind.conf
109 if [[ $?
!= 0 ]] ; then
113 } # CopyRefindFiles()
117 # A series of OS X support functions....
120 # Mount the ESP at /Volumes/ESP or determine its current mount
122 # Sets InstallPart to the ESP mount point
123 # Sets UnmountEsp if we mounted it
125 # Identify the ESP. Note: This returns the FIRST ESP found;
126 # if the system has multiple disks, this could be wrong!
127 Temp
=`diskutil list | grep EFI`
128 Esp
=/dev
/`echo $Temp | cut -f 5 -d ' '`
129 # If the ESP is mounted, use its current mount point....
130 Temp
=`df | grep $Esp`
131 InstallPart
=`echo $Temp | cut -f 6 -d ' '`
132 if [[ $InstallPart == '' ]] ; then
133 mkdir
/Volumes
/ESP
&> /dev
/null
134 mount
-t msdos
$Esp /Volumes
/ESP
135 if [[ $?
!= 0 ]] ; then
136 echo "Unable to mount ESP! Aborting!\n"
140 InstallPart
="/Volumes/ESP"
144 # Control the OS X installation.
145 # Sets Problems=1 if problems found during the installation.
147 echo "Installing rEFInd on OS X...."
148 if [[ $1 == 'esp' ||
$1 == 'ESP' ]] ; then
153 echo "Installing rEFInd to the partition mounted at '$InstallPart'"
154 Platform
=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
156 if [[ $1 == 'esp' ||
$1 == 'ESP' ]] ; then
157 bless
--mount $InstallPart --setBoot --file $InstallPart/$TargetDir/$Refind
159 bless
--setBoot --folder $InstallPart/$TargetDir --file $InstallPart/$TargetDir/$Refind
161 if [[ $?
!= 0 ]] ; then
165 echo "WARNING: If you have an Advanced Format disk, *DO NOT* attempt to check the"
166 echo "bless status with 'bless --info', since this is known to cause disk corruption"
167 echo "on some systems!!"
173 # Now a series of Linux support functions....
176 # Identifies the ESP's location (/boot or /boot/efi); aborts if
177 # the ESP isn't mounted at either location.
178 # Sets InstallPart to the ESP mount point.
180 EspLine
=`df /boot/efi | grep boot`
181 InstallPart
=`echo $EspLine | cut -d " " -f 6`
182 EspFilesystem
=`grep $InstallPart /etc/mtab | cut -d " " -f 3`
183 if [[ $EspFilesystem != 'vfat' ]] ; then
184 echo "/boot/efi doesn't seem to be on a VFAT filesystem. The ESP must be mounted at"
185 echo "/boot or /boot/efi and it must be VFAT! Aborting!"
188 echo "ESP was found at $InstallPart using $EspFilesystem"
191 # Uses efibootmgr to add an entry for rEFInd to the EFI's NVRAM.
192 # If this fails, sets Problems=1
194 Efibootmgr
=`which efibootmgr 2> /dev/null`
195 if [[ $Efibootmgr ]] ; then
196 modprobe efivars
&> /dev
/null
197 InstallDisk
=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 1-8`
198 PartNum
=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 9-10`
199 EntryFilename
=$TargetDir/$Refind
200 EfiEntryFilename
=`echo ${EntryFilename//\//\\\}`
201 ExistingEntry
=`$Efibootmgr -v | grep $Refind`
202 if [[ $ExistingEntry ]] ; then
203 echo "An existing EFI boot manager entry for rEFInd seems to exist:"
205 echo "$ExistingEntry"
207 echo "This entry is NOT being modified, and no new entry is being created."
209 $Efibootmgr -c -l $EfiEntryFilename -L rEFInd
-d $InstallDisk -p $PartNum &> /dev
/null
210 if [[ $?
!= 0 ]] ; then
219 if [[ $EfibootmgrProblems ]] ; then
221 echo "ALERT: There were problems running the efibootmgr program! You may need to"
222 echo "rename the $Refind binary to the default name (EFI/boot/bootx64.efi"
223 echo "on x86-64 systems or EFI/boot/bootia32.efi on x86 systems) to have it run!"
228 # Controls rEFInd installation under Linux.
229 # Sets Problems=1 if something goes wrong.
231 echo "Installing rEFInd on Linux...."
234 if [[ $CpuType == 'x86_64' ]] ; then
236 elif [[ $CpuType == 'i386' ||
$CpuType == 'i486' ||
$CpuType == 'i586' ||
$CpuType == 'i686' ]] ; then
239 echo "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based"
240 echo "computers are VERY RARE. If you've installed a 32-bit version of Linux"
241 echo "on a 64-bit computer, you should manually install the 64-bit version of"
242 echo "rEFInd. If you're installing on a Mac, you should do so from OS X. If"
243 echo "you're positive you want to continue with this installation, answer 'Y'"
244 echo "to the following question..."
246 echo -n "Are you sure you want to continue (Y/N)? "
248 if [[ $ContYN == "Y" ||
$ContYN == "y" ]] ; then
249 echo "OK; continuing with the installation..."
254 echo "Unknown CPU type '$CpuType'; aborting!"
262 # The main part of the script. Sets a few environment variables,
263 # performs a few startup checks, and then calls functions to
264 # install under OS X or Linux, depending on the detected platform.
268 ThisDir
="$( cd -P "$
( dirname "${BASH_SOURCE[0]}" )" && pwd )"
269 RefindDir
="$ThisDir/refind"
270 ThisScript
="$ThisDir/`basename $0`"
272 if [[ `whoami` != "root" ]] ; then
273 echo "Not running as root; attempting to elevate privileges via sudo...."
275 if [[ $?
!= 0 ]] ; then
276 echo "This script must be run as root (or using sudo). Exiting!"
282 if [[ $OSName == 'Darwin' ]] ; then
284 elif [[ $OSName == 'Linux' ]] ; then
287 echo "Running on unknown OS; aborting!"
290 if [[ $Problems ]] ; then
293 echo "Installation has completed, but problems were detected. Review the output for"
294 echo "error messages and take corrective measures as necessary. You may need to"
295 echo "re-run this script or install manually before rEFInd will work."
299 echo "Installation has completed successfully."
303 if [[ $UnmountEsp ]] ; then