4

I'm working on a MacBook Air, that's currently booting to macOS High Sierra 10.13.6. It also has an Ubuntu 16.04 partition, that I am currently trying to reach.

I was trying reinstall rEFInd, which due to SIP is done from the recovery partition. It failed because;

-bash: ./refind-install: /usr/bin/env: bad interpreter: No such file or directory

Which was thrown by the #!/usr/bin/env bash at the top of the install script.

I had a look and indeed there is no /usr/bin/env in my recovery partition. There is one on the main partition. This is the terminal in the recovery partition:

[-bash-3.2# ls /usr/bin/env
ls: /usr/bin/env: No such file or directory
[-bash-3.2# ls /Volumes/Macintosh\ HD/usr/bin/env
/Volumes/Macintosh\ HD/usr/bin/env

Now the end goal it to reinstall rEFInd (I had it before, but updating macOS changed the boot order so it no longer boots correctly), but my question right now is: Is it normal to not have /usr/bin/env in the recovery partition?

The fact that the rEFInd script expects it to be there makes me wonder if I have broken something.

3

Is it normal to not have /usr/env/bin in the recovery partition?

Yes, it's perfectly normal for /usr/bin/env to not be in the recovery partition.

If you were to mount the Recovery partition and open the BaseSystem.dmg container to search for the file, you'll find that it doesn't exist.

$ diskutil list

 #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                    209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh              999.3 GB   disk0s2
   3:                 Apple_Boot Recovery HD            650.0 MB   

So, disk0s3 is the one we want to mount

$ sudo mkdir /Volumes/RecoveryHD
$ sudo mount -t HFS /Volumes/RecoveryHD

Now, open the recovery system image BaseSystem.dmg.

$ open /Volumes/RecoveryHD/com.apple.recovery.boot/BaseSystem.dmg

A GUI will pop up on the screen with a Finder window.

Finder Window

Traverse to the /usr/bin and you'll notice that env is not there.

enter image description here

It's important to remember that the Recovery partition is a slimmed down version of the actual base system. To make rEFInd work correctly, it needs to be done on the boot partition, not from the recovery partition. So, in the end, you didn't mess anything up.

2
  • Both answers were excellent and taught me things I didn't know about working with the partitions in my computer. I'm accepting this one because it answers the question in the title, and so it's probably what future readers will be looking for. – Clumsy cat Jul 26 '18 at 9:44
  • According to rodsbooks.com/refind/sip.html it's recommended to install rEFInd from the recovery partition if SIP is enabled. – Victor Tran Nov 22 '18 at 1:33
3

Many commands are missing when booted to the Recovery partition. If the macOS, you normally boot to, is in good order, then you can restore access to the missing commands by following the instructions given below.

You can access the missing commands by updating the PATH variable. To do this you will need to know the name of the macOS startup disk. The steps are given below.

  1. Determine the name of your startup disk for macOS. While booted to macOS, select →About this Mac from the menu bar. The startup disk name will be displayed on the popup window. On my Mac, the name is Marlin.
  2. Boot to the Recovery partition.
  3. Open a Terminal window.
  4. Enter the commands given below. Replace Marlin with the name of your startup disk.

    RT="/Volumes/Marlin"
    readonly OLDPATH=$PATH
    export PATH=$OLDPATH:$RT/usr/local/bin:$RT/usr/bin:$RT/bin:$RT/usr/sbin:$RT/sbin
    

In your case, /usr/bin/env is an absolute path, so updating the PATH variable will not remove the error message. However, you can manually select the bash shell and then execute the script.

Instead of using

./refind-install

you could have used

bash
. refind-install
exit

or

bash
source refind-install
exit

Note: I omitted any necessary arguments to refind-install.

The Best Advice for Your Situation

In your case, you would be better off avoiding any additional absolute paths to commands that might exist in the refind-install script. The best way to do this would be to boot to the Recovery partition and execute the following command. This will disable System Integrity Protection (SIP).

csrutil disable

You then can boot back to macOS and run the refind-install script. To enable SIP, enter the following command, then reboot your Mac.

csrutil clear
3
  • Thank you for this advice, disabling SIP worked very well and the script ran as intended. I wish I could accept both answers, as they both gave very useful information. – Clumsy cat Jul 26 '18 at 9:43
  • 1
    Why csrutil clear and not csrutil enable? – Harald Hanche-Olsen Jul 26 '18 at 12:53
  • 1
    @Harald Hanche-Olsen: To enter csrutil enable, you would have to boot back to the Recovery partition, enter the command, then boot back to macOS. The command csrutil clear can be entered from macOS and only requires a reboot. Basically, this is a time saver. – David Anderson Jul 26 '18 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .