How to get out of EFI shell in virtual box

I am running a virtual machine for Mac OSX and it always boots into EFI shell, I just want a simple explanation of what this is and how, if possible, to exit it.


Solution 1:

The EFI shell is a command-line tool similar in concept to bash in Linux/Unix/OS X or a Command Prompt window in Windows. It lets you view, delete, edit, and rename files, to update EFI boot manager entries, and so on. You can exit from the shell by typing exit; however, in the case of VirtualBox, this will probably bring you to an EFI menu that can be just as confusing.

If you've installed an OS in your VirtualBox session, chances are it installed a boot loader on the EFI System Partition (ESP). Most OSes register these boot loaders with the firmware, which remembers them and boots them automatically. One quirk of VirtualBox is that it usually forgets these boot manager entries. The result is that the VM boots up into the EFI shell by default. There are several ways to deal with this problem, including:

  • You can launch the boot loader manually by using the EFI shell:
    1. Type fs0: to access the first filesystem, which is usually the ESP.
    2. Type cd EFI\{osname}, where {osname} is the name of the directory where your OS installed its boot loader. (You haven't said what OS you've installed, so I can't be sure what that is. Typing ls EFI will show you what's there.)
    3. Launch the boot loader by typing its name. Again, I can't know what that is. For Linux, it's usually grubx64.efi. For Windows, it's bootmgfw.efi.
  • Automate the above procedure with an EFI shell startup script (startup.nsh in the root directory of the ESP).
  • Rename the boot loader to EFI\BOOT\bootx64.efi, which is the fallback filename:
    1. Type fs0: to access the first filesystem, which is usually the ESP.
    2. Type mv EFI\{osname} EFI\BOOT to rename the directory in which the boot loader resides. As above, you'll have to determine what {osname} is yourself.
    3. Type mv EFI\BOOT\{loadername.efi} EFI\BOOT\bootx64.efi, where {loadername.efi} is the boot loader's name, such as grubx64.efi for most Linux installations.
  • Register the boot loader with the VirtualBox firmware by using the shell's tools. I don't know of a concise description of how to do this on the web, offhand, and I don't have time to write it up here. It's likely to be frustrating without precise instructions because there are a lot of non-obvious pitfalls you must avoid.

Personally, the solution I most often use is to rename the boot loader from the OS's default to EFI\BOOT\bootx64.efi. This is the easiest to implement and it works well enough. One drawback to this approach is that if your OS ever updates the boot loader, the update will probably go to the original location, so you'll have to repeat the process if you want to use the updated boot loader.