[HOWTO] How-to Boot Linux VMs using UEFI

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,176

Zwck

Patron
Joined
Oct 27, 2016
Messages
371
What's keeping you?
i tried it a couple times and it did not work :D

Whats keeping me is that the RancherOS.iso does not work with the implemented system. It works fine using Iohyve but doesnt work with the vm-behyve implentation in f11
 
Last edited:

Grinas

Contributor
Joined
May 4, 2017
Messages
174
Hey,

for anyone else getting permision denied on ubuntu. you must first active the root account. to do this use the following commands.

Code:
passwd root

enter a password

no enter root and create and copy the efi file.
Code:
su root

enter the password

Code:
mkdir /boot/efi/EFI/BOOT


Code:
cp /boot/efi/EFI/ubuntu/grubx64.efi /boot/efi/EFI/BOOT/bootx64.efi
 

Rybena

Dabbler
Joined
Jun 25, 2017
Messages
32
There have been a number of threads were people have failed to boot a Linux VM after the installation phase using the webUI of FreeNAS 11 nightly, finding themselves stuck in the EFI shell and not knowing how to proceed nor how to avoid this happening each time their VM is started.

It has been sugested elsewhere that this is due a grub error, or a grubx64.efi file which is missing or in the wrong place, or you must create a startup.nsh file or change the boot order in the EFI shell. If your Linux install depends on grub and it has completed successfully, creating the correct EFI partition (ESP) and grubx64.efi file, then none of these suggestions are correct.

Creating a VM via the webUI in FreeNAS 11 converts to a bhyve command in the backend, saving you from using a complex string of commands at the CLI e.g:

bhyve -c 4 -m 768M -HAP \
-s 0,hostbridge \
-s 3,ahci-cd,firmware-8.7.1-amd64-netinst.iso \
-s 4,ahci-hd,debianbox.img \
-s 5,virtio-net,tap1 \
-s 29,fbuf,tcp=0.0.0.0:5900,w=800,h=600,wait \
-s 31,lpc -l com1,stdio \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
debtest

The file /usr/local/share/uefi-firmware/BHYVE_UEFI.fd provides byve with the firmware to support UEFI guests, this function is based on the OVMF tianocore project which is also used as the basis of VirtualBox's virtual machine UEFI support. The bhyve UEFI firmware conforms to the known “Default Boot Behaviour” and looks for the file \EFI\BOOT\boot64.efi in the EFI partition of your VM. If it's not present you end up in the EFI shell.

One simple remedy is to create this \EFI\BOOT\boot64.efi file in your VM, which is straight forward once your VM has booted.

But how do you boot your VM if you find yourself in the EFI shell at first? Just type exit at the shell prompt, and in the EFI menu system navigate to "Boot Maintenance Manager" and then select "Boot from file" to locate and select your grubx64.efi file.

As root, cd to the /boot/efi/EFI directory of your VM in order to create the new BOOT directory and copy the existing grubx64.efi to /EFI/BOOT/bootx64.efi. The end result should look like this, using Ubuntu as an example:

root@ubuntu-vm:/boot/efi# tree -L 3 .
.
└── EFI
├── BOOT
│ └── bootx64.efi
└── ubuntu
├── fbx64.efi
├── grub.cfg
├── grubx64.efi
├── mmx64.efi
└── shimx64.efi

3 directories, 6 files
root@ubuntu-vm:/boot/efi#

The file bootx64.efi is a copy of the grubx64.efi in your VM.

NB: If grubx64.efi gets updated you will need to re-create bootx64.efi


Hi thanks for the guide.

I have followed the directions you gave as far as I'm aware but when I select to boot from the grubx64.efi file it boots into grub.

How do I log in as root?
 

Grinas

Contributor
Joined
May 4, 2017
Messages
174
Hi thanks for the guide.

I have followed the directions you gave as far as I'm aware but when I select to boot from the grubx64.efi file it boots into grub.

How do I log in as root?

