]>
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!"
64 # Copy the rEFInd files to the ESP or OS X root partition.
65 # Sets Problems=1 if any critical commands fail.
67 mkdir
-p $InstallPart/$TargetDir &> /dev
/null
68 if [[ $Platform == 'EFI32' ]] ; then
69 cp $RefindDir/refind_ia32.efi
$InstallPart/$TargetDir
70 if [[ $?
!= 0 ]] ; then
73 Refind
="refind_ia32.efi"
74 elif [[ $Platform == 'EFI64' ]] ; then
75 cp $RefindDir/refind_x64.efi
$InstallPart/$TargetDir
76 if [[ $?
!= 0 ]] ; then
79 Refind
="refind_x64.efi"
81 echo "Unknown platform! Aborting!"
84 echo "Copied rEFInd binary file $Refind"
86 if [[ -d $InstallPart/$TargetDir/icons
]] ; then
87 rm -rf $InstallPart/$TargetDir/icons-backup
&> /dev
/null
88 mv -f $InstallPart/$TargetDir/icons
$InstallPart/$TargetDir/icons-backup
89 echo "Notice: Backed up existing icons directory as icons-backup."
91 cp -r $IconsDir $InstallPart/$TargetDir
92 if [[ $?
!= 0 ]] ; then
95 if [[ -f $InstallPart/$TargetDir/refind.conf
]] ; then
96 echo "Existing refind.conf file found; copying sample file as refind.conf-sample"
97 echo "to avoid collision."
99 cp -f $ConfFile $InstallPart/$TargetDir
100 if [[ $?
!= 0 ]] ; then
104 echo "Copying sample configuration file as refind.conf; edit this file to configure"
107 cp -f $ConfFile $InstallPart/$TargetDir/refind.conf
108 if [[ $?
!= 0 ]] ; then
112 } # CopyRefindFiles()
116 # A series of OS X support functions....
119 # Mount the ESP at /Volumes/ESP or determine its current mount
121 # Sets InstallPart to the ESP mount point
122 # Sets UnmountEsp if we mounted it
124 # Identify the ESP. Note: This returns the FIRST ESP found;
125 # if the system has multiple disks, this could be wrong!
126 Temp
=`diskutil list | grep EFI`
127 Esp
=/dev
/`echo $Temp | cut -f 5 -d ' '`
128 # If the ESP is mounted, use its current mount point....
129 Temp
=`df | grep $Esp`
130 InstallPart
=`echo $Temp | cut -f 6 -d ' '`
131 if [[ $InstallPart == '' ]] ; then
132 mkdir
/Volumes
/ESP
&> /dev
/null
133 mount
-t msdos
$Esp /Volumes
/ESP
134 if [[ $?
!= 0 ]] ; then
135 echo "Unable to mount ESP! Aborting!\n"
139 InstallPart
="/Volumes/ESP"
143 # Control the OS X installation.
144 # Sets Problems=1 if problems found during the installation.
146 echo "Installing rEFInd on OS X...."
147 if [[ $1 == 'esp' ||
$1 == 'ESP' ]] ; then
152 echo "Installing rEFInd to the partition mounted at '$InstallPart'"
153 Platform
=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
155 if [[ $1 == 'esp' ||
$1 == 'ESP' ]] ; then
156 bless
--mount $InstallPart --setBoot --file $InstallPart/$TargetDir/$Refind
158 bless
--setBoot --folder $InstallPart/$TargetDir --file $InstallPart/$TargetDir/$Refind
160 if [[ $?
!= 0 ]] ; then
164 echo "WARNING: If you have an Advanced Format disk, *DO NOT* attempt to check the"
165 echo "bless status with 'bless --info', since this is known to cause disk corruption"
166 echo "on some systems!!"
172 # Now a series of Linux support functions....
175 # Identifies the ESP's location (/boot or /boot/efi); aborts if
176 # the ESP isn't mounted at either location.
177 # Sets InstallPart to the ESP mount point.
179 EspLine
=`df /boot/efi | grep boot`
180 InstallPart
=`echo $EspLine | cut -d " " -f 6`
181 EspFilesystem
=`grep $InstallPart /etc/mtab | cut -d " " -f 3`
182 if [[ $EspFilesystem != 'vfat' ]] ; then
183 echo "/boot/efi doesn't seem to be on a VFAT filesystem. The ESP must be mounted at"
184 echo "/boot or /boot/efi and it must be VFAT! Aborting!"
187 echo "ESP was found at $InstallPart using $EspFilesystem"
190 # Uses efibootmgr to add an entry for rEFInd to the EFI's NVRAM.
191 # If this fails, sets Problems=1
193 Efibootmgr
=`which efibootmgr 2> /dev/null`
194 if [[ $Efibootmgr ]] ; then
195 modprobe efivars
&> /dev
/null
196 InstallDisk
=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 1-8`
197 PartNum
=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 9-10`
198 EntryFilename
=$TargetDir/$Refind
199 EfiEntryFilename
=`echo ${EntryFilename//\//\\\}`
200 ExistingEntry
=`$Efibootmgr -v | grep $Refind`
201 if [[ $ExistingEntry ]] ; then
202 echo "An existing EFI boot manager entry for rEFInd seems to exist:"
204 echo "$ExistingEntry"
206 echo "This entry is NOT being modified, and no new entry is being created."
208 $Efibootmgr -c -l $EfiEntryFilename -L rEFInd
-d $InstallDisk -p $PartNum &> /dev
/null
209 if [[ $?
!= 0 ]] ; then
218 if [[ $EfibootmgrProblems ]] ; then
220 echo "ALERT: There were problems running the efibootmgr program! You may need to"
221 echo "rename the $Refind binary to the default name (EFI/boot/bootx64.efi"
222 echo "on x86-64 systems or EFI/boot/bootia32.efi on x86 systems) to have it run!"
227 # Controls rEFInd installation under Linux.
228 # Sets Problems=1 if something goes wrong.
230 echo "Installing rEFInd on Linux...."
233 if [[ $CpuType == 'x86_64' ]] ; then
235 elif [[ $CpuType == 'i386' ||
$CpuType == 'i486' ||
$CpuType == 'i586' ||
$CpuType == 'i686' ]] ; then
238 echo "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based"
239 echo "computers are VERY RARE. If you've installed a 32-bit version of Linux"
240 echo "on a 64-bit computer, you should manually install the 64-bit version of"
241 echo "rEFInd. If you're installing on a Mac, you should do so from OS X. If"
242 echo "you're positive you want to continue with this installation, answer 'Y'"
243 echo "to the following question..."
245 echo -n "Are you sure you want to continue (Y/N)? "
247 if [[ $ContYN == "Y" ||
$ContYN == "y" ]] ; then
248 echo "OK; continuing with the installation..."
253 echo "Unknown CPU type '$CpuType'; aborting!"
261 # The main part of the script. Sets a few environment variables,
262 # performs a few startup checks, and then calls functions to
263 # install under OS X or Linux, depending on the detected platform.
267 ThisDir
="$( cd -P "$
( dirname "${BASH_SOURCE[0]}" )" && pwd )"
268 RefindDir
="$ThisDir/refind"
269 ThisScript
="$ThisDir/`basename $0`"
271 if [[ `whoami` != "root" ]] ; then
272 echo "Not running as root; attempting to elevate privileges via sudo...."
274 if [[ $?
!= 0 ]] ; then
275 echo "This script must be run as root (or using sudo). Exiting!"
281 if [[ $OSName == 'Darwin' ]] ; then
283 elif [[ $OSName == 'Linux' ]] ; then
286 echo "Running on unknown OS; aborting!"
289 if [[ $Problems ]] ; then
292 echo "Installation has completed, but problems were detected. Review the output for"
293 echo "error messages and take corrective measures as necessary. You may need to"
294 echo "re-run this script or install manually before rEFInd will work."
298 echo "Installation has completed successfully."
302 if [[ $UnmountEsp ]] ; then