I've been migrating from my old Intel Mac to a new M3 Mac, which uses ARM64 instead of x64 architecture. I ran into a strange error message when I tried to run a Packer build that used VirtualBox as its provider:
==> Starting the virtual machine... ==> Waiting 10s for boot... ==> Typing the boot command... ==> Error running boot command: VBoxManage error: VBoxManage: error: Failed to send a scancode.
Manually trying to type in the virtual machine window triggered an error notification from VirtualBox:
Keyboard failure
Failed to change keyboard parameter.
The console is not powered up (putScancodes).
Result Code: E_ACCESSDENIED (0x80070005)
Component: KeyboardWrap
Interface: IKeyboard {755e6bdf-1640-41f9-bd74-3ef5fd653250}
I couldn't find any relevant posts online about these errors, but given this build worked with an identical configuration on my x64 Mac and Windows hosts, I assumed the problem was related to the architecture change.
Finding the culprit
The "access denied" error code immediately made me suspicious that macOS's privacy settings were interfering with VirtualBox's ability to read keyboard input. However, the system hadn't prompted me about any attempted access, and I had given VirtualBox fairly permissive access already.
I started troubleshooting by manually creating a test VM in VirtualBox with all of the default hardware settings. I booted into the installation ISO I was using for the build, and keyboard input worked right away. This hinted that some hardware setting in my build configuration differed from VirtualBox's defaults, and that setting was likely responsible for the problem.
When you create a new VM within VirtualBox, it defaults to using a virtual USB 3.0 (xHCI) controller. Conversely, Packer's VirtualBox plug-in natively configures a pretty sparse machine that doesn't even enable USB by default. To mimic the build configuration, I disabled USB on the test VM, and switched the emulated pointing device from its default "USB Tablet" setting to "PS/2 Mouse" — and on my next boot, I was greeted by the same "Keyboard failure" error as earlier. Interesting!
The fix
For VirtualBox running on macOS with Apple Silicon (ARM64) hardware, "Keyboard failure" errors can potentially be fixed by enabling USB 3.0 on the VM. It seems to specifically require USB 3.0, as my VM still wasn't registering keyboard input when I tried with USB 1.1 and USB 2.0.
Additionally, if the mouse isn't working (such as in the Ubuntu graphical installer), the pointing device may need to be set to "USB Tablet". I noticed that if the pointing device was set to "PS/2 Mouse" (which the Packer plugin uses by default), mouse input wouldn't work in the guest host unless the VirtualBox guest additions were installed.
I was able to fix my Packer build with the following additions to my virtualbox-iso
source block. Note, the iso_interface
option isn't related to this
issue, but is necessary for booting ISOs on ARM64.
source "virtualbox-iso" "base" {
# Required for booting ISOs on EFI / ARM64
iso_interface = "sata"
# Use USB 3.0 and 'USB Tablet' pointing device
vboxmanage = [
[ "modifyvm", "{{ .Name }}", "--usb-xhci=on"],
[ "modifyvm", "{{ .Name }}", "--mouse", "usbtablet" ]
]
}