read my post
 

british

Dabbler
Joined
Jan 23, 2012
Messages
25
Anyone got RHEL6.9 booting correctly? I tried copying the EFI executable as described, but didn't get a menu, only a grub shell.

Yes, I know 7 works fine, but for something I'm doing I require a 6.x

All the best !
 

british

Dabbler
Joined
Jan 23, 2012
Messages
25
Half a fix. When you get placed in the interactive shell type exit. Then choose "Boot Maintenance Manager" -> "Boot From File" -> Choose "No Volume Label" -> "EFI" -> "redhat" -> "grub.efi"

Now you can also add a boot entry if you wish, and change the boot order. I save the config but it seems to get wiped upon reboot or shutdown. Shame, thought I'd nailed it :-/
 

Stux

MVP
Joined
Jun 2, 2016
Messages
4,367
Half a fix. When you get placed in the interactive shell type exit. Then choose "Boot Maintenance Manager" -> "Boot From File" -> Choose "No Volume Label" -> "EFI" -> "redhat" -> "grub.efi"

Now you can also add a boot entry if you wish, and change the boot order. I save the config but it seems to get wiped upon reboot or shutdown. Shame, thought I'd nailed it :-/

As mentioned previously UEFI settings currently get lost across vm power cycles.
 

Shaheed Haque

Dabbler
Joined
Apr 9, 2017
Messages
12
I posted on a similar problem with making the grub-efi fix permanent. The answer, at least for me, lay in disabling secure-boot mode when running the Ubuntu-specific boot-repair tool.

As per https://forums.freenas.org/index.php?threads/how-to-boot-ubuntu-desktop-vm-in-uefi-mode.53863, the crucial missing step in my case was the need to disable Secure Boot in the boot-repair tool, which promptedme through a series of steps which replaced grub-<whatever> with grub-efi. This was different than before, where the boot-repair tool ran but did not result in a fix which worked across both reboots/power-cycles.

Thanks, Shaheed
 

SoftvalMedia

Cadet
Joined
Jul 9, 2017
Messages
3
Thx, i had the same problem on debian 9. The problem it's that you need to be creating that folder for every VM. :confused:
 

NetSoerfer

Explorer
Joined
May 8, 2016
Messages
57
There have been a number of threads were people have failed to boot a Linux VM after the installation phase using the webUI of FreeNAS 11 nightly, finding themselves stuck in the EFI shell and not knowing how to proceed nor how to avoid this happening each time their VM is started.
I would suggest putting this into the FreeNAS documentation - it is both fairly common and pretty difficult to troubleshoot for someone unfamiliar with how the EFI boot process works (which is hardly required for FreeNAS operation).
 

NetSoerfer

Explorer
Joined
May 8, 2016
Messages
57
The file /usr/local/share/uefi-firmware/BHYVE_UEFI.fd provides byve with the firmware to support UEFI guests, this function is based on the OVMF tianocore project which is also used as the basis of VirtualBox's virtual machine UEFI support. The bhyve UEFI firmware conforms to the known “Default Boot Behaviour” and looks for the file \EFI\BOOT\boot64.efi in the EFI partition of your VM. If it's not present you end up in the EFI shell.

One simple remedy is to create this \EFI\BOOT\boot64.efi file in your VM, which is straight forward once your VM has booted.

