#
# Revision history:
#
-# 0.5.2 -- Changed --drivers to --alldrivers and added --nodrivers option;
+# 0.6.1 -- Added --root option; minor bug fixes
+# 0.6.0 -- Changed --drivers to --alldrivers and added --nodrivers option;
# changed default driver installation behavior in Linux to install
# the driver needed to read /boot (if available)
# 0.5.1.2 -- Fixed bug that caused failure to generate refind_linux.conf file
# Note: install.sh version numbers match those of the rEFInd package
# with which they first appeared.
+RootDir="/"
TargetDir=/EFI/refind
-EtcKeysDir=/etc/refind.d/keys
LocalKeysBase="refind_local"
-RLConfFile="/boot/refind_linux.conf"
ShimSource="none"
TargetX64="refind_x64.efi"
TargetIA32="refind_ia32.efi"
TargetIA32="bootia32.efi"
shift
;;
+ --root) RootDir=$2
+ shift
+ ;;
--localkeys) LocalKeys=1
;;
--shim) ShimSource=$2
;;
--nodrivers) InstallDrivers="none"
;;
- * ) echo "Usage: $0 [--esp | --usedefault {device-file}] [--nodrivers | --alldrivers] "
- echo " [--shim {shim-filename}] [--localkeys]"
+ * ) echo "Usage: $0 [--esp | --usedefault {device-file} | --root {directory} ]"
+ echo " [--nodrivers | --alldrivers] [--shim {shim-filename}]"
+ echo " [--localkeys]"
exit 1
esac
shift
done
+
if [[ $InstallToEspOnMac == 1 && $TargetDir == '/EFI/BOOT' ]] ; then
echo "You may use --esp OR --usedefault, but not both! Aborting!"
exit 1
fi
-# exit 1
+ if [[ $RootDir != '/' && $TargetDir == '/EFI/BOOT' ]] ; then
+ echo "You may use --usedefault OR --root, but not both! Aborting!"
+ exit 1
+ fi
+ if [[ $RootDir != '/' && $InstallToEspOnMac == 1 ]] ; then
+ echo "You may use --root OR --esp, but not both! Aborting!"
+ exit 1
+ fi
+
+ RLConfFile="$RootDir/boot/refind_linux.conf"
+ EtcKeysDir="$RootDir/etc/refind.d/keys"
} # GetParams()
# Abort if the rEFInd files can't be found.
# Copy the public keys to the installation medium
CopyKeys() {
if [[ $LocalKeys == 1 ]] ; then
- cp $EtcKeysDir/$LocalKeysBase.cer $InstallDir/$TargetDir
- cp $EtcKeysDir/$LocalKeysBase.crt $InstallDir/$TargetDir
- else
- cp $ThisDir/refind.cer $InstallDir/$TargetDir
- cp $ThisDir/refind.crt $InstallDir/$TargetDir
+ mkdir -p $InstallDir/$TargetDir/keys/
+ cp $EtcKeysDir/$LocalKeysBase.cer $InstallDir/$TargetDir/keys/
+ cp $EtcKeysDir/$LocalKeysBase.crt $InstallDir/$TargetDir/keys/
+# else
+# cp $ThisDir/refind.cer $InstallDir/$TargetDir/keys/
+# cp $ThisDir/refind.crt $InstallDir/$TargetDir/keys/
fi
} # CopyKeys()
BootFS=`blkid -o export $BootPart 2> /dev/null | grep TYPE= | cut -f 2 -d =`
DriverType=""
case $BootFS in
- ext2 | ext3) DriverType="ext2"
+ ext2 | ext3 | ext4) DriverType="ext4"
;;
reiserfs) DriverType="reiserfs"
;;
hfsplus) DriverType="hfs"
;;
+ *) BootFS=""
esac
if [[ -n $BootFS ]] ; then
echo "Installing driver for $BootFS (${DriverType}_$1.efi)"
if [[ $LocalKeys == 0 ]] ; then
echo "Storing copies of rEFInd Secure Boot public keys in $EtcKeysDir"
mkdir -p $EtcKeysDir
- cp $ThisDir/refind.cer $EtcKeysDir
- cp $ThisDir/refind.crt $EtcKeysDir
+ cp $ThisDir/keys/refind.cer $EtcKeysDir
+ cp $ThisDir/keys/refind.crt $EtcKeysDir
fi
fi
else
if [[ $? != 0 ]] ; then
Problems=1
fi
+ cp -rf $ThisDir/keys $InstallDir/$TargetDir/
if [[ -f $InstallDir/$TargetDir/refind.conf ]] ; then
echo "Existing refind.conf file found; copying sample file as refind.conf-sample"
echo "to avoid overwriting your customizations."
elif [[ $InstallToEspOnMac == "1" ]] ; then
MountOSXESP
else
- InstallDir="/"
+ InstallDir="$RootDir/"
fi
echo "Installing rEFInd to the partition mounted at '$InstallDir'"
Platform=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
# appropriate options haven't been set, warn the user and offer to abort.
# If we're NOT in Secure Boot mode but the user HAS specified the --shim
# or --localkeys option, warn the user and offer to abort.
+#
+# FIXME: Although I checked the presence (and lack thereof) of the
+# /sys/firmware/efi/vars/SecureBoot* files on my Secure Boot test system
+# before releasing this script, I've since found that they are at least
+# sometimes present when Secure Boot is absent. This means that the first
+# test can produce false alarms. A better test is highly desirable.
CheckSecureBoot() {
VarFile=`ls -d /sys/firmware/efi/vars/SecureBoot* 2> /dev/null`
if [[ -n $VarFile && $TargetDir != '/EFI/BOOT' && $ShimSource == "none" ]] ; then
echo ""
- echo "CAUTION: The computer seems to have been booted with Secure Boot active, but"
- echo "you haven't specified a valid shim.efi file source. The resulting installation"
- echo "will not boot unless you disable Secure Boot. You may continue, but you should"
- echo "consider using --shim to specify a working shim.efi file. You can read more"
- echo "about this topic at http://www.rodsbooks.com/refind/secureboot.html."
+ echo "CAUTION: Your computer appears to support Secure Boot, but you haven't"
+ echo "specified a valid shim.efi file source. If you've disabled Secure Boot and"
+ echo "intend to leave it disabled, this is fine; but if Secure Boot is active, the"
+ echo "resulting installation won't boot. You can read more about this topic at"
+ echo "http://www.rodsbooks.com/refind/secureboot.html."
echo ""
echo -n "Do you want to proceed with installation (Y/N)? "
read ContYN
cp $RefindDir/refind_ia32.efi $TempDir
cp -a $RefindDir/drivers_ia32 $TempDir 2> /dev/null
cp -a $ThisDir/drivers_ia32 $TempDir 2> /dev/null
- SignOneBinary $RefindDir/refind_x64.efi $ThisDir/refind_x64.efi
+ SignOneBinary $RefindDir/refind_x64.efi $TempDir/refind_x64.efi
for Driver in `ls $RefindDir/drivers_x64/*.efi $ThisDir/drivers_x64/*.efi 2> /dev/null` ; do
TempName=`basename $Driver`
SignOneBinary $Driver $TempDir/drivers_x64/$TempName
DeleteRefindDir=1
}
-# Identifies the ESP's location (/boot or /boot/efi); aborts if
-# the ESP isn't mounted at either location.
+# Identifies the ESP's location (/boot or /boot/efi, or these locations under
+# the directory specified by --root); aborts if the ESP isn't mounted at
+# either location.
# Sets InstallDir to the ESP mount point.
FindLinuxESP() {
- EspLine=`df /boot/efi | grep boot`
+ EspLine=`df $RootDir/boot/efi 2> /dev/null | grep boot/efi`
+ if [[ ! -n $EspLine ]] ; then
+ EspLine=`df $RootDir/boot | grep boot`
+ fi
InstallDir=`echo $EspLine | cut -d " " -f 6`
- EspFilesystem=`grep $InstallDir /etc/mtab | cut -d " " -f 3`
+ if [[ -n $InstallDir ]] ; then
+ EspFilesystem=`grep $InstallDir /etc/mtab | cut -d " " -f 3`
+ fi
if [[ $EspFilesystem != 'vfat' ]] ; then
- echo "/boot/efi doesn't seem to be on a VFAT filesystem. The ESP must be mounted at"
- echo "/boot or /boot/efi and it must be VFAT! Aborting!"
+ echo "$RootDir/boot/efi doesn't seem to be on a VFAT filesystem. The ESP must be"
+ echo "mounted at $RootDir/boot or $RootDir/boot/efi and it must be VFAT! Aborting!"
exit 1
fi
echo "ESP was found at $InstallDir using $EspFilesystem"
# Create a minimal/sample refind_linux.conf file in /boot.
GenerateRefindLinuxConf() {
if [[ ! -f $RLConfFile ]] ; then
- if [[ -f /etc/default/grub ]] ; then
+ if [[ -f "$RootDir/etc/default/grub" ]] ; then
# We want the default options used by the distribution, stored here....
- source /etc/default/grub
+ source "$RootDir/etc/default/grub"
fi
- RootFS=`df / | grep dev | cut -f 1 -d " "`
+ RootFS=`df $RootDir | grep dev | cut -f 1 -d " "`
StartOfDevname=`echo $RootFS | cut -b 1-7`
if [[ $StartOfDevname == "/dev/sd" || $StartOfDevName == "/dev/hd" ]] ; then
# Identify root filesystem by UUID rather than by device node, if possible