]>
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.2 -- Initial version
22 # Note: install.sh version numbers match those of the rEFInd package
23 # with which they first appeared.
28 # Functions used by both OS X and Linux....
32 mkdir
-p $InstallPart/$TargetDir &> /dev
/null
33 if [[ $Platform == 'EFI32' ]] ; then
34 cp $SourceDir/refind_ia32.efi
$InstallPart/$TargetDir
35 if [[ $?
!= 0 ]] ; then
38 Refind
="refind_ia32.efi"
39 elif [[ $Platform == 'EFI64' ]] ; then
40 cp $SourceDir/refind_x64.efi
$InstallPart/$TargetDir
41 if [[ $?
!= 0 ]] ; then
44 Refind
="refind_x64.efi"
46 echo "Unknown platform! Aborting!"
49 echo "Copied rEFInd binary file $Refind"
51 if [[ -d $InstallPart/$TargetDir/icons
]] ; then
52 rm -rf $InstallPart/$TargetDir/icons-backup
&> /dev
/null
53 mv -f $InstallPart/$TargetDir/icons
$InstallPart/$TargetDir/icons-backup
54 echo "Notice: Backed up existing icons directory as icons-backup."
56 cp -r $SourceDir/icons
$InstallPart/$TargetDir
57 if [[ $?
!= 0 ]] ; then
60 if [[ -f $InstallPart/$TargetDir/refind.conf
]] ; then
61 echo "Existing refind.conf file found; copying sample file as refind.conf-sample"
62 echo "to avoid collision."
64 cp -f $SourceDir/refind.conf-sample
$InstallPart/$TargetDir
65 if [[ $?
!= 0 ]] ; then
69 echo "Copying sample configuration file as refind.conf; edit this file to configure"
72 cp -f $SourceDir/refind.conf-sample
$InstallPart/$TargetDir/refind.conf
73 if [[ $?
!= 0 ]] ; then
81 # A series of OS X support functions....
84 # Mount the ESP at /Volumes/ESP or determine its current mount
86 # Sets InstallPart to the ESP mount point
87 # Sets UnmountEsp if we mounted it
89 # Identify the ESP. Note: This returns the FIRST ESP found;
90 # if the system has multiple disks, this could be wrong!
91 Temp
=`diskutil list | grep EFI`
92 Esp
=/dev
/`echo $Temp | cut -f 5 -d ' '`
93 # If the ESP is mounted, use its current mount point....
95 InstallPart
=`echo $Temp | cut -f 6 -d ' '`
96 if [[ $InstallPart == '' ]] ; then
97 mkdir
/Volumes
/ESP
&> /dev
/null
98 mount
-t msdos
$Esp /Volumes
/ESP
99 if [[ $?
!= 0 ]] ; then
100 echo "Unable to mount ESP! Aborting!\n"
104 InstallPart
="/Volumes/ESP"
109 echo "Installing rEFInd on OS X...."
110 if [[ $1 == 'esp' ||
$1 == 'ESP' ]] ; then
115 echo "Installing rEFInd to the partition mounted at '$InstallPart'"
116 Platform
=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
118 if [[ $1 == 'esp' ||
$1 == 'ESP' ]] ; then
119 bless
--mount $InstallPart --setBoot --file $InstallPart/$TargetDir/$Refind
121 bless
--setBoot --folder $InstallPart/$TargetDir --file $InstallPart/$TargetDir/$Refind
123 if [[ $?
!= 0 ]] ; then
127 echo "WARNING: If you have an Advanced Format disk, *DO NOT* attempt to check the"
128 echo "bless status with 'bless --info', since this is known to cause disk corruption"
129 echo "on some systems!!"
135 # Now a series of Linux support functions....
139 EspLine
=`df /boot/efi | grep boot`
140 InstallPart
=`echo $EspLine | cut -d " " -f 6`
141 EspFilesystem
=`grep $InstallPart /etc/mtab | cut -d " " -f 3`
142 if [[ $EspFilesystem != 'vfat' ]] ; then
143 echo "/boot/efi doesn't seem to be on a VFAT filesystem. The ESP must be mounted at"
144 echo "/boot or /boot/efi and it must be VFAT! Aborting!"
147 echo "ESP was found at $InstallPart using $EspFilesystem"
151 Efibootmgr
=`which efibootmgr 2> /dev/null`
152 if [[ $Efibootmgr ]] ; then
153 modprobe efivars
&> /dev
/null
154 InstallDisk
=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 1-8`
155 PartNum
=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 9-10`
156 EntryFilename
=$TargetDir/$Refind
157 EfiEntryFilename
=`echo ${EntryFilename//\//\\\}`
158 ExistingEntry
=`$Efibootmgr -v | grep $Refind`
159 if [[ $ExistingEntry ]] ; then
160 echo "An existing EFI boot manager entry for rEFInd seems to exist:"
162 echo "$ExistingEntry"
164 echo "This entry is NOT being modified, and no new entry is being created."
166 $Efibootmgr -c -l $EfiEntryFilename -L rEFInd
-d $InstallDisk -p $PartNum &> /dev
/null
167 if [[ $?
!= 0 ]] ; then
176 if [[ $EfibootmgrProblems ]] ; then
178 echo "ALERT: There were problems running the efibootmgr program! You may need to"
179 echo "rename the $Refind binary to the default name (EFI/boot/bootx64.efi"
180 echo "on x86-64 systems or EFI/boot/bootia32.efi on x86 systems) to have it run!"
186 echo "Installing rEFInd on Linux...."
189 if [[ $CpuType == 'x86_64' ]] ; then
191 elif [[ $CpuType == 'i386' ||
$CpuType == 'i486' ||
$CpuType == 'i586' ||
$CpuType == 'i686' ]] ; then
194 echo "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based"
195 echo "computers are VERY RARE. If you've installed a 32-bit version of Linux"
196 echo "on a 64-bit computer, you should manually install the 64-bit version of"
197 echo "rEFInd. If you're installing on a Mac, you should do so from OS X. If"
198 echo "you're positive you want to continue with this installation, answer 'Y'"
199 echo "to the following question..."
201 echo -n "Are you sure you want to continue (Y/N)? "
203 if [[ $ContYN == "Y" ||
$ContYN == "y" ]] ; then
204 echo "OK; continuing with the installation..."
209 echo "Unknown CPU type '$CpuType'; aborting!"
216 # The main part of the script; just checks the OS and calls a
217 # function for installing on that platform....
219 ThisScript
=`readlink -f $0`
220 if [[ `whoami` != "root" ]] ; then
221 echo "Not running as root; attempting to elevate privileges via sudo...."
223 if [[ $?
!= 0 ]] ; then
224 echo "This script must be run as root (or using sudo). Exiting!"
231 SourceDir
=`dirname $ThisScript`/refind
232 if [[ $OSName == 'Darwin' ]] ; then
234 elif [[ $OSName == 'Linux' ]] ; then
237 echo "Running on unknown OS; aborting!"
240 if [[ $Problems ]] ; then
243 echo "Installation has completed, but problems were detected. Review the output for"
244 echo "error messages and take corrective measures as necessary. You may need to"
245 echo "re-run this script or install manually before rEFInd will work."
249 echo "Installation has completed successfully."
253 if [[ $UnmountEsp ]] ; then