]> code.delx.au - refind/blobdiff - refind-install
Merge branch 'master' of ssh://git.code.sf.net/p/refind/code
[refind] / refind-install
index cd9b07b1dfe7e0f5575f5dae468e676ff8e19ae9..6f2f7134c287c735a8318cc72120be3e3a830153 100755 (executable)
 #
 # Revision history:
 #
 #
 # Revision history:
 #
-# 0.9.3   -- Enable running under OS X's recovery system & add warning about
+# 0.10.1  -- Improve extraction of default kernel options from /proc/cmdline.
+#            Add support for AMD64 (aka AARCH64, aa64) platform.
+# 0.10.0  -- Enable running under OS X's recovery system & add warning about
 #            SIP & brief instructions on how to deal with it if SIP is
 #            SIP & brief instructions on how to deal with it if SIP is
-#            detected to be enabled.
+#            detected to be enabled. Also change way refind_linux.conf default
+#            options are found; use /proc/cmdline as base.
 # 0.9.2   -- Added --keepname option.
 # 0.8.7   -- Better detection of Secure Boot mode & fixed errors when copying
 #            Shim & MokManager files over themselves; fixed bug that caused
 # 0.9.2   -- Added --keepname option.
 # 0.8.7   -- Better detection of Secure Boot mode & fixed errors when copying
 #            Shim & MokManager files over themselves; fixed bug that caused
@@ -167,11 +170,11 @@ GetParams() {
       echo "or --preloader! Aborting!"
       exit 1
    fi
       echo "or --preloader! Aborting!"
       exit 1
    fi
-   if [[ "$KeepName" == 1 && "$OSTYPE" != "linux-gnu" ]] ; then
+   if [[ "$KeepName" == 1 && "$OSTYPE" != "linux" && "$OSTYPE" != "linux-gnu" ]] ; then
       echo "The --keepname option is valid only under Linux! Aborting!"
       exit 1
    fi
       echo "The --keepname option is valid only under Linux! Aborting!"
       exit 1
    fi
-   if [[ "$KeepName" == 1 && "$TargetDir" != "/EFI/BOOT" ]] ; then
+   if [[ "$KeepName" == 1 && "$TargetDir" == "/EFI/BOOT" ]] ; then
       echo "The --keepname option is incompatible with --usedefault! Aborting!"
       exit 1
    fi
       echo "The --keepname option is incompatible with --usedefault! Aborting!"
       exit 1
    fi
@@ -191,16 +194,93 @@ ReadYesNo() {
    fi
 }
 
    fi
 }
 
+# Determine what CPU type and EFI bit depth we're using.
+# Sets Platform global variable to lowercase EFI platform code (currently
+# "x64", "ia32", or "aa64") -- the same code used in filenames.
+DeterminePlatform() {
+   local CpuType
+   case "$OSTYPE" in
+   darwin*)
+      CpuType=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
+      if [[ "$CpuType" == EFI32 ]] ; then
+         Platform="ia32"
+      else
+         Platform="x64"
+      fi
+      ;;
+   linux*)
+      CpuType=`uname -m`
+      case "$CpuType" in
+      aarch64)
+         Platform="aa64"
+         ;;
+      x86_64)
+         Platform="x64"
+         ;;
+      i?86)
+         Platform="ia32"
+         # If we're in EFI mode, do some sanity checks, and alert the user or even
+         # abort. Not in BIOS mode, though, since that could be used on an emergency
+         # disc to try to recover a troubled Linux installation.
+         if [[ -d /sys/firmware/efi ]] ; then
+            if [[ "$ShimSource" != "none" && "$TargetDir" != "/BOOT/EFI" ]] ; then
+               echo ""
+               echo "CAUTION: shim does not currently supports 32-bit systems, so you should not"
+               echo "use the --shim option to install on such systems. Aborting!"
+               echo ""
+               exit 1
+            fi
+            echo
+            echo "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based"
+            echo "computers are VERY RARE. If you've installed a 32-bit version of Linux"
+            echo "on a 64-bit computer, you should manually install the 64-bit version of"
+            echo "rEFInd. If you're positive you want to continue with this installation,"
+            echo "answer 'Y' to the following question..."
+            echo
+            echo -n "Are you sure you want to continue (Y/N)? "
+            ReadYesNo
+            if [[ $YesNo == "Y" || $YesNo == "y" ]] ; then
+               echo "OK; continuing with the installation..."
+            else
+               exit 0
+            fi
+         fi # In EFI mode
+         ;;
+      *)
+         echo "Unknown CPU type '$CpuType'; aborting!"
+         exit 1
+         ;;
+      esac # case "$CpuType"....
+      ;;
+   *)
+      echo "Unknown OS; aborting!"
+      exit 1
+      ;;
+   esac # case "$OSTYPE"....
+} # DeterminePlatform()
+
 # Abort if the rEFInd files can't be found.
 # Also sets $ConfFile to point to the configuration file,
 # Abort if the rEFInd files can't be found.
 # Also sets $ConfFile to point to the configuration file,