The file names are wrong - should be bootx64.efi. (they're correct in the direction listing below that passage.)
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,176
To think that none of this would be an issue if GRUB followed the UEFI spec.

Though, to be fair, bhyve could support the storage GRUB uses for its nonstandard behavior and solve the issue.
 

KrisBee

Wizard
Joined
Mar 20, 2017
Messages
1,288
The file names are wrong - should be bootx64.efi. (they're correct in the direction listing below that passage.)
A typo, Guilty as charged. Anyone can do it, like 'direction ' instead of 'directory'. :)
 

NetSoerfer

Explorer
Joined
May 8, 2016
Messages
57
Ha! Touché :D Goes to show not just that I should read the whole thing before acting on it (that had me quite confused for a while), but that I should read my own stuff as well :p
 

Ir13h

Dabbler
Joined
Mar 3, 2017
Messages
32
Can anyone help with this arch-anywhere install? I am not sure its the same problem as the op is talking about but I don't know enough to know for sure. I am using this iso https://arch-anywhere.org/# which lets me enable uefi and then choose either grub or systemd or syslinux as the bootloader. I have tried with uefi enabled and disabled and tried all of the bootloader options and always end up in the same state (see gif). after the install I can chroot into the installed os console and see my users home directory and navigate around etc but when I reboot the same thing always happens just a blinking cursor. Any ideas?
http://g.recordit.co/YuHs5k7jYo.gif

video might help so you guys can pause instead of gif http://recordit.co/YuHs5k7jYo
 

RobKamp

Dabbler
Joined
Dec 29, 2011
Messages
26
In what way is this fix not permanent?
It is not permanent as for every ubuntu install we have to do a copy of this grubx64.efi to bootx64.efi and for every update for Grub as well. So not permanent at all.

I suggest to hold update of grub using
Code:
sudo apt-mark hold grub
. This will stop the update grub when using apt-get update && apt-get upgrade.
 

RobKamp

Dabbler
Joined
Dec 29, 2011
Messages
26
I would suggest putting this into the FreeNAS documentation - it is both fairly common and pretty difficult to troubleshoot for someone unfamiliar with how the EFI boot process works (which is hardly required for FreeNAS operation).
I suggest ubuntu change their EFI boot to the standard.
 

Shaheed Haque

Dabbler
Joined
Apr 9, 2017
Messages
12
I suggest ubuntu change their EFI boot to the standard.

Rob,

The solution I posted on Jul 10, reply #49, seems to work as a permanent fix for me. The resulting files under the /boot/efi tree look like this (sorry about the formatting):


$ ls -lR /boot/efi
/boot/efi:
total 4
drwxr-xr-x 5 root root 4096 Jul 8 10:12 EFI

/boot/efi/EFI:
total 12
drwxr-xr-x 2 root root 4096 Jul 10 12:11 Boot
drwxr-xr-x 3 root root 4096 Jul 8 10:12 Microsoft
drwxr-xr-x 3 root root 4096 Jun 29 12:09 ubuntu

/boot/efi/EFI/Boot:
total 120
-rwxr-xr-x 1 root root 121856 Jul 10 12:11 bootx64.efi
-rwxr-xr-x 1 root root 0 Jul 10 12:11 bootx64.efi.grb

/boot/efi/EFI/Microsoft:
total 4
drwxr-xr-x 2 root root 4096 Jul 10 12:11 Boot

/boot/efi/EFI/Microsoft/Boot:
total 240
-rwxr-xr-x 1 root root 121856 Jul 10 12:11 bootmgfw.efi
-rwxr-xr-x 1 root root 0 Jul 10 12:11 bootmgfw.efi.grb
-rwxr-xr-x 1 root root 121856 Jul 10 12:11 bootx64.efi
-rwxr-xr-x 1 root root 0 Jul 10 12:11 bootx64.efi.grb

/boot/efi/EFI/ubuntu:
total 2484
drwxr-xr-x 2 root root 4096 Jun 29 12:08 fw
-rwxr-xr-x 1 root root 65544 Jun 29 12:08 fwupx64.efi
-rwxr-xr-x 1 root root 126 Jul 8 10:32 grub.cfg
-rwxr-xr-x 1 root root 122368 Jul 29 22:08 grubx64.efi
-rwxr-xr-x 1 root root 1168464 Jul 8 10:32 mmx64.efi
-rwxr-xr-x 1 root root 1169992 Jul 8 10:32 shimx64.efi

/boot/efi/EFI/ubuntu/fw:
total 0


I did not have to manipulate any files by hand.

Hth, Shaheed
 
Top