November 22, 2019

Install Debian on VirtualBox enabling UEFI (English)

I installed Debian Buster on VirtualBox and had trouble with UEFI then.

I am not a specialist for UEFI, so I don’t think it is the best way. But anyway, I succeeded to boot the Debian VM now.

(Probably you have the same trouble using ubuntu.)

What is UEFI?

UEFI is a new standard specification to replace BIOS.

BIOS is a specification for a program on the motherboard. CPU first run BIOS on boot, and BIOS kickstarts the OS.

However, BIOS is so old that it is not always suitable for recent hardware. So Intel proposed EFI (Extensible Firmware Interface) in 1999, and UEFI (Unified Extensible Firmware Interface) was decided based on EFI in 2005.

How to enable UEFI on VirtualBox

After creating a new VM, open VM settings and check the UEFI in motherboard tab in the system page.

Then, install the OS as usual.

(Don’t forget to create a partition for UEFI.)

What is the problem?

Installing the OS is OK. The problem is, Debian won’t start once after turning off the power. (Reboot is OK because it won’t turn off the hardware.)

In my case, Debian created directory /EFI/debian in the UEFI partition, and put kickstart program there, however, it seems that VirtualBox search only /EFI/boot/bootx64.efi for the program.

Debian behavior seems quite natural for me for multi boot machine. I suspect VirtualBox violates UEFI specification.

I should have created a patch because both VirtualBox and Debian are open source; however, I focused just to manage the problem.

After installing Debian and turning on the power, I saw the following screen.

As the “Mapping table” shows, the motherboard detects only 1 filesystem (FS0) and 3 other partitions (BLK0, BLK1, and BLK3.)

I don’t know what are BLK0, 1, 3. Probably BLK0 is CD/DVD drive and BLK3 is ‘/’ partition for Debian. (BLK1 is the end of the SATA controller???)

Anyway, the motherboard does not understand what they are. So FS0 is the UEFI partition undoubtedly.

UEFI shell resembles bash. command help shows the list of all commands.

Shell> help

First of all, let’s go to directory /EFI. Type as follows.

Shell> fs0:
fs0:\> cd EFI

Command fs0: specifies the partition to use. Either FS0: or fs0: is OK. (Don’t forget the last :.) Command cd is same to bash.

Then, make directory /EFI/boot and copy the files from /EFI/debian to /EFI/boot.

fs0:\EFI\> mkdir boot
fs0:\EFI\> cd debian
fs0:\EFI\debian\> cp grubx64.efi ../boot/bootx64.efi
fs0:\EFI\debian\> cp grub.cfg ../boot

Commands mkdir boot and cd debian are the same to bash. I went to directory debian to enable filename completion. (Pushing [tab] button after cp grub., then the shell complete the extension cfg if I was in the same directory to file grub.cfg.)

Command cp <src> <dst> is also same to bash. grubx64.efi is the kickstart program Debian created. It must be rename bootx64.efi. grub.cfg is a configuration file. It must be the same directory to the program.

That’s all. Debian will start after the switching power supply. It is a good idea to stop the power from the VirtualBox manager, however, reset command can do the same thing.

fs0:\EFI\debian\> reset

In my case, debian started successfully then.