3 # Linux/MacOS X script to install rEFInd
7 # ./refind-install [options]
10 # "--notesp" to install to the OS X root filesystem rather than to the ESP.
11 # This option may not be used under Linux.
12 # "--usedefault {devicefile}" to install as default
13 # (/EFI/BOOT/BOOTX64.EFI and similar) to the specified device
14 # (/dev/sdd1 or whatever) without registering with the NVRAM.
15 # "--ownhfs {devicefile}" to install to an HFS+ volume that's NOT currently
16 # an OS X boot volume.
17 # "--root {dir}" to specify installation using the specified directory
18 # as the system's root
19 # "--alldrivers" to install all drivers along with regular files
20 # "--nodrivers" to suppress driver installation (default in Linux is
21 # driver used on /boot; --nodrivers is OS X default)
22 # "--shim {shimfile}" to install a shim.efi file for Secure Boot
23 # "--preloader" is synonymous with "--shim"
24 # "--localkeys" to re-sign x86-64 binaries with a locally-generated key
25 # "--keepname" to keep refind_x64.efi name as such even when using shim
26 # "--yes" to assume a "yes" response to all prompts
28 # The "esp" option is valid only on Mac OS X; it causes
29 # installation to the EFI System Partition (ESP) rather than
30 # to the current OS X boot partition. Under Linux, this script
31 # installs to the ESP by default.
33 # This program is copyright (c) 2012-2015 by Roderick W. Smith
35 # This program is licensed under the terms of the GNU GPL, version 3,
36 # or (at your option) any later version.
37 # You should have received a copy of the GNU General Public License
38 # along with this program. If not, see <http://www.gnu.org/licenses/>.
42 # 0.10.1 -- Improve extraction of default kernel options from /proc/cmdline.
43 # Add support for AMD64 (aka AARCH64, aa64) platform. Added
44 # warning when --alldrivers used without --usedefault.
45 # 0.10.0 -- Enable running under OS X's recovery system & add warning about
46 # SIP & brief instructions on how to deal with it if SIP is
47 # detected to be enabled. Also change way refind_linux.conf default
48 # options are found; use /proc/cmdline as base.
49 # 0.9.2 -- Added --keepname option.
50 # 0.8.7 -- Better detection of Secure Boot mode & fixed errors when copying
51 # Shim & MokManager files over themselves; fixed bug that caused
52 # inappropriate installation to EFI/BOOT/bootx64.efi
53 # 0.8.6 -- Fixed bugs that caused misidentification of ESP on disks with
54 # partition numbers over 10 on OS X and misidentification of mount
55 # point if already-mounted ESP had space in path.
56 # 0.8.5 -- Refinement/cleanup of new OS X ESP-as-default policy
57 # 0.8.4 -- OS X default changed to install to ESP under /EFI/BOOT
58 # 0.7.9 -- Fixed bug that caused errors if dmraid utility not installed
59 # 0.7.7 -- Fixed bug that created mangled refind_linux.conf file; added ability
60 # to locate and mount ESP on Linux, if it's not mounted
61 # 0.7.6 -- Added --ownhfs {device-filename} option
62 # 0.7.5 -- Fixed bug when installing to ESP on recent versions of OS X
63 # 0.7.2 -- Fixed code that could be confused by use of autofs to mount the ESP
64 # 0.7.0 -- Added support for the new Btrfs driver
65 # 0.6.12 -- Added support for PreLoader as well as for shim
66 # 0.6.11 -- Improvements in script's ability to handle directories with spaces
68 # 0.6.9 -- Install gptsync on Macs
69 # 0.6.8 -- Bug fix: ESP scan now uses "uniq".
70 # 0.6.6 -- Bug fix: Upgrade drivers when installed to EFI/BOOT. Also enable
71 # copying shim.efi and MokManager.efi over themselves.
72 # 0.6.4 -- Copies ext2 driver rather than ext4 driver for ext2/3fs
73 # 0.6.3 -- Support for detecting rEFInd in EFI/BOOT and EFI/Microsoft/Boot
74 # directories & for installing to EFI/BOOT in BIOS mode
75 # 0.6.2-1 -- Added --yes option & tweaked key-copying for use with RPM install script
76 # 0.6.1 -- Added --root option; minor bug fixes
77 # 0.6.0 -- Changed --drivers to --alldrivers and added --nodrivers option;
78 # changed default driver installation behavior in Linux to install
79 # the driver needed to read /boot (if available)
80 # 0.5.1.2 -- Fixed bug that caused failure to generate refind_linux.conf file
81 # 0.5.1.1 -- Fixed bug that caused script failure under OS X
82 # 0.5.1 -- Added --shim & --localkeys options & create sample refind_linux.conf
84 # 0.5.0 -- Added --usedefault & --drivers options & changed "esp" option to "--esp"
85 # 0.4.5 -- Fixed check for rEFItBlesser in OS X
86 # 0.4.2 -- Added notice about BIOS-based OSes & made NVRAM changes in Linux smarter
87 # 0.4.1 -- Added check for rEFItBlesser in OS X
88 # 0.3.3.1 -- Fixed OS X 10.7 bug; also works as make target
89 # 0.3.2.1 -- Check for presence of source files; aborts if not present
90 # 0.3.2 -- Initial version
92 # Note: install.sh version numbers match those of the rEFInd package
93 # with which they first appeared.
97 LocalKeysBase
="refind_local"
102 TargetX64
="refind_x64.efi"
103 TargetIA32
="refind_ia32.efi"
109 # Functions used by both OS X and Linux....
114 # Install the driver required to read Linux /boot, if it's available
115 # Note: Under OS X, this will be installed only if a Linux partition
116 # is detected, in which case the ext4fs driver will be installed.
117 InstallDrivers
="boot"
118 while [[ $# -gt 0 ]]; do
120 --notesp) InstallToEspOnMac
=0
125 TargetDir
=/System
/Library
/CoreServices
128 --usedefault) TargetDir
=/EFI
/BOOT
130 TargetX64
="bootx64.efi"
131 TargetIA32
="bootia32.efi"
138 --localkeys) LocalKeys
=1
140 --shim |
--preloader) ShimSource
="$2"
141 ShimType
=`basename $ShimSource`
144 --keepname) KeepName
=1
146 --drivers |
--alldrivers) InstallDrivers
="all"
148 --nodrivers) InstallDrivers
="none"
152 * ) echo "Usage: $0 [--notesp | --usedefault {device-file} | --root {dir} |"
153 echo " --ownhfs {device-file} ] [--keepname]"
154 echo " [--nodrivers | --alldrivers]"
155 echo " [--localkeys] [--keepname] [--yes]"
160 if [[ "$InstallToEspOnMac" == 0 && "$RootDir" == '/' && "$TargetDir" == '/EFI/BOOT' ]] ; then
161 echo "You may use --notesp OR --usedefault, but not both! Aborting!"
164 if [[ "$RootDir" != '/' && "$TargetDir" == '/EFI/BOOT' ]] ; then
165 echo "You may use --root OR --usedefault, but not both! Aborting!"
168 if [[ "$TargetDir" != '/System/Library/CoreServices' && "$OwnHfs" == '1' ]] ; then
169 echo "If you use --ownhfs, you may NOT use --usedefault! Aborting!"
172 if [[ "$KeepName" == 1 && "$ShimSource" == "none" ]] ; then
173 echo "The --keepname option is meaningful only in conjunction with --shim"
174 echo "or --preloader! Aborting!"
177 if [[ "$KeepName" == 1 && "$OSTYPE" != "linux" && "$OSTYPE" != "linux-gnu" ]] ; then
178 echo "The --keepname option is valid only under Linux! Aborting!"
181 if [[ "$KeepName" == 1 && "$TargetDir" == "/EFI/BOOT" ]] ; then
182 echo "The --keepname option is incompatible with --usedefault! Aborting!"
185 if [[ "$InstallDrivers" == "all" && "$TargetDir" != "/EFI/BOOT" ]] ; then
186 echo "The --alldrivers option is meant for creating USB flash drives with (near-)"
187 echo "universal boot support. Using it on a hard disk partition runs the risk of"
188 echo "creating serious problems, up to and including rendering your computer"
189 echo -n "unbootable. Are you SURE you want to proceed (Y/N)? "
191 if [[ "$YesNo" != "Y" && "$YesNo" != "y" ]] ; then
192 echo "Aborting installation!"
196 RLConfFile
="$RootDir/boot/refind_linux.conf"
197 EtcKeysDir
="$RootDir/etc/refind.d/keys"
200 # Get a yes/no response from the user and place it in the YesNo variable.
201 # If the AlwaysYes variable is set to 1, skip the user input and set "Y"
202 # in the YesNo variable.
204 if [[ $AlwaysYes == 1 ]] ; then
212 # Determine what CPU type and EFI bit depth we're using.
213 # Sets Platform global variable to lowercase EFI platform code (currently
214 # "x64", "ia32", or "aa64") -- the same code used in filenames.
215 DeterminePlatform
() {
219 CpuType
=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
220 if [[ "$CpuType" == EFI32
]] ; then
237 # If we're in EFI mode, do some sanity checks, and alert the user or even
238 # abort. Not in BIOS mode, though, since that could be used on an emergency
239 # disc to try to recover a troubled Linux installation.
240 if [[ -d /sys
/firmware
/efi
]] ; then
241 if [[ "$ShimSource" != "none" && "$TargetDir" != "/BOOT/EFI" ]] ; then
243 echo "CAUTION: shim does not currently supports 32-bit systems, so you should not"
244 echo "use the --shim option to install on such systems. Aborting!"
249 echo "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based"
250 echo "computers are VERY RARE. If you've installed a 32-bit version of Linux"
251 echo "on a 64-bit computer, you should manually install the 64-bit version of"
252 echo "rEFInd. If you're positive you want to continue with this installation,"
253 echo "answer 'Y' to the following question..."
255 echo -n "Are you sure you want to continue (Y/N)? "
257 if [[ $YesNo == "Y" ||
$YesNo == "y" ]] ; then
258 echo "OK; continuing with the installation..."
265 echo "Unknown CPU type '$CpuType'; aborting!"
268 esac # case "$CpuType"....
271 echo "Unknown OS; aborting!"
274 esac # case "$OSTYPE"....
275 } # DeterminePlatform()
277 # Abort if the rEFInd files can't be found.
278 # Also sets $ConfFile to point to the configuration file,
279 # $IconsDir to point to the icons directory,
280 # $ShimSource to the source of the shim.efi file (if necessary),
281 # $ThisDir to point to the directory in which this script resides,
282 # and $RefindDir to point to where the rEFInd binaries live
284 # Note: $ThisDir points to real (not symlinked) script home on Linux,
285 # enabling creating a symlink in /usr/sbin (or wherever); but on OS X,
286 # "readlink" doesn't do the same thing as under Linux, so the script
287 # must not be a symlink under OS X.
290 ThisDir
="$( cd -P "${BASH_SOURCE%/*}" && pwd )"
293 ThisDir
="$(dirname "$
(readlink
-f "$0")")"
296 RefindDir
="$ThisDir/refind"
298 if [[ ! -f "$RefindDir/refind_$Platform.efi" ]] ; then
299 echo "The rEFInd binary file is missing! Aborting installation!"
303 if [[ -f "$RefindDir/refind.conf-sample" ]] ; then
304 ConfFile
="$RefindDir/refind.conf-sample"
305 elif [[ -f "$ThisDir/refind.conf-sample" ]] ; then
306 ConfFile
="$ThisDir/refind.conf-sample"
308 echo "The sample configuration file is missing! Aborting installation!"
312 if [[ -d "$RefindDir/icons" ]] ; then
313 IconsDir
="$RefindDir/icons"
314 elif [[ -d "$ThisDir/icons" ]] ; then
315 IconsDir
="$ThisDir/icons"
317 echo "The icons directory is missing! Aborting installation!"
321 echo "ShimSource is $ShimSource"
322 if [[ "$ShimSource" != "none" ]] ; then
323 if [[ -f "$ShimSource" ]] ; then
324 if [[ $ShimType == "shimx64.efi" ||
$ShimType == "shim.efi" ]] ; then
325 TargetX64
="grubx64.efi"
326 TargetAARCH64
="grubaa64.efi"
327 MokManagerSource
=`dirname "$ShimSource"`/MokManager.efi
328 elif [[ $ShimType == "preloader.efi" ||
$ShimType == "PreLoader.efi" ]] ; then
329 TargetX64
="loader.efi"
330 MokManagerSource
=`dirname "$ShimSource"`/HashTool.efi
332 echo "Unknown shim/PreBootloader filename: $ShimType!"
333 echo "Known filenames are shimx64.efi, shim.efi, and PreLoader.efi. Aborting!"
337 echo "The specified shim/PreBootloader file, $ShimSource, doesn't exist!"
338 echo "Aborting installation!"
344 # Helper for CopyRefindFiles; copies shim files (including MokManager, if it's
345 # available) to target.
347 local inode1
=`ls -i "$ShimSource" 2> /dev/null | cut -f 1 -d " "`
348 local inode2
=`ls -i "$InstallDir/$TargetDir/$TargetShim" 2> /dev/null | cut -f 1 -d " "`
349 if [[ $inode1 != $inode2 ]] ; then
350 cp -fb "$ShimSource" "$InstallDir/$TargetDir/$TargetShim"
351 if [[ $?
!= 0 ]] ; then
355 inode1
=`ls -i "$MokManagerSource" 2> /dev/null | cut -f 1 -d " "`
356 local TargetMMName
=`basename $MokManagerSource`
357 inode2
=`ls -i "$InstallDir/$TargetDir/$TargetMMName" 2> /dev/null | cut -f 1 -d " "`
358 if [[ $inode1 != $inode2 ]] ; then
359 if [[ -f "$MokManagerSource" ]] ; then
360 cp -fb "$MokManagerSource" "$InstallDir/$TargetDir/"
362 if [[ $?
!= 0 ]] ; then
368 # Copy the public keys to the installation medium
370 if [[ $LocalKeys == 1 ]] ; then
371 mkdir
-p "$InstallDir/$TargetDir/keys/"
372 cp "$EtcKeysDir/$LocalKeysBase.cer" "$InstallDir/$TargetDir/keys/"
373 cp "$EtcKeysDir/$LocalKeysBase.crt" "$InstallDir/$TargetDir/keys/"
377 # Set varaibles for installation in EFI/BOOT directory
379 TargetDir
="/EFI/BOOT"
380 if [[ $ShimSource == "none" ]] ; then
381 TargetX64
="bootx64.efi"
382 TargetIA32
="bootia32.efi"
383 TargetAARCH64
="bootaa64.efi"
385 if [[ $ShimType == "shim.efi" ||
$ShimType == "shimx64.efi" ||
$ShimType = "shimaa64.efi" ]] ; then
386 TargetX64
="grubx64.efi"
387 TargetAARCH64
="grubaa64.efi"
388 elif [[ $ShimType == "preloader.efi" ||
$ShimType == "PreLoader.efi" ]] ; then
389 TargetX64
="loader.efi"
391 echo "Unknown shim/PreBootloader type: $ShimType"
395 TargetIA32
="bootia32.efi"
396 TargetShim
="boot$Platform.efi"
398 if [[ $KeepName == 1 ]] ; then
399 echo "Installation is to /EFI/BOOT, which is incompatible with --keepname! Aborting!"
404 # Set variables for installation in EFI/Microsoft/Boot directory
406 TargetDir
="/EFI/Microsoft/Boot"
407 if [[ $ShimSource == "none" ]] ; then
408 TargetX64
="bootmgfw.efi"
409 TargetIA32
="bootmgfw.efi"
410 TargetAARCH64
="bootmgfw.efi"
412 if [[ $ShimType == "shim.efi" ||
$ShimType == "shimx64.efi" ||
$ShimType == "shimaa64.efi" ]] ; then
413 TargetX64
="grubx64.efi"
414 TargetAARCH64
="grubaa64.efi"
415 elif [[ $ShimType == "preloader.efi" ||
$ShimType == "PreLoader.efi" ]] ; then
416 TargetX64
="loader.efi"
418 echo "Unknown shim/PreBootloader type: $ShimType"
422 TargetShim
="bootmgfw.efi"
424 if [[ $KeepName == 1 ]] ; then
425 echo "Installation is to /EFI/Microsoft/Boot, which is incompatible with --keepname!"
429 } # SetVarsForMsBoot()
431 # TargetDir defaults to /EFI/refind; however, this function adjusts it as follows:
432 # - If an existing refind.conf is available in /EFI/BOOT or /EFI/Microsoft/Boot,
433 # install to that directory under the suitable name; but DO NOT do this if
434 # refind.conf is also in /EFI/refind.
435 # - If booted in BIOS mode and the ESP lacks any other EFI files, install to
437 # - If booted in BIOS mode and there's no refind.conf file and there is a
438 # /EFI/Microsoft/Boot/bootmgfw.efi file, move it down one level and
439 # install under that name, "hijacking" the Windows boot loader filename
440 DetermineTargetDir
() {
443 if [[ -f $InstallDir/EFI
/BOOT
/refind.conf
&& ! -f $InstallDir/EFI
/refind
/refind.conf
]] ; then
447 if [[ -f $InstallDir/EFI
/Microsoft
/Boot
/refind.conf
&& ! -f $InstallDir/EFI
/refind
/refind.conf
]] ; then
451 if [[ -f $InstallDir/EFI
/refind
/refind.conf
]] ; then
452 TargetDir
="/EFI/refind"
453 if [[ $ShimSource == "none" ||
$KeepName == 1 ]] ; then
454 TargetX64
="refind_x64.efi"
455 TargetIA32
="refind_ia32.efi"
456 TargetAARCH64
="refind_aa64.efi"
460 if [[ $Upgrade == 1 ]] ; then
461 echo "Found rEFInd installation in $InstallDir$TargetDir; upgrading it."
464 if [[ ! -d /sys
/firmware
/efi
&& ! $OSTYPE == darwin
* && $Upgrade == 0 ]] ; then # BIOS-mode
465 FoundEfiFiles
=`find "$InstallDir/EFI/BOOT" -name "*.efi" 2> /dev/null`
466 FoundConfFiles
=`find "$InstallDir" -name "refind\.conf" 2> /dev/null`
467 if [[ ! -n "$FoundConfFiles" && -f "$InstallDir/EFI/Microsoft/Boot/bootmgfw.efi" ]] ; then
468 mv -n "$InstallDir/EFI/Microsoft/Boot/bootmgfw.efi" "$InstallDir/EFI/Microsoft" &> /dev
/null
470 echo "Running in BIOS mode with a suspected Windows installation; moving boot loader"
471 echo "files so as to install to $InstallDir$TargetDir."
472 elif [[ ! -n "$FoundEfiFiles" ]] ; then # In BIOS mode and no default loader; install as default loader
474 echo "Running in BIOS mode with no existing default boot loader; installing to"
475 echo $InstallDir$TargetDir
477 echo "Running in BIOS mode with an existing default boot loader; backing it up and"
478 echo "installing rEFInd in its place."
479 if [[ -d "$InstallDir/EFI/BOOT-rEFIndBackup" ]] ; then
481 echo "Caution: An existing backup of a default boot loader exists! If the current"
482 echo "default boot loader and the backup are different boot loaders, the current"
483 echo "one will become inaccessible."
485 echo -n "Do you want to proceed with installation (Y/N)? "
487 if [[ $YesNo == "Y" ||
$YesNo == "y" ]] ; then
488 echo "OK; continuing with the installation..."
493 mv -n "$InstallDir/EFI/BOOT" "$InstallDir/EFI/BOOT-rEFIndBackup"
497 } # DetermineTargetDir()
499 # Determine (or guess) the filesystem used on the Linux /boot filesystem.
500 # Store the result in the BootFS global variable.
505 if command -v blkid
&>/dev
/null
; then
506 BootPart
=`df $RootDir/boot | grep dev | cut -f 1 -d " "`
507 BootFS
=`blkid -o export $BootPart 2> /dev/null | grep TYPE= | cut -f 2 -d =`
511 # 0FC63DAF-8483-4772-8E79-3D69D8477DE4 = Linux filesystem
512 # BC13C2FF-59E6-4262-A352-B275FD6F7172 = Freedesktop $boot partition
513 # 933AC7E1-2EB4-4F13-B844-0E14E2AEF915 = Freedesktop Linux /home
514 # E6D6D379-F507-44C2-A23C-238F2A3DF928 = Linux LVM
515 # A19D880F-05FC-4D3B-A006-743F0F84911E = Linux RAID
516 # 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F = Linux swap
517 Temp
=$
(diskutil list |
grep -i '0FC63DAF-8483-4772-8E79-3D69D8477DE4\|BC13C2FF-59E6-4262-A352-B275FD6F7172\|933AC7E1-2EB4-4F13-B844-0E14E2AEF915\|E6D6D379-F507-44C2-A23C-238F2A3DF928\|A19D880F-05FC-4D3B-A006-743F0F84911E\|0657FD6D-A4AB-43C4-84E5-0933C84B4F4F\|Linux')
519 if [[ -n $Temp ]] ; then
520 echo "Found suspected Linux partition(s); installing ext4fs driver."
527 # Copy drivers from $RefindDir/drivers_$1 to $InstallDir/$TargetDir/drivers_$1,
528 # honoring the $InstallDrivers condition. Must be passed a suitable
529 # architecture code (ia32 or x64).
531 if [[ $InstallDrivers == "all" ]] ; then
532 mkdir
-p "$InstallDir/$TargetDir/drivers_$1"
533 cp "$ThisDir"/drivers_
$1/*_
$1.efi
"$InstallDir/$TargetDir/drivers_$1/" 2> /dev
/null
534 cp "$RefindDir"/drivers_
$1/*_
$1.efi
"$InstallDir/$TargetDir/drivers_$1/" 2> /dev
/null
535 elif [[ "$InstallDrivers" == "boot" ]] ; then
539 ext2 | ext3
) DriverType
="ext2"
540 # Could use ext4, but that can create unwanted entries from symbolic
541 # links in / to /boot/vmlinuz if a separate /boot partition is used.
543 ext4
) DriverType
="ext4"
545 reiserfs
) DriverType
="reiserfs"
547 btrfs
) DriverType
="btrfs"
549 hfsplus
) DriverType
="hfs"
551 ntfs
) DriverType
="ntfs"
555 if [[ -n $BootFS ]] ; then
556 echo "Installing driver for $BootFS (${DriverType}_$1.efi)"
557 mkdir
-p "$InstallDir/$TargetDir/drivers_$1"
558 cp "$ThisDir/drivers_$1/${DriverType}_$1.efi" "$InstallDir/$TargetDir/drivers_$1/" 2> /dev
/null
559 cp "$RefindDir/drivers_$1/${DriverType}_$1.efi" "$InstallDir/$TargetDir/drivers_$1"/ 2> /dev
/null
564 # Copy tools (currently only gptsync, and that only on Macs) to the EFI/tools
565 # directory on the ESP. Must be passed a suitable architecture code (ia32
568 mkdir
-p "$InstallDir/EFI/tools"
569 if [[ $OSTYPE == darwin
* ]] ; then
570 cp -f "$RefindDir/tools_$1/gptsync_$1.efi" "$InstallDir/EFI/tools/"
571 if [[ -f "$InstallDir/EFI/tools/gptsync.efi" ]] ; then
572 mv "$InstallDir/EFI/tools/gptsync.efi" "$InstallDir/EFI/tools/gptsync.efi-disabled"
573 echo "Found old gptsync.efi; disabling it by renaming it to gptsync.efi-disabled"
578 # Copy the rEFInd files to the ESP or OS X root partition.
579 # Sets Problems=1 if any critical commands fail.
581 mkdir
-p "$InstallDir/$TargetDir"
582 if [[ "$TargetDir" == '/EFI/BOOT' ]] ; then
583 cp "$RefindDir/refind_ia32.efi" "$InstallDir/$TargetDir/$TargetIA32" 2> /dev
/null
584 if [[ $?
!= 0 ]] ; then
585 echo "Note: IA32 (x86) binary not installed!"
587 cp "$RefindDir/refind_x64.efi" "$InstallDir/$TargetDir/$TargetX64" 2> /dev
/null
588 if [[ $?
!= 0 ]] ; then
591 cp "$RefindDir/refind_aa64.efi" "$InstallDir/$TargetDir/$TargetAARCH64" 2> /dev
/null
592 if [[ $?
!= 0 && $Platform == "aa64" ]] ; then
595 if [[ "$ShimSource" != "none" ]] ; then
596 TargetShim
="bootx64.efi"
599 if [[ $InstallDrivers == "all" ]] ; then
600 cp -r "$RefindDir"/drivers_
* "$InstallDir/$TargetDir/" 2> /dev
/null
601 cp -r "$ThisDir"/drivers_
* "$InstallDir/$TargetDir/" 2> /dev
/null
602 elif [[ $Upgrade == 1 ||
$InstallToEspOnMac == 1 ]] ; then
603 CopyDrivers
"$Platform"
604 CopyTools
"$Platform"
606 Refind
="boot$Platform.efi"
608 elif [[ $Platform == 'x64' ||
$TargetDir == "/EFI/Microsoft/Boot" ]] ; then
609 cp "$RefindDir/refind_x64.efi" "$InstallDir/$TargetDir/$TargetX64"
610 if [[ $?
!= 0 ]] ; then
615 Refind
="refind_x64.efi"
617 if [[ "$ShimSource" != "none" ]] ; then
618 if [[ "$TargetShim" == "default" ]] ; then
619 TargetShim
=`basename "$ShimSource"`
623 if [[ $LocalKeys == 0 ]] ; then
624 echo "Storing copies of rEFInd Secure Boot public keys in $EtcKeysDir"
625 mkdir
-p "$EtcKeysDir"
626 cp "$ThisDir/keys/refind.cer" "$EtcKeysDir" 2> /dev
/null
627 cp "$ThisDir/keys/refind.crt" "$EtcKeysDir" 2> /dev
/null
630 if [[ "$TargetDir" == '/System/Library/CoreServices' ]] ; then
631 SetupMacHfs
$TargetX64
633 elif [[ $Platform == 'ia32' ||
$Platform == 'aa64' ]] ; then
634 if [[ $Platform == 'ia32' ]] ; then
635 cp "$RefindDir/refind_ia32.efi" "$InstallDir/$TargetDir/$TargetIA32"
636 if [[ $?
!= 0 ]] ; then
640 cp "$RefindDir/refind_aa64.efi" "$InstallDir/$TargetDir/$TargetAARCH64"
641 if [[ $?
!= 0 ]] ; then
645 CopyDrivers
$Platform
647 Refind
="refind_$Platform.efi"
648 if [[ "$TargetDir" == '/System/Library/CoreServices' ]] ; then
649 SetupMacHfs
$TargetIA32
652 echo "Unknown platform! Aborting!"
655 echo "Copied rEFInd binary files"
657 if [[ -d "$InstallDir/$TargetDir/icons" ]] ; then
658 rm -rf "$InstallDir/$TargetDir/icons-backup" &> /dev
/null
659 mv -f "$InstallDir/$TargetDir/icons" "$InstallDir/$TargetDir/icons-backup"
660 echo "Notice: Backed up existing icons directory as icons-backup."
662 cp -r "$IconsDir" "$InstallDir/$TargetDir"
663 if [[ $?
!= 0 ]] ; then
666 mkdir
-p "$InstallDir/$TargetDir/keys"
667 cp -rf "$ThisDir"/keys
/*.
[cd]er
"$InstallDir/$TargetDir/keys/" 2> /dev
/null
668 cp -rf "$EtcKeysDir"/*.
[cd]er
"$InstallDir/$TargetDir/keys/" 2> /dev
/null
669 if [[ -f "$InstallDir/$TargetDir/refind.conf" ]] ; then
670 echo "Existing refind.conf file found; copying sample file as refind.conf-sample"
671 echo "to avoid overwriting your customizations."
673 cp -f "$ConfFile" "$InstallDir/$TargetDir"
674 if [[ $?
!= 0 ]] ; then
678 echo "Copying sample configuration file as refind.conf; edit this file to configure"
681 cp -f "$ConfFile" "$InstallDir/$TargetDir/refind.conf"
682 if [[ $?
!= 0 ]] ; then
686 if [[ $DeleteRefindDir == 1 ]] ; then
687 echo "Deleting the temporary directory $RefindDir"
690 } # CopyRefindFiles()
692 # Mount the partition the user specified with the --usedefault or --ownhfs option
693 MountDefaultTarget
() {
694 InstallDir
=/tmp
/refind_install
695 mkdir
-p "$InstallDir"
697 if [[ $OSTYPE == darwin
* ]] ; then
698 if [[ $OwnHfs == '1' ]] ; then
699 Temp
=`diskutil info "$TargetPart" | grep "Mount Point"`
700 InstallDir
=`echo $Temp | cut -f 3-30 -d ' '`
701 if [[ $InstallDir == '' ]] ; then
702 InstallDir
=/tmp
/refind_install
703 mount
-t hfs
"$TargetPart" "$InstallDir"
708 mount
-t msdos
"$TargetPart" "$InstallDir"
710 elif [[ $OSTYPE == linux
* ]] ; then
711 mount
-t vfat
"$TargetPart" "$InstallDir"
713 if [[ $?
!= 0 ]] ; then
714 echo "Couldn't mount $TargetPart ! Aborting!"
718 } # MountDefaultTarget()
721 # A series of OS X support functions....
724 # Mount the ESP at /Volumes/ESP or determine its current mount
726 # Sets InstallDir to the ESP mount point
727 # Sets UnmountEsp if we mounted it
729 # Identify the ESP. Note: This returns the FIRST ESP found;
730 # if the system has multiple disks, this could be wrong!
731 Temp
=$
(mount |
sed -n -E "/^(\/dev\/disk[0-9]+s[0-9]+) on \/ \(.*$/s//\1/p")
733 Temp
=$
(diskutil list |
grep " EFI " |
grep -o 'disk.*' |
head -n 1)
734 if [ -z $Temp ]; then
735 echo "Warning: root device doesn't have an EFI partition"
738 echo "Warning: root device could not be found"
740 if [ -z $Temp ]; then
741 Temp
=$
(diskutil list |
sed -n -E '/^ *[0-9]+:[ ]+EFI EFI[ ]+[0-9.]+ [A-Z]+[ ]+(disk[0-9]+s[0-9]+)$/ { s//\1/p
745 if [ -z $Temp ]; then
746 echo "Could not find an EFI partition. Aborting!"
750 Esp
=/dev
/`echo $Temp`
751 # If the ESP is mounted, use its current mount point....
752 Temp
=`df -P | grep "$Esp "`
753 InstallDir
=`echo $Temp | cut -f 6- -d ' '`
754 if [[ "$InstallDir" == '' ]] ; then
755 mkdir
/Volumes
/ESP
&> /dev
/null
756 mount
-t msdos
"$Esp" /Volumes
/ESP
757 # Some systems have HFS+ "ESPs." They shouldn't, but they do. If this is
758 # detected, mount it as such and set appropriate options.
759 if [[ $?
!= 0 ]] ; then
760 mount
-t hfs
"$Esp" /Volumes
/Esp
763 if [[ $?
!= 0 ]] ; then
764 echo "Unable to mount ESP! Aborting!\n"
769 InstallDir
="/Volumes/ESP"
773 # Set up for booting from Mac HFS+ volume that boots rEFInd in MJG's way
774 # (http://mjg59.dreamwidth.org/7468.html)
775 # Must be passed the original rEFInd binary filename (without a path).
777 if [[ -s "$InstallDir/mach_kernel" ]] ; then
778 echo "Attempt to install rEFInd to a partition with a /mach_kernel file! Aborting!"
781 cp -n "$InstallDir/$TargetDir/boot.efi" "$InstallDir/$TargetDir/boot.efi-backup" &> /dev
/null
782 ln -f "$InstallDir/$TargetDir/$1" "$InstallDir/$TargetDir/boot.efi"
783 touch "$InstallDir/mach_kernel"
784 rm "$InstallDir/$TargetDir/SystemVersion.plist" &> /dev
/null
785 cat - << ENDOFHERE >> "$InstallDir/$TargetDir/SystemVersion.plist"
786 <xml version="1.0" encoding="UTF-8"?>
787 <plist version="1.0">
789 <key>ProductBuildVersion</key>
791 <key>ProductName</key>
792 <string>rEFInd</string>
793 <key>ProductVersion</key>
794 <string>0.10.0</string>
801 if [[ -x "/usr/bin/csrutil" ]] ; then
802 local OKToInstall
=`/usr/bin/csrutil status | \
803 grep "Protection status: disabled\|enabled (Apple Internal)\|NVRAM Protections: disabled"`
804 if [[ -z "$OKToInstall" ]] ; then
806 echo "**** ALERT: SIP ENABLED! ****"
808 if [[ "$Upgrade" == "1" ]] ; then
809 echo "You are attempting to upgrade an existing installation, but it appears that"
810 echo "System Integrity Protection (SIP) is enabled. If rEFInd is working now, then"
811 echo "this is fine; you can upgrade your existing rEFInd. If rEFInd is not working,"
812 echo "though, re-installing from this boot will not help. To re-enable rEFInd, you"
813 echo "must re-install it from a Recovery system or from another OS. To enter the"
814 echo "Recovery system and re-install rEFInd:"
816 echo "rEFInd cannot be installed because System Integrity Protection (SIP) seems"
817 echo "to be enabled! You must install rEFInd from your Recovery installation or"
818 echo "from another OS. To install from the Recovery system:"
822 echo " 2. Hold down Command+R as the chime sounds"
823 echo " 3. When the OS has booted, select Utilities->Terminal"
824 echo " 4. Change to this directory with the 'cd' command; it will probably be under"
825 if [[ "`pwd | cut -b 1-8`" == "/Volumes" ]] ; then
828 local RootName
=`diskutil info -plist / | grep -A 1 VolumeName | grep string | cut -d \> -f 2 | cut -d \< -f 1`
829 echo " /Volumes/$RootName`pwd`"
831 echo " 5. Re-run this script."
833 if [[ "$Upgrade" != "1" ]] ; then
834 echo "If you believe SIP is NOT enabled, you may attempt an installation anyhow,"
835 echo "but it may fail."
838 echo "For more on this subject, see http://www.rodsbooks.com/refind/sip.html"
840 echo -n "Do you want to attempt installation (Y/N)? "
842 if [[ $YesNo == "N" ||
$YesNo == "n" ]] ; then
846 fi # csrutil status suggests OK to install
850 # Control the OS X installation.
851 # Sets Problems=1 if problems found during the installation.
853 echo "Installing rEFInd on OS X...."
854 if [[ "$InstallToEspOnMac" == "1" ]] ; then
856 elif [[ "$TargetDir" == "/EFI/BOOT" ||
"$OwnHfs" == '1' ]] ; then
859 InstallDir
="$RootDir/"
861 echo "Installing rEFInd to the partition mounted at $InstallDir"
865 cp "$ThisDir/mountesp" /usr
/local
/bin
&> /dev
/null
866 if [[ $InstallToEspOnMac == "1" ]] ; then
867 bless
--mount "$InstallDir" --setBoot --file "$InstallDir/$TargetDir/$Refind" --shortform
868 elif [[ "$TargetDir" != "/EFI/BOOT" ]] ; then
869 bless
--setBoot --folder "$InstallDir/$TargetDir" --file "$InstallDir/$TargetDir/$Refind"
871 if [[ $?
!= 0 ]] ; then
874 if [[ -f /Library
/StartupItems
/rEFItBlesser ||
-d /Library
/StartupItems
/rEFItBlesser
]] ; then
876 echo "/Library/StartupItems/rEFItBlesser found!"
877 echo "This program is part of rEFIt, and will cause rEFInd to fail to work after"
878 echo -n "its first boot. Do you want to remove rEFItBlesser (Y/N)? "
880 if [[ $YesNo == "Y" ||
$YesNo == "y" ]] ; then
881 echo "Deleting /Library/StartupItems/rEFItBlesser..."
882 rm -r /Library
/StartupItems
/rEFItBlesser
884 echo "Not deleting rEFItBlesser."
891 # Now a series of Linux support functions....
894 # Check for evidence that we're running in Secure Boot mode. If so, and if
895 # appropriate options haven't been set, warn the user and offer to abort.
896 # If we're NOT in Secure Boot mode but the user HAS specified the --shim
897 # or --localkeys option, warn the user and offer to abort.
900 if [[ -f /sys
/firmware
/efi
/vars
/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c
/data
]] ; then
901 IsSecureBoot
=`od -An -t u1 /sys/firmware/efi/vars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c/data | tr -d '[[:space:]]'`
905 if [[ $IsSecureBoot == "1" && "$TargetDir" != '/EFI/BOOT' && "$ShimSource" == "none" ]] ; then
907 echo "CAUTION: Your computer appears to be booted with Secure Boot, but you haven't"
908 echo "specified a valid shim.efi file source. Chances are you should re-run with"
909 echo "the --shim option. You can read more about this topic at"
910 echo "http://www.rodsbooks.com/refind/secureboot.html."
912 echo -n "Do you want to proceed with installation (Y/N)? "
914 if [[ $YesNo == "Y" ||
$YesNo == "y" ]] ; then
915 echo "OK; continuing with the installation..."
921 if [[ "$ShimSource" != "none" && ! $IsSecureBoot == "1" ]] ; then
923 echo "You've specified installing using a shim.efi file, but your computer does not"
924 echo "appear to be running in Secure Boot mode. Although installing in this way"
925 echo "should work, it's unnecessarily complex. You may continue, but unless you"
926 echo "plan to enable Secure Boot, you should consider stopping and omitting the"
927 echo "--shim option. You can read more about this topic at"
928 echo "http://www.rodsbooks.com/refind/secureboot.html."
930 echo -n "Do you want to proceed with installation (Y/N)? "
932 if [[ $YesNo == "Y" ||
$YesNo == "y" ]] ; then
933 echo "OK; continuing with the installation..."
939 if [[ $LocalKeys != 0 && ! $IsSecureBoot == "1" ]] ; then
941 echo "You've specified re-signing your rEFInd binaries with locally-generated keys,"
942 echo "but your computer does not appear to be running in Secure Boot mode. The"
943 echo "keys you generate will be useless unless you enable Secure Boot. You may"
944 echo "proceed with this installation, but before you do so, you may want to read"
945 echo "more about it at http://www.rodsbooks.com/refind/secureboot.html."
947 echo -n "Do you want to proceed with installation (Y/N)? "
949 if [[ $YesNo == "Y" ||
$YesNo == "y" ]] ; then
950 echo "OK; continuing with the installation..."
956 } # CheckSecureBoot()
958 # Check for the presence of locally-generated keys from a previous installation in
959 # $EtcKeysDir (/etc/refind.d/keys). If they're not present, generate them using
962 PrivateKey
="$EtcKeysDir/$LocalKeysBase.key"
963 CertKey
="$EtcKeysDir/$LocalKeysBase.crt"
964 DerKey
="$EtcKeysDir/$LocalKeysBase.cer"
965 OpenSSL
=`which openssl 2> /dev/null`
967 # Do the work only if one or more of the necessary keys is missing
968 # TODO: Technically, we don't need the DerKey; but if it's missing and openssl
969 # is also missing, this will fail. This could be improved.
970 if [[ ! -f "$PrivateKey" ||
! -f "$CertKey" ||
! -f "$DerKey" ]] ; then
971 echo "Generating a fresh set of local keys...."
972 mkdir
-p "$EtcKeysDir"
973 chmod 0700 "$EtcKeysDir"
974 if [[ ! -x "$OpenSSL" ]] ; then
975 echo "Can't find openssl, which is required to create your private signing keys!"
979 if [[ -f "$PrivateKey" ]] ; then
980 echo "Backing up existing $PrivateKey"
981 cp -f "$PrivateKey" "$PrivateKey.backup" 2> /dev
/null
983 if [[ -f "$CertKey" ]] ; then
984 echo "Backing up existing $CertKey"
985 cp -f "$CertKey" "$CertKey.backup" 2> /dev
/null
987 if [[ -f "$DerKey" ]] ; then
988 echo "Backing up existing $DerKey"
989 cp -f "$DerKey" "$DerKey.backup" 2> /dev
/null
991 "$OpenSSL" req
-new -x509 -newkey rsa
:2048 -keyout "$PrivateKey" -out "$CertKey" \
992 -nodes -days 3650 -subj "/CN=Locally-generated rEFInd key/"
993 "$OpenSSL" x509
-in "$CertKey" -out "$DerKey" -outform DER
994 chmod 0600 "$PrivateKey"
996 echo "Using existing local keys...."
1000 # Sign a single binary. Requires parameters:
1002 # $2 = destination file
1003 # Also assumes that the SBSign, PESign, UseSBSign, UsePESign, and various key variables are set
1005 # Aborts script on error
1007 $SBSign --key "$PrivateKey" --cert "$CertKey" --output "$2" "$1"
1008 if [[ $?
!= 0 ]] ; then
1009 echo "Problem signing the binary $1! Aborting!"
1014 # Re-sign the x86-64 binaries with a locally-generated key, First look for appropriate
1015 # key files in $EtcKeysDir. If they're present, use them to re-sign the binaries. If
1016 # not, try to generate new keys and store them in $EtcKeysDir.
1018 SBSign
=`which sbsign 2> /dev/null`
1019 echo "Found sbsign at $SBSign"
1020 TempDir
="/tmp/refind_local"
1021 if [[ ! -x "$SBSign" ]] ; then
1022 echo "Can't find sbsign, which is required to sign rEFInd with your own keys!"
1027 mkdir
-p "$TempDir/drivers_$Platform"
1028 cp "$RefindDir/refind.conf-sample $TempDir" 2> /dev
/null
1029 cp "$ThisDir/refind.conf-sample $TempDir" 2> /dev
/null
1030 cp "$RefindDir/refind_ia32.efi $TempDir" 2> /dev
/null
1031 cp -a "$RefindDir/drivers_ia32 $TempDir" 2> /dev
/null
1032 cp -a "$ThisDir/drivers_ia32 $TempDir" 2> /dev
/null
1033 SignOneBinary
"$RefindDir/refind_$Platform.efi" "$TempDir/refind_$Platform.efi"
1035 IFS
=$
(echo -en "\n\b")
1036 for Driver
in `ls "$RefindDir"/drivers_$Platform/*.efi "$ThisDir"/drivers_$Platform/*.efi 2> /dev/null` ; do
1037 TempName
=`basename "$Driver"`
1038 SignOneBinary
"$Driver" "$TempDir/drivers_$Platform/$TempName"
1041 RefindDir
="$TempDir"
1043 } # ReSignBinaries()
1045 # Locate and mount an ESP, if possible, based on parted output.
1046 # Should be called only if /boot/efi is NOT an acceptable ESP.
1047 # Sets InstallDir to the mounted ESP's path ($RootDir/boot/efi)
1048 # and EspFilesystem the filesystem (always "vfat")
1050 echo "The ESP doesn't seem to be mounted! Trying to find it...."
1057 for Drive
in `ls /dev/[sh]d?` ; do
1059 Dmraid
=`which dmraid 2> /dev/null`
1060 if [ -x "$Dmraid" ] ; then
1061 DmStatus
=`dmraid -r | grep $Drive`
1062 if [ -n "$DmStatus" ] ; then
1063 echo "$Drive seems to be part of a RAID array; skipping!"
1067 TableType
=`parted $Drive print -m -s 2>/dev/null | awk -F: '$1 == "'$Drive'" { print $6 }'`
1068 if [[ $TableType == 'gpt' && $SkipIt == 0 ]] ; then # read only GPT disks that aren't part of dmraid array
1069 PartNum
=`LANG=C parted $Drive print -m -s 2>/dev/null | awk -F: '$7 ~ "(^boot| boot)" { print $1 }' | head -n 1`
1070 if [ "$PartNum" -eq "$PartNum" ] 2> /dev
/null
; then
1071 InstallDir
="$RootDir/boot/efi"
1072 mkdir
-p $InstallDir
1073 mount
$Drive$PartNum $InstallDir
1074 EspFilesystem
=`grep "$Drive$PartNum.*/boot/efi" /etc/mtab | uniq | grep -v autofs | cut -d " " -f 3`
1075 if [[ $EspFilesystem != 'vfat' ]] ; then
1078 echo "Mounting ESP at $InstallDir"
1081 fi # $PartNum -eq $PartNum
1086 # Identifies the ESP's location (/boot or /boot/efi, or these locations under
1087 # the directory specified by --root); aborts if the ESP isn't mounted at
1089 # Sets InstallDir to the ESP mount point.
1091 mount
/boot
&> /dev
/null
1092 mount
/boot
/efi
&> /dev
/null
1093 EspLine
=`df "$RootDir/boot/efi" 2> /dev/null | grep boot/efi`
1094 if [[ ! -n "$EspLine" ]] ; then
1095 EspLine
=`df "$RootDir"/boot | grep boot`
1097 InstallDir
=`echo $EspLine | cut -d " " -f 6`
1099 if [[ -n "$InstallDir" ]] ; then
1100 EspFilesystem
=`grep -w "$InstallDir" /etc/mtab | uniq | grep -v autofs | cut -d " " -f 3`
1102 if [[ $EspFilesystem != 'vfat' ]] ; then
1105 if [[ $EspFilesystem != 'vfat' ]] ; then
1106 echo "$RootDir/$InstallDir doesn't seem to be on a VFAT filesystem. The ESP must be"
1107 echo "mounted at $RootDir/boot or $RootDir/boot/efi and it must be VFAT! Aborting!"
1110 echo "ESP was found at $InstallDir using $EspFilesystem"
1113 # Uses efibootmgr to add an entry for rEFInd to the EFI's NVRAM.
1114 # If this fails, sets Problems=1
1117 Efibootmgr
=`which efibootmgr 2> /dev/null`
1118 if [[ "$Efibootmgr" ]] ; then
1119 InstallDisk
=`grep "$InstallDir" /etc/mtab | cut -d " " -f 1 | cut -c 1-8`
1120 PartNum
=`grep "$InstallDir" /etc/mtab | cut -d " " -f 1 | cut -c 9-10`
1121 EntryFilename
="$TargetDir/$Refind"
1122 EfiEntryFilename
=`echo ${EntryFilename//\//\\\}`
1123 EfiEntryFilename2
=`echo ${EfiEntryFilename} | sed s/\\\\\\\\/\\\\\\\\\\\\\\\\/g`
1124 ExistingEntry
=`"$Efibootmgr" -v | grep -i "$EfiEntryFilename2"`
1126 if [[ "$ExistingEntry" ]] ; then
1127 ExistingEntryBootNum
=`echo "$ExistingEntry" | cut -c 5-8`
1128 FirstBoot
=`"$Efibootmgr" | grep BootOrder | cut -c 12-15`
1129 if [[ "$ExistingEntryBootNum" != "$FirstBoot" ]] ; then
1130 echo "An existing rEFInd boot entry exists, but isn't set as the default boot"
1131 echo "manager. The boot order is being adjusted to make rEFInd the default boot"
1132 echo "manager. If this is NOT what you want, you should use efibootmgr to"
1133 echo "manually adjust your EFI's boot order."
1135 "$Efibootmgr" -b $ExistingEntryBootNum -B &> /dev
/null
1138 echo "Installing it!"
1139 if [[ "$KeepName" == 0 ]] ; then
1140 "$Efibootmgr" -c -l "$EfiEntryFilename" -L "rEFInd Boot Manager" -d $InstallDisk -p $PartNum &> /dev
/null
1142 "$Efibootmgr" -c -l "$EfiEntryFilename" -L "rEFInd Boot Manager" -d $InstallDisk -p $PartNum \
1143 -u "$TargetShim $TargetX64" &> /dev
/null
1145 if [[ $?
!= 0 ]] ; then
1146 EfibootmgrProblems
=1
1150 else # efibootmgr not found
1151 EfibootmgrProblems
=1
1155 if [[ $EfibootmgrProblems ]] ; then
1157 echo "ALERT: There were problems running the efibootmgr program! You may need to"
1158 echo "rename the $Refind binary to the default name (EFI/BOOT/bootx64.efi"
1159 echo "on x86-64 systems, EFI/BOOT/bootia32.efi on x86 systems, or"
1160 echo "EFI/BOOT/bootaa64.efi on ARM64 systems) to have it run!"
1163 echo "rEFInd has been set as the default boot manager."
1167 # Create a minimal/sample refind_linux.conf file in /boot.
1168 GenerateRefindLinuxConf
() {
1169 if [[ -f "$RLConfFile" ]] ; then
1170 echo "Existing $RLConfFile found; not overwriting."
1172 echo "Creating $RLConfFile; edit it to adjust kernel options."
1173 RootFS
=`df "$RootDir" | grep dev | cut -f 1 -d " "`
1174 StartOfDevname
=`echo "$RootFS" | cut -b 1-7`
1175 if [[ "$StartOfDevname" == "/dev/sd" ||
"$StartOfDevName" == "/dev/hd" ]] ; then
1176 # Identify root filesystem by UUID rather than by device node, if possible
1177 Uuid
=`blkid -o export -s UUID "$RootFS" 2> /dev/null | grep UUID=`
1178 if [[ -n $Uuid ]] ; then
1182 if [[ $RootDir == "/" ]] ; then
1183 local FirstCmdlineOption
=`cat /proc/cmdline | cut -d ' ' -f 1`
1184 if [[ "$FirstCmdlineOption" =~
(vmlinuz|bzImage|kernel
) ]] ; then
1185 DefaultOptions
=`cat /proc/cmdline | cut -d ' ' -f 2- | sed 's/\S*initrd=\S*//g' | sed 's/ *$//' | sed 's/^ *//'`
1187 DefaultOptions
=`cat /proc/cmdline | sed 's/\S*initrd=\S*//g' | sed 's/ *$//' | sed 's/^ *//'`
1190 if [[ -f "$RootDir/etc/default/grub" ]] ; then
1191 # We want the default options used by the distribution, stored here....
1192 source "$RootDir/etc/default/grub"
1193 echo "Setting default boot options based on $RootDir/etc/default/grub"
1195 DefaultOptions
="ro root=$RootFS $GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
1197 echo "\"Boot with standard options\" \"$DefaultOptions\"" > $RLConfFile
1198 echo "\"Boot to single-user mode\" \"$DefaultOptions single\"" >> $RLConfFile
1199 echo "\"Boot with minimal options\" \"ro root=$RootFS\"" >> $RLConfFile
1203 # Controls rEFInd installation under Linux.
1204 # Sets Problems=1 if something goes wrong.
1206 if [[ "$TargetDir" == "/System/Library/CoreServices" ]] ; then
1207 echo "You may not use the --ownhfs option under Linux! Aborting!"
1210 echo "Installing rEFInd on Linux...."
1211 modprobe efivars
&> /dev
/null
1212 if [[ $TargetDir == "/EFI/BOOT" ]] ; then
1219 if [[ $LocalKeys == 1 ]] ; then
1225 if [[ "$TargetDir" != "/EFI/BOOT" && "$TargetDir" != "/EFI/Microsoft/Boot" ]] ; then
1227 GenerateRefindLinuxConf
1229 } # InstallOnLinux()
1232 # The main part of the script. Sets a few environment variables,
1233 # performs a few startup checks, and then calls functions to
1234 # install under OS X or Linux, depending on the detected platform.
1237 if [[ $UID != 0 ]] ; then
1238 echo "Not running as root; attempting to elevate privileges via sudo...."
1239 sudo
"$BASH_SOURCE" "$@"
1240 if [[ $?
!= 0 ]] ; then
1241 echo "This script must be run as root (or using sudo). Exiting!"
1251 if [[ "$ShimSource" != "none" ]] ; then
1252 echo "The --shim option is not supported on OS X! Exiting!"
1255 if [[ "$LocalKeys" != 0 ]] ; then
1256 echo "The --localkeys option is not supported on OS X! Exiting!"
1265 echo "Running on unknown OS; aborting!"
1266 if [[ "$InstallToEspOnMac" == 0 ]] ; then
1267 echo "The --notesp option is not supported on Linux! Exiting!"
1272 if [[ $Problems ]] ; then
1275 echo "Installation has completed, but problems were detected. Review the output for"
1276 echo "error messages and take corrective measures as necessary. You may need to"
1277 echo "re-run this script or install manually before rEFInd will work."
1281 echo "Installation has completed successfully."
1285 if [[ $UnmountEsp == '1' ]] ; then
1286 echo "Unmounting install dir"
1289 diskutil unmount
$InstallDir
1297 if [[ "$InstallDir" == /tmp
/refind_install
]] ; then