-# $IconsDir to point to the icons directory, and
-# $ShimSource to the source of the shim.efi file (if necessary).
+# $IconsDir to point to the icons directory,
+# $ShimSource to the source of the shim.efi file (if necessary),
+# $ThisDir to point to the directory in which this script resides,
+# and $RefindDir to point to where the rEFInd binaries live
 CheckForFiles() {
 CheckForFiles() {
-   # Note: This check is satisfied if EITHER the 32- or the 64-bit version
-   # is found, even on the wrong platform. This is because the platform
-   # hasn't yet been determined. This could obviously be improved, but it
-   # would mean restructuring lots more code....
-   if [[ ! -f "$RefindDir/refind_ia32.efi" && ! -f "$RefindDir/refind_x64.efi" ]] ; then
+   # Note: $ThisDir points to real (not symlinked) script home on Linux,
+   # enabling creating a symlink in /usr/sbin (or wherever); but on OS X,
+   # "readlink" doesn't do the same thing as under Linux, so the script
+   # must not be a symlink under OS X.
+   case "$OSTYPE" in
+      darwin*)
+           ThisDir="$( cd -P "${BASH_SOURCE%/*}" && pwd )"
+           ;;
+      linux*)
+           ThisDir="$(dirname "$(readlink -f "$0")")"
+           ;;
+   esac
+   RefindDir="$ThisDir/refind"
+
+   if [[ ! -f "$RefindDir/refind_$Platform.efi" ]] ; then
       echo "The rEFInd binary file is missing! Aborting installation!"
       exit 1
    fi
       echo "The rEFInd binary file is missing! Aborting installation!"
       exit 1
    fi
@@ -228,6 +308,7 @@ CheckForFiles() {
       if [[ -f "$ShimSource" ]] ; then
          if [[ $ShimType == "shimx64.efi" || $ShimType == "shim.efi" ]] ; then
             TargetX64="grubx64.efi"
       if [[ -f "$ShimSource" ]] ; then
          if [[ $ShimType == "shimx64.efi" || $ShimType == "shim.efi" ]] ; then
             TargetX64="grubx64.efi"
+            TargetAARCH64="grubaa64.efi"
             MokManagerSource=`dirname "$ShimSource"`/MokManager.efi
          elif [[ $ShimType == "preloader.efi" || $ShimType == "PreLoader.efi" ]] ; then
             TargetX64="loader.efi"
             MokManagerSource=`dirname "$ShimSource"`/MokManager.efi
          elif [[ $ShimType == "preloader.efi" || $ShimType == "PreLoader.efi" ]] ; then
             TargetX64="loader.efi"
@@ -284,9 +365,11 @@ SetVarsForBoot() {
    if [[ $ShimSource == "none" ]] ; then
       TargetX64="bootx64.efi"
       TargetIA32="bootia32.efi"
    if [[ $ShimSource == "none" ]] ; then
       TargetX64="bootx64.efi"
       TargetIA32="bootia32.efi"
+      TargetAARCH64="bootaa64.efi"
    else
    else
-      if [[ $ShimType == "shim.efi" || $ShimType == "shimx64.efi" ]] ; then
+      if [[ $ShimType == "shim.efi" || $ShimType == "shimx64.efi" || $ShimType = "shimaa64.efi" ]] ; then
          TargetX64="grubx64.efi"
          TargetX64="grubx64.efi"
+         TargetAARCH64="grubaa64.efi"
       elif [[ $ShimType == "preloader.efi" || $ShimType == "PreLoader.efi" ]] ; then
          TargetX64="loader.efi"
       else
       elif [[ $ShimType == "preloader.efi" || $ShimType == "PreLoader.efi" ]] ; then
          TargetX64="loader.efi"
       else
@@ -295,7 +378,7 @@ SetVarsForBoot() {
          exit 1
       fi
       TargetIA32="bootia32.efi"
          exit 1
       fi
       TargetIA32="bootia32.efi"
-      TargetShim="bootx64.efi"
+      TargetShim="boot$Platform.efi"
    fi
    if [[ $KeepName == 1 ]] ; then
       echo "Installation is to /EFI/BOOT, which is incompatible with --keepname! Aborting!"
    fi
    if [[ $KeepName == 1 ]] ; then
       echo "Installation is to /EFI/BOOT, which is incompatible with --keepname! Aborting!"
@@ -309,9 +392,11 @@ SetVarsForMsBoot() {
    if [[ $ShimSource == "none" ]] ; then
       TargetX64="bootmgfw.efi"
       TargetIA32="bootmgfw.efi"
    if [[ $ShimSource == "none" ]] ; then
       TargetX64="bootmgfw.efi"
       TargetIA32="bootmgfw.efi"
+      TargetAARCH64="bootmgfw.efi"
    else
    else
-      if [[ $ShimType == "shim.efi" || $ShimType == "shimx64.efi" ]] ; then
+      if [[ $ShimType == "shim.efi" || $ShimType == "shimx64.efi" || $ShimType == "shimaa64.efi" ]] ; then
          TargetX64="grubx64.efi"
          TargetX64="grubx64.efi"
+         TargetAARCH64="grubaa64.efi"
       elif [[ $ShimType == "preloader.efi" || $ShimType == "PreLoader.efi" ]] ; then
          TargetX64="loader.efi"
       else
       elif [[ $ShimType == "preloader.efi" || $ShimType == "PreLoader.efi" ]] ; then
          TargetX64="loader.efi"
       else
@@ -353,6 +438,7 @@ DetermineTargetDir() {
       if [[ $ShimSource == "none" || $KeepName == 1 ]] ; then
          TargetX64="refind_x64.efi"
          TargetIA32="refind_ia32.efi"
       if [[ $ShimSource == "none" || $KeepName == 1 ]] ; then
          TargetX64="refind_x64.efi"
          TargetIA32="refind_ia32.efi"
+         TargetAARCH64="refind_aa64.efi"
       fi
       Upgrade=1
    fi
       fi
       Upgrade=1
    fi
@@ -398,13 +484,11 @@ DetermineTargetDir() {
 # Determine (or guess) the filesystem used on the Linux /boot filesystem.
 # Store the result in the BootFS global variable.
 SetBootFS() {
 # Determine (or guess) the filesystem used on the Linux /boot filesystem.
 # Store the result in the BootFS global variable.
 SetBootFS() {
-   local Blkid
-
    BootFS=""
    case "$OSTYPE" in
    BootFS=""
    case "$OSTYPE" in
-      linux-gnu)
-           if command -v blkid 2>/dev/null; then
-              BootPart=`df /boot | grep dev | cut -f 1 -d " "`
+      linux*)
+           if command -v blkid &>/dev/null; then
+              BootPart=`df $RootDir/boot | grep dev | cut -f 1 -d " "`
               BootFS=`blkid -o export $BootPart 2> /dev/null | grep TYPE= | cut -f 2 -d =`
            fi
            ;;
               BootFS=`blkid -o export $BootPart 2> /dev/null | grep TYPE= | cut -f 2 -d =`
            fi
            ;;
@@ -489,6 +573,10 @@ CopyRefindFiles() {
       if [[ $? != 0 ]] ; then
          Problems=1
       fi
       if [[ $? != 0 ]] ; then
          Problems=1
       fi
+      cp "$RefindDir/refind_aa64.efi" "$InstallDir/$TargetDir/$TargetAARCH64" 2> /dev/null
+      if [[ $? != 0 && $Platform == "aa64" ]] ; then
+         Problems=1
+      fi
       if [[ "$ShimSource" != "none" ]] ; then
          TargetShim="bootx64.efi"
          CopyShimFiles
       if [[ "$ShimSource" != "none" ]] ; then
          TargetShim="bootx64.efi"
          CopyShimFiles
@@ -497,22 +585,12 @@ CopyRefindFiles() {
          cp -r "$RefindDir"/drivers_* "$InstallDir/$TargetDir/" 2> /dev/null
          cp -r "$ThisDir"/drivers_* "$InstallDir/$TargetDir/" 2> /dev/null
       elif [[ $Upgrade == 1 || $InstallToEspOnMac == 1 ]] ; then
          cp -r "$RefindDir"/drivers_* "$InstallDir/$TargetDir/" 2> /dev/null
          cp -r "$ThisDir"/drivers_* "$InstallDir/$TargetDir/" 2> /dev/null
       elif [[ $Upgrade == 1 || $InstallToEspOnMac == 1 ]] ; then
-         if [[ $Platform == 'EFI64' ]] ; then
-            CopyDrivers x64
-            CopyTools x64
-         else
-            CopyDrivers ia32
-            CopyTools ia32
-         fi
-      fi
-      Refind=""
-      if [[ $Platform == 'EFI64' ]] ; then
-         Refind='bootx64.efi'
-      elif [[ $Platform == 'EFI32' ]] ; then
-         Refind='bootia32.efi'
+         CopyDrivers "$Platform"
+         CopyTools "$Platform"
       fi
       fi
+      Refind="boot$Platform.efi"
       CopyKeys
       CopyKeys
-   elif [[ $Platform == 'EFI64' || $TargetDir == "/EFI/Microsoft/Boot" ]] ; then
+   elif [[ $Platform == 'x64' || $TargetDir == "/EFI/Microsoft/Boot" ]] ; then
       cp "$RefindDir/refind_x64.efi" "$InstallDir/$TargetDir/$TargetX64"
       if [[ $? != 0 ]] ; then
          Problems=1
       cp "$RefindDir/refind_x64.efi" "$InstallDir/$TargetDir/$TargetX64"
       if [[ $? != 0 ]] ; then
          Problems=1
@@ -537,14 +615,21 @@ CopyRefindFiles() {
       if [[ "$TargetDir" == '/System/Library/CoreServices' ]] ; then
          SetupMacHfs $TargetX64
       fi
       if [[ "$TargetDir" == '/System/Library/CoreServices' ]] ; then
          SetupMacHfs $TargetX64
       fi
-   elif [[ $Platform == 'EFI32' ]] ; then
-      cp "$RefindDir/refind_ia32.efi" "$InstallDir/$TargetDir/$TargetIA32"
-      if [[ $? != 0 ]] ; then
-         Problems=1
+   elif [[ $Platform == 'ia32' || $Platform == 'aa64' ]] ; then
+      if [[ $Platform == 'ia32' ]] ; then
+         cp "$RefindDir/refind_ia32.efi" "$InstallDir/$TargetDir/$TargetIA32"
+         if [[ $? != 0 ]] ; then
+            Problems=1
+         fi
+      else
+         cp "$RefindDir/refind_aa64.efi" "$InstallDir/$TargetDir/$TargetAARCH64"
+         if [[ $? != 0 ]] ; then
+            Problems=1
+         fi
       fi
       fi
-      CopyDrivers ia32
-      CopyTools ia32
-      Refind="refind_ia32.efi"
+      CopyDrivers $Platform
+      CopyTools $Platform
+      Refind="refind_$Platform.efi"
       if [[ "$TargetDir" == '/System/Library/CoreServices' ]] ; then
          SetupMacHfs $TargetIA32
       fi
       if [[ "$TargetDir" == '/System/Library/CoreServices' ]] ; then
          SetupMacHfs $TargetIA32
       fi
@@ -607,7 +692,7 @@ MountDefaultTarget() {
       else
          mount -t msdos "$TargetPart" "$InstallDir"
       fi
       else
          mount -t msdos "$TargetPart" "$InstallDir"
       fi
-   elif [[ $OSTYPE == linux-gnu ]] ; then
+   elif [[ $OSTYPE == linux* ]] ; then
       mount -t vfat "$TargetPart" "$InstallDir"
    fi
    if [[ $? != 0 ]] ; then
       mount -t vfat "$TargetPart" "$InstallDir"
    fi
    if [[ $? != 0 ]] ; then
@@ -691,7 +776,7 @@ SetupMacHfs() {
         <key>ProductName</key>
         <string>rEFInd</string>
         <key>ProductVersion</key>
         <key>ProductName</key>
         <string>rEFInd</string>
         <key>ProductVersion</key>
-        <string>0.9.2</string>
+        <string>0.10.0</string>
 </dict>
 </plist>
 ENDOFHERE
 </dict>
 </plist>
 ENDOFHERE
@@ -699,7 +784,8 @@ ENDOFHERE
 
 CheckForSIP() {
    if [[ -x "/usr/bin/csrutil" ]] ; then
 
 CheckForSIP() {
    if [[ -x "/usr/bin/csrutil" ]] ; then
-      local OKToInstall=`/usr/bin/csrutil status | grep "Protection status: enabled (Custom Configuration\|Apple Internal)"`
+      local OKToInstall=`/usr/bin/csrutil status | \
+                         grep "Protection status: disabled\|enabled (Apple Internal)\|NVRAM Protections: disabled"`
       if [[ -z "$OKToInstall" ]] ; then
          echo
          echo "**** ALERT: SIP ENABLED! ****"
       if [[ -z "$OKToInstall" ]] ; then
          echo
          echo "**** ALERT: SIP ENABLED! ****"
@@ -760,8 +846,8 @@ InstallOnOSX() {
    echo "Installing rEFInd to the partition mounted at $InstallDir"
    DetermineTargetDir
    CheckForSIP
    echo "Installing rEFInd to the partition mounted at $InstallDir"
    DetermineTargetDir
    CheckForSIP
-   Platform=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
    CopyRefindFiles
    CopyRefindFiles
+   cp "$ThisDir/mountesp" /usr/local/bin &> /dev/null
    if [[ $InstallToEspOnMac == "1" ]] ; then
       bless --mount "$InstallDir" --setBoot --file "$InstallDir/$TargetDir/$Refind" --shortform
    elif [[ "$TargetDir" != "/EFI/BOOT" ]] ; then
    if [[ $InstallToEspOnMac == "1" ]] ; then
       bless --mount "$InstallDir" --setBoot --file "$InstallDir/$TargetDir/$Refind" --shortform
    elif [[ "$TargetDir" != "/EFI/BOOT" ]] ; then
@@ -783,11 +869,6 @@ InstallOnOSX() {
          echo "Not deleting rEFItBlesser."
       fi
    fi
          echo "Not deleting rEFItBlesser."
       fi
    fi
-   echo
-   echo "WARNING: If you have an Advanced Format disk, *DO NOT* attempt to check the"
-   echo "bless status with 'bless --info', since this is known to cause disk corruption"
-   echo "on some systems!!"
-   echo
 } # InstallOnOSX()
 
 
 } # InstallOnOSX()
 
 
@@ -928,18 +1009,18 @@ ReSignBinaries() {
       exit 1
    fi
    GenerateKeys
       exit 1
    fi
    GenerateKeys
-   mkdir -p "$TempDir/drivers_x64"
+   mkdir -p "$TempDir/drivers_$Platform"
    cp "$RefindDir/refind.conf-sample $TempDir" 2> /dev/null
    cp "$ThisDir/refind.conf-sample $TempDir" 2> /dev/null
    cp "$RefindDir/refind_ia32.efi $TempDir" 2> /dev/null
    cp -a "$RefindDir/drivers_ia32 $TempDir" 2> /dev/null
    cp -a "$ThisDir/drivers_ia32 $TempDir" 2> /dev/null
    cp "$RefindDir/refind.conf-sample $TempDir" 2> /dev/null
    cp "$ThisDir/refind.conf-sample $TempDir" 2> /dev/null
    cp "$RefindDir/refind_ia32.efi $TempDir" 2> /dev/null
    cp -a "$RefindDir/drivers_ia32 $TempDir" 2> /dev/null
    cp -a "$ThisDir/drivers_ia32 $TempDir" 2> /dev/null
-   SignOneBinary "$RefindDir/refind_x64.efi" "$TempDir/refind_x64.efi"
+   SignOneBinary "$RefindDir/refind_$Platform.efi" "$TempDir/refind_$Platform.efi"
    SaveIFS=$IFS
    IFS=$(echo -en "\n\b")
    SaveIFS=$IFS
    IFS=$(echo -en "\n\b")
-   for Driver in `ls "$RefindDir"/drivers_x64/*.efi "$ThisDir"/drivers_x64/*.efi 2> /dev/null` ; do
+   for Driver in `ls "$RefindDir"/drivers_$Platform/*.efi "$ThisDir"/drivers_$Platform/*.efi 2> /dev/null` ; do
       TempName=`basename "$Driver"`
       TempName=`basename "$Driver"`
-      SignOneBinary "$Driver" "$TempDir/drivers_x64/$TempName"
+      SignOneBinary "$Driver" "$TempDir/drivers_$Platform/$TempName"
    done
    IFS=$SaveIFS
    RefindDir="$TempDir"
    done
    IFS=$SaveIFS
    RefindDir="$TempDir"
@@ -1059,8 +1140,9 @@ AddBootEntry() {
    if [[ $EfibootmgrProblems ]] ; then
       echo
       echo "ALERT: There were problems running the efibootmgr program! You may need to"
    if [[ $EfibootmgrProblems ]] ; then
       echo
       echo "ALERT: There were problems running the efibootmgr program! You may need to"
-      echo "rename the $Refind binary to the default name (EFI/boot/bootx64.efi"
-      echo "on x86-64 systems or EFI/boot/bootia32.efi on x86 systems) to have it run!"
+      echo "rename the $Refind binary to the default name (EFI/BOOT/bootx64.efi"
+      echo "on x86-64 systems, EFI/BOOT/bootia32.efi on x86 systems, or"
+      echo "EFI/BOOT/bootaa64.efi on ARM64 systems) to have it run!"
       echo
    else
       echo "rEFInd has been set as the default boot manager."
       echo
    else
       echo "rEFInd has been set as the default boot manager."
@@ -1073,11 +1155,6 @@ GenerateRefindLinuxConf() {
       echo "Existing $RLConfFile found; not overwriting."
    else
       echo "Creating $RLConfFile; edit it to adjust kernel options."
       echo "Existing $RLConfFile found; not overwriting."
    else
       echo "Creating $RLConfFile; edit it to adjust kernel options."
-      if [[ -f "$RootDir/etc/default/grub" ]] ; then
-         # We want the default options used by the distribution, stored here....
-         source "$RootDir/etc/default/grub"
-         echo "Setting default boot options based on $RootDir/etc/default/grub"
-      fi
       RootFS=`df "$RootDir" | grep dev | cut -f 1 -d " "`
       StartOfDevname=`echo "$RootFS" | cut -b 1-7`
       if [[ "$StartOfDevname" == "/dev/sd" || "$StartOfDevName" == "/dev/hd" ]] ; then
       RootFS=`df "$RootDir" | grep dev | cut -f 1 -d " "`
       StartOfDevname=`echo "$RootFS" | cut -b 1-7`
       if [[ "$StartOfDevname" == "/dev/sd" || "$StartOfDevName" == "/dev/hd" ]] ; then
@@ -1087,10 +1164,24 @@ GenerateRefindLinuxConf() {
             RootFS="$Uuid"
          fi
       fi
             RootFS="$Uuid"
          fi
       fi
-      DefaultOptions="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
-      echo "\"Boot with standard options\"        \"ro root=$RootFS $DefaultOptions \"" > $RLConfFile
-      echo "\"Boot to single-user mode\"          \"ro root=$RootFS $DefaultOptions single\"" >> $RLConfFile
-      echo "\"Boot with minimal options\"         \"ro root=$RootFS\"" >> $RLConfFile
+      if [[ $RootDir == "/" ]] ; then
+         local FirstCmdlineOption=`cat /proc/cmdline | cut -d ' ' -f 1`
+         if [[ "$FirstCmdlineOption" =~ (vmlinuz|bzImage|kernel) ]] ; then
+            DefaultOptions=`cat /proc/cmdline | cut -d ' ' -f 2- | sed 's/\S*initrd=\S*//g' | sed 's/ *$//' | sed 's/^ *//'`
+         else
+            DefaultOptions=`cat /proc/cmdline | sed 's/\S*initrd=\S*//g' | sed 's/ *$//' | sed 's/^ *//'`
+         fi
+      else
+         if [[ -f "$RootDir/etc/default/grub" ]] ; then
+            # We want the default options used by the distribution, stored here....
+            source "$RootDir/etc/default/grub"
+            echo "Setting default boot options based on $RootDir/etc/default/grub"
+         fi
+         DefaultOptions="ro root=$RootFS $GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
+      fi
+      echo "\"Boot with standard options\"  \"$DefaultOptions\"" > $RLConfFile
+      echo "\"Boot to single-user mode\"    \"$DefaultOptions single\"" >> $RLConfFile
+      echo "\"Boot with minimal options\"   \"ro root=$RootFS\"" >> $RLConfFile
    fi
 }
 
    fi
 }
 
