]>
code.delx.au - refind/blob - install.sh
479cef7c85b8ee7f988cce448acbe99c15caaa1c
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.1 -- Check for presence of source files; aborts if not present
21 # 0.3.2 -- Initial version
23 # Note: install.sh version numbers match those of the rEFInd package
24 # with which they first appeared.
29 # Functions used by both OS X and Linux....
32 # Abort if the rEFInd files can't be found.
34 if [[ ! -f $SourceDir/refind_ia32.efi ||
! -f $SourceDir/refind_x64.efi ||
! -f $SourceDir/refind.conf-sample ||
! -d $SourceDir/icons
]] ; then
35 echo "One or more files missing! Aborting installation!"
40 # Copy the rEFInd files to the ESP or OS X root partition.
41 # Sets Problems=1 if any critical commands fail.
43 mkdir
-p $InstallPart/$TargetDir &> /dev
/null
44 if [[ $Platform == 'EFI32' ]] ; then
45 cp $SourceDir/refind_ia32.efi
$InstallPart/$TargetDir
46 if [[ $?
!= 0 ]] ; then
49 Refind
="refind_ia32.efi"
50 elif [[ $Platform == 'EFI64' ]] ; then
51 cp $SourceDir/refind_x64.efi
$InstallPart/$TargetDir
52 if [[ $?
!= 0 ]] ; then
55 Refind
="refind_x64.efi"
57 echo "Unknown platform! Aborting!"
60 echo "Copied rEFInd binary file $Refind"
62 if [[ -d $InstallPart/$TargetDir/icons
]] ; then
63 rm -rf $InstallPart/$TargetDir/icons-backup
&> /dev
/null
64 mv -f $InstallPart/$TargetDir/icons
$InstallPart/$TargetDir/icons-backup
65 echo "Notice: Backed up existing icons directory as icons-backup."
67 cp -r $SourceDir/icons
$InstallPart/$TargetDir
68 if [[ $?
!= 0 ]] ; then
71 if [[ -f $InstallPart/$TargetDir/refind.conf
]] ; then
72 echo "Existing refind.conf file found; copying sample file as refind.conf-sample"
73 echo "to avoid collision."
75 cp -f $SourceDir/refind.conf-sample
$InstallPart/$TargetDir
76 if [[ $?
!= 0 ]] ; then
80 echo "Copying sample configuration file as refind.conf; edit this file to configure"
83 cp -f $SourceDir/refind.conf-sample
$InstallPart/$TargetDir/refind.conf
84 if [[ $?
!= 0 ]] ; then
92 # A series of OS X support functions....
95 # Mount the ESP at /Volumes/ESP or determine its current mount
97 # Sets InstallPart to the ESP mount point
98 # Sets UnmountEsp if we mounted it
100 # Identify the ESP. Note: This returns the FIRST ESP found;
101 # if the system has multiple disks, this could be wrong!
102 Temp
=`diskutil list | grep EFI`
103 Esp
=/dev
/`echo $Temp | cut -f 5 -d ' '`
104 # If the ESP is mounted, use its current mount point....
105 Temp
=`df | grep $Esp`
106 InstallPart
=`echo $Temp | cut -f 6 -d ' '`
107 if [[ $InstallPart == '' ]] ; then
108 mkdir
/Volumes
/ESP
&> /dev
/null
109 mount
-t msdos
$Esp /Volumes
/ESP
110 if [[ $?
!= 0 ]] ; then
111 echo "Unable to mount ESP! Aborting!\n"
115 InstallPart
="/Volumes/ESP"
119 # Control the OS X installation.
120 # Sets Problems=1 if problems found during the installation.
122 echo "Installing rEFInd on OS X...."
123 if [[ $1 == 'esp' ||
$1 == 'ESP' ]] ; then
128 echo "Installing rEFInd to the partition mounted at '$InstallPart'"
129 Platform
=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
131 if [[ $1 == 'esp' ||
$1 == 'ESP' ]] ; then
132 bless
--mount $InstallPart --setBoot --file $InstallPart/$TargetDir/$Refind
134 bless
--setBoot --folder $InstallPart/$TargetDir --file $InstallPart/$TargetDir/$Refind
136 if [[ $?
!= 0 ]] ; then
140 echo "WARNING: If you have an Advanced Format disk, *DO NOT* attempt to check the"
141 echo "bless status with 'bless --info', since this is known to cause disk corruption"
142 echo "on some systems!!"
148 # Now a series of Linux support functions....
151 # Identifies the ESP's location (/boot or /boot/efi); aborts if
152 # the ESP isn't mounted at either location.
153 # Sets InstallPart to the ESP mount point.
155 EspLine
=`df /boot/efi | grep boot`
156 InstallPart
=`echo $EspLine | cut -d " " -f 6`
157 EspFilesystem
=`grep $InstallPart /etc/mtab | cut -d " " -f 3`
158 if [[ $EspFilesystem != 'vfat' ]] ; then
159 echo "/boot/efi doesn't seem to be on a VFAT filesystem. The ESP must be mounted at"
160 echo "/boot or /boot/efi and it must be VFAT! Aborting!"
163 echo "ESP was found at $InstallPart using $EspFilesystem"
166 # Uses efibootmgr to add an entry for rEFInd to the EFI's NVRAM.
167 # If this fails, sets Problems=1
169 Efibootmgr
=`which efibootmgr 2> /dev/null`
170 if [[ $Efibootmgr ]] ; then
171 modprobe efivars
&> /dev
/null
172 InstallDisk
=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 1-8`
173 PartNum
=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 9-10`
174 EntryFilename
=$TargetDir/$Refind
175 EfiEntryFilename
=`echo ${EntryFilename//\//\\\}`
176 ExistingEntry
=`$Efibootmgr -v | grep $Refind`
177 if [[ $ExistingEntry ]] ; then
178 echo "An existing EFI boot manager entry for rEFInd seems to exist:"
180 echo "$ExistingEntry"
182 echo "This entry is NOT being modified, and no new entry is being created."
184 $Efibootmgr -c -l $EfiEntryFilename -L rEFInd
-d $InstallDisk -p $PartNum &> /dev
/null
185 if [[ $?
!= 0 ]] ; then
194 if [[ $EfibootmgrProblems ]] ; then
196 echo "ALERT: There were problems running the efibootmgr program! You may need to"
197 echo "rename the $Refind binary to the default name (EFI/boot/bootx64.efi"
198 echo "on x86-64 systems or EFI/boot/bootia32.efi on x86 systems) to have it run!"
203 # Controls rEFInd installation under Linux.
204 # Sets Problems=1 if something goes wrong.
206 echo "Installing rEFInd on Linux...."
209 if [[ $CpuType == 'x86_64' ]] ; then
211 elif [[ $CpuType == 'i386' ||
$CpuType == 'i486' ||
$CpuType == 'i586' ||
$CpuType == 'i686' ]] ; then
214 echo "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based"
215 echo "computers are VERY RARE. If you've installed a 32-bit version of Linux"
216 echo "on a 64-bit computer, you should manually install the 64-bit version of"
217 echo "rEFInd. If you're installing on a Mac, you should do so from OS X. If"
218 echo "you're positive you want to continue with this installation, answer 'Y'"
219 echo "to the following question..."
221 echo -n "Are you sure you want to continue (Y/N)? "
223 if [[ $ContYN == "Y" ||
$ContYN == "y" ]] ; then
224 echo "OK; continuing with the installation..."
229 echo "Unknown CPU type '$CpuType'; aborting!"
237 # The main part of the script. Sets a few environment variables,
238 # performs a few startup checks, and then calls functions to
239 # install under OS X or Linux, depending on the detected platform.
242 ThisScript
=`readlink -f $0`
244 SourceDir
=`dirname $ThisScript`/refind
246 if [[ `whoami` != "root" ]] ; then
247 echo "Not running as root; attempting to elevate privileges via sudo...."
249 if [[ $?
!= 0 ]] ; then
250 echo "This script must be run as root (or using sudo). Exiting!"
256 if [[ $OSName == 'Darwin' ]] ; then
258 elif [[ $OSName == 'Linux' ]] ; then
261 echo "Running on unknown OS; aborting!"
264 if [[ $Problems ]] ; then
267 echo "Installation has completed, but problems were detected. Review the output for"
268 echo "error messages and take corrective measures as necessary. You may need to"
269 echo "re-run this script or install manually before rEFInd will work."
273 echo "Installation has completed successfully."
277 if [[ $UnmountEsp ]] ; then