Bug 278984 - Debian 12 won't boot in UEFI mode
Summary: Debian 12 won't boot in UEFI mode
Status: Closed Not A Bug
Alias: None
Product: Base System
Classification: Unclassified
Component: bhyve (show other bugs)
Version: 13.2-RELEASE
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-virtualization (Nobody)
URL:
Keywords: bhyve
Depends on:
Blocks:
 
Reported: 2024-05-14 16:22 UTC by Vurefozu
Modified: 2024-05-23 06:16 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vurefozu 2024-05-14 16:22:25 UTC
Hi.
If you install Debian 12 on bhyve from an iso image in UEFI mode, you will notice that the grub boot loader will not be found.

To fix this you need to do the following:
mkdir /boot/efi/EFI/BOOT/
# copy file - workaround for bhyve grub package #
# Pay attention to destination file bootx64.efi #
cp /boot/efi/EFI/debian/grubx64.efi /boot/efi/EFI/BOOT/bootx64.efi

Taken here: https://www.cyberciti.biz/faq/how-to-install-linux-vm-on-freebsd-using-bhyve-and-zfs/

I suggest fixing bhyve so that it tries to load not only /boot/efi/EFI/BOOT/bootx64.efi, but also /boot/efi/EFI/debian/grubx64.efi.
Comment 1 Ed Maste freebsd_committer freebsd_triage 2024-05-14 17:03:21 UTC
Please try with FreeBSD 14.0 or later - have a look at the details in https://github.com/churchers/vm-bhyve/issues/336
Comment 2 mario felicioni 2024-05-14 20:02:23 UTC
(In reply to Ed Maste from comment #1)

I'm using FreeBSD 14 and I have that problem. And nope,I don't use vm-bhyve and I don't like it. I prefer to use the raw bhyve parameters. That bug is well known and it exists since years. I never understood if it belongs to Debian or to FreeBSD...in any case I would like to see it fixed,but I don't want to be forced to use vm-bhyve to use the fix.
Comment 3 Ed Maste freebsd_committer freebsd_triage 2024-05-14 20:16:12 UTC
(In reply to mario felicioni from comment #2)
You don't have to use vm-bhyve, I just linked to that thread as it has some relevant information.

Are you passing a BHYVE_UEFI_VARS.fd file via bhyve's -l argument?
Comment 4 mario felicioni 2024-05-14 20:33:35 UTC
Usually I use this template :

bhyve -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s 1,ahci-hd,/bhyve/debian12-test1/Debian.img,bootindex=1 \
-s 13,virtio-net,tap4 \
-s 14,virtio-9p,sharename=/ \
-s 29,fbuf,tcp=0.0.0.0:5904,w=1600,h=950,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd \
vm0:4 < /dev/null & sleep 2 && vncviewer 0:4
Comment 5 Ed Maste freebsd_committer freebsd_triage 2024-05-14 23:27:08 UTC
(In reply to mario felicioni from comment #4)
Yes you need to pass a BHYVE_UEFI_VARS.fd file for the nvram variables to persist.
Comment 6 Vurefozu 2024-05-18 11:47:08 UTC
(In reply to Ed Maste from comment #1)
Thx.
Comment 7 mario felicioni 2024-05-18 12:07:39 UTC
How can I pass a BHYVE_UEFI_VARS.fd file ? Is this correct ?

bhyve -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s 1,ahci-hd,/bhyve/debian12-test1/Debian.img,bootindex=1 \
-s 13,virtio-net,tap4 \
-s 14,virtio-9p,sharename=/ \
-s 29,fbuf,tcp=0.0.0.0:5904,w=1600,h=950,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd \
-l bootrom,/usr/local/share/edk2-bhyve/BHYVE_UEFI_VARS.fd \
vm0:4 < /dev/null & sleep 2 && vncviewer 0:4
Comment 8 mario felicioni 2024-05-18 12:10:48 UTC
oh sorry,maybe the correct file is on /usr/local/share/uefi-firmware. So :

bhyve -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s 1,ahci-hd,/bhyve/debian12-test1/Debian.img,bootindex=1 \
-s 13,virtio-net,tap4 \
-s 14,virtio-9p,sharename=/ \
-s 29,fbuf,tcp=0.0.0.0:5904,w=1600,h=950,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd \
vm0:4 < /dev/null & sleep 2 && vncviewer 0:4

I doubt that it is correct...
Comment 9 Vurefozu 2024-05-20 08:08:03 UTC
(In reply to mario felicioni from comment #8)

I found this option, but haven't tested it yet
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd,BHYVE_UEFI_VARS.fd
Comment 10 mario felicioni 2024-05-20 08:38:42 UTC
Somewhere I read that you can chain BHYVE_UEFI_CODE.fd and BHYVE_UEFI_VARS.fd into one only file.
Comment 11 mario felicioni 2024-05-20 20:05:55 UTC
Please read here :

https://www.digitalfoundations.com.au/blog/macos-on-windows-with-qemu/

at a certain point,he explains how to combine OVMF_VARS.fd + OVMF_CODE.fd :

copy /B OVMF_VARS.fd + OVMF_CODE.fd OVMF_combined.fd

so,what about to do :

copy /B BHYVE_UEFI_VARS.fd + BHYVE_UEFI_CODE.fd BHYVE_combined.fd

(in Windows)

and then :

bhyve -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s 1,ahci-hd,/bhyve/debian12-test1/Debian.img,bootindex=1 \
-s 13,virtio-net,tap4 \
-s 14,virtio-9p,sharename=/ \
-s 29,fbuf,tcp=0.0.0.0:5904,w=1600,h=950,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_combined.fd \
vm0:4 < /dev/null & sleep 2 && vncviewer 0:4

please try and let me know if it works.
Comment 12 Vurefozu 2024-05-21 19:49:53 UTC
(In reply to mario felicioni from comment #11)

After connecting via VNC it crashes.

# bhyve -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s 1,ahci-hd,/vm/vm/debian12-test2/disk0.img,bootindex=1 \
-s 29,fbuf,tcp=0.0.0.0:5900,w=1600,h=950,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/vm/vm/debian12-test2/BHYVE_combined.fd \
guest
fbuf frame buffer base: 0x29db7a200000 [sz 16777216]
vm exit[0]
        reason          VMX
        rip             0x000000000000039d
        inst_length     2
        status          0
        exit_reason     2 (Triple fault)
        qualification   0x0000000000000000
        inst_type               0
        inst_error              0
Abort trap

# uname -a
FreeBSD home 13.2-RELEASE-p11 FreeBSD 13.2-RELEASE-p11 releng/13.2-n254665-f5ac4e174fdd MYGENERIC amd64
Comment 13 Vurefozu 2024-05-21 19:50:16 UTC
cat /usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd > BHYVE_combined.fd
cat /usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd >> BHYVE_combined.fd
Comment 14 Ed Maste freebsd_committer freebsd_triage 2024-05-21 20:15:22 UTC
Based on the original report I assumed copying grubx64.efi to bootx64.efi gave you a working system - is that assumption wrong (or, did you not try connecting with VNC previously)?
Comment 15 mario felicioni 2024-05-21 20:28:21 UTC
That's how it can be fixed. But the problem is not fixed in that way if you don't develop something that looks like a patch.
Comment 16 Ed Maste freebsd_committer freebsd_triage 2024-05-21 21:08:01 UTC
(In reply to mario felicioni from comment #15)
No, it appears there are two problems being reported here and I want to make sure I understand correctly.

For the "UEFI variables don't persist" issue copying grubx64.efi to bootx64.efi is a workaround. That issue is fixed by passing appropriate parameters to the bhyve invocation. There's no patch for this issue, because there's no bug to fix.
Comment 17 mario felicioni 2024-05-21 21:46:46 UTC
I disagree. Debian is the only distro that does not boot automatically as soon as it is installed. You can grab any other linux distro and you will see that after the installation it can boot without any manual intervention.
Comment 18 Ed Maste freebsd_committer freebsd_triage 2024-05-21 23:37:39 UTC
(In reply to mario felicioni from comment #17)
It seems Debian requires persistent variables, while other distros install a fallback efi/boot/bootx64.efi. The fix for this is to provide correct commandline parameters to persist UEFI environment variables.
Comment 19 Vurefozu 2024-05-22 05:07:06 UTC
(In reply to Ed Maste from comment #14)
> did you not try connecting with VNC previously
Yes you are right. I fixed this problem. But to reproduce the problem I need Debian12 from /boot/efi/EFI/debian/grubx64.efi not to boot.

Can you please tell me how to log into UEFI to change the settings?
You wrote that you can also pass parameters, but how to pass them?
Comment 20 mario felicioni 2024-05-22 07:19:48 UTC
(In reply to Ed Maste from comment #18)

Sure,but you haven't explained how to pass both the parameters. Please give a look at comment #7 and #11. At the moment both of them don't work.
Comment 21 Vurefozu 2024-05-22 08:35:37 UTC
(In reply to mario felicioni from comment #20)
I myself don’t know how to do this correctly.
But if you look at the official man bhyve - https://man.freebsd.org/cgi/man.cgi?query=bhyve&sektion=8&format=html

then the correct option is:

-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd,BHYVE_UEFI_VARS.fd
Comment 22 odhiambo@gmail.com 2024-05-22 12:52:08 UTC
(In reply to Vurefozu from comment #21)
Of course you know that the 2nd file will give a not found error, no?
Comment 23 mario felicioni 2024-05-22 13:19:48 UTC
(In reply to Vurefozu from comment #21)

I've just tried. I've used these parameters :

bhyve -S -c sockets=2,cores=2,threads=2 -m 4G -w -H -A \
-s 0,hostbridge \
-s 1,ahci-hd,/mnt/zroot-133/bhyve/img/Linux/Debian.img,bootindex=1 \
-s 13,virtio-net,tap1 \
-s 14,virtio-9p,sharename=/ \
-s 29,fbuf,tcp=0.0.0.0:5901,w=1600,h=950,wait \
-s 30,xhci,tablet \
-s 31,lpc \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd,BHYVE_UEFI_VARS.fd \
vm0:1 < /dev/null & sleep 2 && vncviewer 0:1

I see only this message :

fbuf frame buffer base: 0x2ed80000000 [sz 16777216]

so,the vm tried to boot,but then it exits.
Comment 24 Vurefozu 2024-05-22 13:22:05 UTC
(In reply to odhiambo@gmail.com from comment #22)

In man bhyve they write this:

> Run a UEFI virtual  machine  with a VARS file to save	EFI variables.
> Note that bhyve will write guest modifications to the given VARS file.
> Be sure to create a per-guest copy of the template VARS file from /usr.

You must first copy the file /usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd to the directory with the guest virtual machine.

But I can’t figure out how to launch the UEFI menu to select the desired file and save the setting.
Comment 25 mario felicioni 2024-05-22 16:27:33 UTC
---> You must first copy the file /usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd to the directory with the guest virtual machine.

My BHYVE_UEFI_VARS.fd file is on /usr/local/share/uefi-firmware ; is this wrong ?
Comment 26 mario felicioni 2024-05-22 16:29:54 UTC
In man bhyve they write this:

> Run a UEFI virtual  machine  with a VARS file to save	EFI variables.
> Note that bhyve will write guest modifications to the given VARS file.
> Be sure to create a per-guest copy of the template VARS file from /usr.

For me it's not clear what should I do.
Comment 27 Vurefozu 2024-05-22 16:30:25 UTC
(In reply to mario felicioni from comment #25)

Apparently it's not correct.
From man bhyve (https://man.freebsd.org/cgi/man.cgi?query=bhyve&sektion=8&format=html):
> Be sure to create a per-guest copy of the template VARS file from /usr.
Comment 28 Vurefozu 2024-05-22 16:31:38 UTC
(In reply to mario felicioni from comment #26)

> For me it's not clear what should I do.
cp /usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd .
Comment 29 mario felicioni 2024-05-22 16:45:46 UTC
https://ibb.co/c8cx9wZ

I'm trying to boot a Debian img file that I've created with qemu and that it boots if I use qemu. I imagine that I should create a new Debian vm from scratch if I want to boot it with bhyve,right ?
Comment 30 Vurefozu 2024-05-22 17:21:46 UTC
(In reply to mario felicioni from comment #29)

To continue the discussion, I created a topic on the forum - https://forums.freebsd.org/threads/debian-12-wont-boot-in-uefi-mode.93529/
I suggest continuing the discussion there.
Comment 31 Corvin Köhne freebsd_committer freebsd_triage 2024-05-23 06:16:57 UTC
You have to copy the file /usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd to any location you want. Then you have to pass that copy to bhyve with:

-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CODE.fd,BHYVE_UEFI_VARS.fd

Replace BHYVE_UEFI_VARS.fd with the full (or correct relative) path to your copy of the VARS file.

When installing Debian, more precisely grub, it creates an EFI boot entry pointing to /EFI/debian/grubx64.efi. Boot entries are saved as EFI VARS. If you haven't passed a VARS file to bhyve when installing Debian, this information is lost after reboot. For already installed VM's you either have to reinstall grub or create a new boot entry on your own:

efibootmgr --create --disk <boot-disk> --part <boot-partition> --loader /EFI/debian/grubx64.efi --label <pick-a-name>

Note that your boot partition is commonly mounted at /boot/efi on Debian. Therefore, the path to the loader is just /EFI/debian/grubx64.efi.

Btw. Qemu is able to use a seperate EFI CODE and EFI VARS files too. So, if you want to create your VM image with Qemu, use seperate files for CODE and VARS. Then reuse the VARS file when booting bhyve and everything should work as expected.

I'm closing this bug report as it's already fixed.