@@ -1109,42 +1200,6 @@ InstallOnLinux() {
       FindMountedESP
       DetermineTargetDir
    fi
       FindMountedESP
       DetermineTargetDir
    fi
-   CpuType=`uname -m`
-   if [[ $CpuType == 'x86_64' ]] ; then
-      Platform="EFI64"
-   elif [[ ($CpuType == 'i386' || $CpuType == 'i486' || $CpuType == 'i586' || $CpuType == 'i686') ]] ; then
-      Platform="EFI32"
-      # If we're in EFI mode, do some sanity checks, and alert the user or even
-      # abort. Not in BIOS mode, though, since that could be used on an emergency
-      # disc to try to recover a troubled Linux installation.
-      if [[ -d /sys/firmware/efi ]] ; then
-         if [[ "$ShimSource" != "none" && "$TargetDir" != "/BOOT/EFI" ]] ; then
-            echo ""
-            echo "CAUTION: shim does not currently supports 32-bit systems, so you should not"
-            echo "use the --shim option to install on such systems. Aborting!"
-            echo ""
-            exit 1
-         fi
-         echo
-         echo "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based"
-         echo "computers are VERY RARE. If you've installed a 32-bit version of Linux"
-         echo "on a 64-bit computer, you should manually install the 64-bit version of"
-         echo "rEFInd. If you're installing on a Mac, you should do so from OS X. If"
-         echo "you're positive you want to continue with this installation, answer 'Y'"
-         echo "to the following question..."
-         echo
-         echo -n "Are you sure you want to continue (Y/N)? "
-         ReadYesNo
-         if [[ $YesNo == "Y" || $YesNo == "y" ]] ; then
-            echo "OK; continuing with the installation..."
-         else
-            exit 0
-         fi
-      fi # in EFI mode
-   else
-      echo "Unknown CPU type '$CpuType'; aborting!"
-      exit 1
-   fi
 
    if [[ $LocalKeys == 1 ]] ; then
       ReSignBinaries
 
    if [[ $LocalKeys == 1 ]] ; then
       ReSignBinaries
@@ -1164,8 +1219,6 @@ InstallOnLinux() {
 # install under OS X or Linux, depending on the detected platform.
 #
 GetParams "$@"
 # install under OS X or Linux, depending on the detected platform.
 #
 GetParams "$@"
-ThisDir="$( cd -P "${BASH_SOURCE%/*}" && pwd )"
-RefindDir="$ThisDir/refind"
 if [[ $UID != 0 ]] ; then
    echo "Not running as root; attempting to elevate privileges via sudo...."
    sudo "$BASH_SOURCE" "$@"
 if [[ $UID != 0 ]] ; then
    echo "Not running as root; attempting to elevate privileges via sudo...."
    sudo "$BASH_SOURCE" "$@"
@@ -1176,6 +1229,7 @@ if [[ $UID != 0 ]] ; then
       exit 0
    fi
 fi
       exit 0
    fi
 fi
+DeterminePlatform
 CheckForFiles
 case "$OSTYPE" in
    darwin*)
 CheckForFiles
 case "$OSTYPE" in
    darwin*)
@@ -1189,7 +1243,7 @@ case "$OSTYPE" in
         fi
         InstallOnOSX $1
         ;;
         fi
         InstallOnOSX $1
         ;;
-   linux-gnu)
+   linux*)
         InstallOnLinux
         ;;
    *)
         InstallOnLinux
         ;;
    *)
@@ -1215,7 +1269,14 @@ fi
 
 if [[ $UnmountEsp == '1' ]] ; then
    echo "Unmounting install dir"
 
 if [[ $UnmountEsp == '1' ]] ; then
    echo "Unmounting install dir"
-   umount $InstallDir
+   case "$OSTYPE" in
+   darwin*)
+      diskutil unmount $InstallDir
+      ;;
+   *)
+      umount $InstallDir
+      ;;
+   esac
 fi
 
 if [[ "$InstallDir" == /tmp/refind_install ]] ; then
 fi
 
 if [[ "$InstallDir" == /tmp/refind_install ]] ; then