Page 1 of 1

How to get the boot device on UEFI?

Posted: Wed Feb 05, 2020 6:50 am
by ilmmatias
Hello everyone, until now, I had been hardcoding the boot device to be the first CD/DVD (when no boot device is specified on the configuration file), but now I want to get the boot device in the right way, for CD/DVD and USB boot.
How exactly should I do this?

Re: How to get the boot device on UEFI?

Posted: Wed Feb 05, 2020 7:03 am
by zhiayang
if i am not mistaken, you can get the DeviceHandle from your LoadedImageProtocol; then, the volume that you are booted from should have that handle as well.

you can get handles using bs->LocateHandleBuffer(...).

Re: How to get the boot device on UEFI?

Posted: Wed Feb 05, 2020 11:40 am
by kzinti
zhiayang is correct, you can obtain the boot device handle from the LoadedImageProtocol:

Code: Select all

    extern "C" EFI_STATUS efi_main(EFI_HANDLE hImage, EFI_SYSTEM_TABLE* systemTable)
    {
        // Get access to the boot file system
        EFI_LOADED_IMAGE_PROTOCOL* image;
        status = BS->HandleProtocol(hImage, &efiLoadedImageProtocolGuid, (void**)&image);
Then the boot device handle is at "image->DeviceHandle".