]>
code.delx.au - refind/blob - install.sh
3 # Linux/MacOS X script to install rEFInd
7 # ./install.sh [options]
10 # "--esp" to install to the ESP rather than to the system's root
11 # filesystem. This is the default on Linux
12 # "--usedefault {devicefile}" to install as default
13 # (/EFI/BOOT/BOOTX64.EFI and similar) to the specified
14 # device (/dev/sdd1 or whatever) without registering with
16 # "--drivers" to install drivers along with regular files
18 # The "esp" option is valid only on Mac OS X; it causes
19 # installation to the EFI System Partition (ESP) rather than
20 # to the current OS X boot partition. Under Linux, this script
21 # installs to the ESP by default.
23 # This program is copyright (c) 2012 by Roderick W. Smith
24 # It is released under the terms of the GNU GPL, version 3,
25 # a copy of which should be included in the file COPYING.txt.
29 # 0.5.0 -- Added --usedefault & --drivers options & changed "esp" option to "--esp"
30 # 0.4.5 -- Fixed check for rEFItBlesser in OS X
31 # 0.4.2 -- Added notice about BIOS-based OSes & made NVRAM changes in Linux smarter
32 # 0.4.1 -- Added check for rEFItBlesser in OS X
33 # 0.3.3.1 -- Fixed OS X 10.7 bug; also works as make target
34 # 0.3.2.1 -- Check for presence of source files; aborts if not present
35 # 0.3.2 -- Initial version
37 # Note: install.sh version numbers match those of the rEFInd package
38 # with which they first appeared.
41 EtcKeysDir
=/etc
/refind.d
/keys
45 # Functions used by both OS X and Linux....
51 while [[ $# -gt 0 ]]; do
53 --esp |
--ESP) InstallToEspOnMac
=1
55 --usedefault) TargetDir
=/EFI
/BOOT
59 --drivers) InstallDrivers
=1
61 * ) echo "Usage: $0 [--esp | --usedefault {device-file}] [--drivers]"
67 if [[ $InstallToEspOnMac == 1 && $TargetDir == '/EFI/BOOT' ]] ; then
68 echo "You may use --esp OR --usedefault, but not both! Aborting!"
74 # Abort if the rEFInd files can't be found.
75 # Also sets $ConfFile to point to the configuration file, and
76 # $IconsDir to point to the icons directory
78 # Note: This check is satisfied if EITHER the 32- or the 64-bit version
79 # is found, even on the wrong platform. This is because the platform
80 # hasn't yet been determined. This could obviously be improved, but it
81 # would mean restructuring lots more code....
82 if [[ ! -f $RefindDir/refind_ia32.efi
&& ! -f $RefindDir/refind_x64.efi
]] ; then
83 echo "The rEFInd binary file is missing! Aborting installation!"
87 if [[ -f $RefindDir/refind.conf-sample
]] ; then
88 ConfFile
=$RefindDir/refind.conf-sample
89 elif [[ -f $ThisDir/refind.conf-sample
]] ; then
90 ConfFile
=$ThisDir/refind.conf-sample
92 echo "The sample configuration file is missing! Aborting installation!"
96 if [[ -d $RefindDir/icons
]] ; then
97 IconsDir
=$RefindDir/icons
98 elif [[ -d $ThisDir/icons
]] ; then
99 IconsDir
=$ThisDir/icons
101 echo "The icons directory is missing! Aborting installation!"
105 # Copy the rEFInd files to the ESP or OS X root partition.
106 # Sets Problems=1 if any critical commands fail.
108 mkdir
-p $InstallDir/$TargetDir &> /dev
/null
109 if [[ $TargetDir == '/EFI/BOOT' ]] ; then
110 cp $RefindDir/refind_ia32.efi
$InstallDir/$TargetDir/bootia32.efi
2> /dev
/null
111 if [[ $?
!= 0 ]] ; then
112 echo "Note: IA32 (x86) binary not installed!"
114 cp $RefindDir/refind_x64.efi
$InstallDir/$TargetDir/bootx64.efi
2> /dev
/null
115 if [[ $?
!= 0 ]] ; then
118 if [[ $InstallDrivers == 1 ]] ; then
119 cp -r $RefindDir/drivers_
* $InstallDir/$TargetDir/
122 cp $ThisDir/refind.cer
$InstallDir/$TargetDir
123 cp $ThisDir/refind.crt
$InstallDir/$TargetDir
124 elif [[ $Platform == 'EFI32' ]] ; then
125 cp $RefindDir/refind_ia32.efi
$InstallDir/$TargetDir
126 if [[ $?
!= 0 ]] ; then
129 if [[ $InstallDrivers == 1 ]] ; then
130 mkdir
-p $InstallDir/$TargetDir/drivers_ia32
131 cp -r $RefindDir/drivers_ia32
/*_ia32.efi
$InstallDir/$TargetDir/drivers_ia32
/
133 Refind
="refind_ia32.efi"
134 elif [[ $Platform == 'EFI64' ]] ; then
135 cp $RefindDir/refind_x64.efi
$InstallDir/$TargetDir
136 if [[ $?
!= 0 ]] ; then
139 if [[ $InstallDrivers == 1 ]] ; then
140 mkdir
-p $InstallDir/$TargetDir/drivers_x64
141 cp -r $RefindDir/drivers_x64
/*_x64.efi
$InstallDir/$TargetDir/drivers_x64
/
143 Refind
="refind_x64.efi"
144 cp $ThisDir/refind.cer
$InstallDir/$TargetDir
145 cp $ThisDir/refind.crt
$InstallDir/$TargetDir
146 if [[ $SBModeInstall == 1 ]] ; then
147 echo "Storing copies of rEFInd Secure Boot public keys in $EtcKeysDir"
149 cp $ThisDir/refind.cer
$EtcKeysDir
150 cp $ThisDir/refind.crt
$EtcKeysDir
153 echo "Unknown platform! Aborting!"
156 echo "Copied rEFInd binary file $Refind"
158 if [[ -d $InstallDir/$TargetDir/icons
]] ; then
159 rm -rf $InstallDir/$TargetDir/icons-backup
&> /dev
/null
160 mv -f $InstallDir/$TargetDir/icons
$InstallDir/$TargetDir/icons-backup
161 echo "Notice: Backed up existing icons directory as icons-backup."
163 cp -r $IconsDir $InstallDir/$TargetDir
164 if [[ $?
!= 0 ]] ; then
167 if [[ -f $InstallDir/$TargetDir/refind.conf
]] ; then
168 echo "Existing refind.conf file found; copying sample file as refind.conf-sample"
169 echo "to avoid collision."
171 cp -f $ConfFile $InstallDir/$TargetDir
172 if [[ $?
!= 0 ]] ; then
176 echo "Copying sample configuration file as refind.conf; edit this file to configure"
179 cp -f $ConfFile $InstallDir/$TargetDir/refind.conf
180 if [[ $?
!= 0 ]] ; then
184 } # CopyRefindFiles()
186 # Mount the partition the user specified with the --usedefault option
187 MountDefaultTarget
() {
188 InstallDir
=/tmp
/refind_install
190 if [[ $OSName == 'Darwin' ]] ; then
191 mount
-t msdos
$TargetPart $InstallDir
192 elif [[ $OSName == 'Linux' ]] ; then
193 mount
-t vfat
$TargetPart $InstallDir
195 if [[ $?
!= 0 ]] ; then
196 echo "Couldn't mount $TargetPart ! Aborting!"
201 } # MountDefaultTarget()
204 # A series of OS X support functions....
207 # Mount the ESP at /Volumes/ESP or determine its current mount
209 # Sets InstallDir to the ESP mount point
210 # Sets UnmountEsp if we mounted it
212 # Identify the ESP. Note: This returns the FIRST ESP found;
213 # if the system has multiple disks, this could be wrong!
214 Temp
=`diskutil list | grep " EFI "`
215 Esp
=/dev
/`echo $Temp | cut -f 5 -d ' '`
216 # If the ESP is mounted, use its current mount point....
217 Temp
=`df | grep $Esp`
218 InstallDir
=`echo $Temp | cut -f 6 -d ' '`
219 if [[ $InstallDir == '' ]] ; then
220 mkdir
/Volumes
/ESP
&> /dev
/null
221 mount
-t msdos
$Esp /Volumes
/ESP
222 if [[ $?
!= 0 ]] ; then
223 echo "Unable to mount ESP! Aborting!\n"
227 InstallDir
="/Volumes/ESP"
231 # Control the OS X installation.
232 # Sets Problems=1 if problems found during the installation.
234 echo "Installing rEFInd on OS X...."
235 if [[ $TargetDir == "/EFI/BOOT" ]] ; then
237 elif [[ $InstallToEspOnMac == "1" ]] ; then
242 echo "Installing rEFInd to the partition mounted at '$InstallDir'"
243 Platform
=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
245 if [[ $InstallToEspOnMac == "1" ]] ; then
246 bless
--mount $InstallDir --setBoot --file $InstallDir/$TargetDir/$Refind
247 elif [[ $TargetDir != "/EFI/BOOT" ]] ; then
248 bless
--setBoot --folder $InstallDir/$TargetDir --file $InstallDir/$TargetDir/$Refind
250 if [[ $?
!= 0 ]] ; then
253 if [[ -f /Library
/StartupItems
/rEFItBlesser ||
-d /Library
/StartupItems
/rEFItBlesser
]] ; then
255 echo "/Library/StartupItems/rEFItBlesser found!"
256 echo "This program is part of rEFIt, and will cause rEFInd to fail to work after"
257 echo -n "its first boot. Do you want to remove rEFItBlesser (Y/N)? "
259 if [[ $YesNo == "Y" ||
$YesNo == "y" ]] ; then
260 echo "Deleting /Library/StartupItems/rEFItBlesser..."
261 rm -r /Library
/StartupItems
/rEFItBlesser
263 echo "Not deleting rEFItBlesser."
267 echo "WARNING: If you have an Advanced Format disk, *DO NOT* attempt to check the"
268 echo "bless status with 'bless --info', since this is known to cause disk corruption"
269 echo "on some systems!!"
275 # Now a series of Linux support functions....
278 # Check for evidence that we're running in Secure Boot mode. If so, warn the
279 # user and confirm installation.
280 # TODO: Perform a reasonable Secure Boot installation.
282 VarFile
=`ls -ld /sys/firmware/efi/vars/SecureBoot* 2> /dev/null`
283 if [[ -n $VarFile && $TargetDir != '/EFI/BOOT' ]] ; then
285 echo "CAUTION: The computer seems to have been booted with Secure Boot active."
286 echo "Although rEFInd, when installed in conjunction with the shim boot loader, can"
287 echo "work on a Secure Boot computer, this installation script doesn't yet support"
288 echo "direct installation in a way that will work on such a computer. You may"
289 echo "proceed with installation with this script, but if you intend to boot with"
290 echo "Secure Boot active, you must then reconfigure your boot programs to add shim"
291 echo "to the process. Alternatively, you may terminate this script and do a manual"
292 echo "installation, as described at http://www.rodsbooks.com/refind/secureboot.html."
294 echo -n "Do you want to proceed with installation (Y/N)? "
296 if [[ $ContYN == "Y" ||
$ContYN == "y" ]] ; then
297 echo "OK; continuing with the installation..."
305 # Identifies the ESP's location (/boot or /boot/efi); aborts if
306 # the ESP isn't mounted at either location.
307 # Sets InstallDir to the ESP mount point.
309 EspLine
=`df /boot/efi | grep boot`
310 InstallDir
=`echo $EspLine | cut -d " " -f 6`
311 EspFilesystem
=`grep $InstallDir /etc/mtab | cut -d " " -f 3`
312 if [[ $EspFilesystem != 'vfat' ]] ; then
313 echo "/boot/efi doesn't seem to be on a VFAT filesystem. The ESP must be mounted at"
314 echo "/boot or /boot/efi and it must be VFAT! Aborting!"
317 echo "ESP was found at $InstallDir using $EspFilesystem"
320 # Uses efibootmgr to add an entry for rEFInd to the EFI's NVRAM.
321 # If this fails, sets Problems=1
324 Efibootmgr
=`which efibootmgr 2> /dev/null`
325 if [[ $Efibootmgr ]] ; then
326 modprobe efivars
&> /dev
/null
327 InstallDisk
=`grep $InstallDir /etc/mtab | cut -d " " -f 1 | cut -c 1-8`
328 PartNum
=`grep $InstallDir /etc/mtab | cut -d " " -f 1 | cut -c 9-10`
329 EntryFilename
=$TargetDir/$Refind
330 EfiEntryFilename
=`echo ${EntryFilename//\//\\\}`
331 EfiEntryFilename2
=`echo ${EfiEntryFilename} | sed s/\\\\\\\\/\\\\\\\\\\\\\\\\/g`
332 ExistingEntry
=`$Efibootmgr -v | grep $EfiEntryFilename2`
333 if [[ $ExistingEntry ]] ; then
334 ExistingEntryBootNum
=`echo $ExistingEntry | cut -c 5-8`
335 FirstBoot
=`$Efibootmgr | grep BootOrder | cut -c 12-15`
336 if [[ $ExistingEntryBootNum != $FirstBoot ]] ; then
337 echo "An existing rEFInd boot entry exists, but isn't set as the default boot"
338 echo "manager. The boot order is being adjusted to make rEFInd the default boot"
339 echo "manager. If this is NOT what you want, you should use efibootmgr to"
340 echo "manually adjust your EFI's boot order."
341 $Efibootmgr -b $ExistingEntryBootNum -B &> /dev
/null
347 if [[ $InstallIt == "1" ]] ; then
348 echo "Installing it!"
349 $Efibootmgr -c -l $EfiEntryFilename -L rEFInd
-d $InstallDisk -p $PartNum &> /dev
/null
350 if [[ $?
!= 0 ]] ; then
359 if [[ $EfibootmgrProblems ]] ; then
361 echo "ALERT: There were problems running the efibootmgr program! You may need to"
362 echo "rename the $Refind binary to the default name (EFI/boot/bootx64.efi"
363 echo "on x86-64 systems or EFI/boot/bootia32.efi on x86 systems) to have it run!"
368 # Controls rEFInd installation under Linux.
369 # Sets Problems=1 if something goes wrong.
371 echo "Installing rEFInd on Linux...."
372 if [[ $TargetDir == "/EFI/BOOT" ]] ; then
378 if [[ $CpuType == 'x86_64' ]] ; then
380 elif [[ $CpuType == 'i386' ||
$CpuType == 'i486' ||
$CpuType == 'i586' ||
$CpuType == 'i686' ]] ; then
383 echo "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based"
384 echo "computers are VERY RARE. If you've installed a 32-bit version of Linux"
385 echo "on a 64-bit computer, you should manually install the 64-bit version of"
386 echo "rEFInd. If you're installing on a Mac, you should do so from OS X. If"
387 echo "you're positive you want to continue with this installation, answer 'Y'"
388 echo "to the following question..."
390 echo -n "Are you sure you want to continue (Y/N)? "
392 if [[ $ContYN == "Y" ||
$ContYN == "y" ]] ; then
393 echo "OK; continuing with the installation..."
398 echo "Unknown CPU type '$CpuType'; aborting!"
403 if [[ $TargetDir != "/EFI/BOOT" ]] ; then
409 # The main part of the script. Sets a few environment variables,
410 # performs a few startup checks, and then calls functions to
411 # install under OS X or Linux, depending on the detected platform.
416 ThisDir
="$( cd -P "$
( dirname "${BASH_SOURCE[0]}" )" && pwd )"
417 RefindDir
="$ThisDir/refind"
418 ThisScript
="$ThisDir/`basename $0`"
420 if [[ `whoami` != "root" ]] ; then
421 echo "Not running as root; attempting to elevate privileges via sudo...."
422 sudo
$ThisScript $1 $2 $3
423 if [[ $?
!= 0 ]] ; then
424 echo "This script must be run as root (or using sudo). Exiting!"
430 if [[ $OSName == 'Darwin' ]] ; then
432 elif [[ $OSName == 'Linux' ]] ; then
435 echo "Running on unknown OS; aborting!"
438 if [[ $Problems ]] ; then
441 echo "Installation has completed, but problems were detected. Review the output for"
442 echo "error messages and take corrective measures as necessary. You may need to"
443 echo "re-run this script or install manually before rEFInd will work."
447 echo "Installation has completed successfully."
451 if [[ $UnmountEsp ]] ; then
452 echo "Unmounting install dir"
456 if [[ $InstallDir == /tmp
/refind_install
]] ; then