Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Booting raw-disk windows 10 vm in virtualbox boots to grub shell

I have a dual-boot setup with Windows 10 and Kubuntu 18. Following instructions found from here and there I managed to get the Windows to run as guest in Kubuntu host as a VM using VirtualBox.

sudo usermod -a -G disk $USER
VBoxManage internalcommands createrawvmdk -filename "/path/to/vm/win10.vmdk" -rawdisk /dev/sda -partitions 1,3,4 -relative

The first line is to avoid running VirtualBox as superuser.
When I boot the VM, I briefly see an error message

Boot Failed. EFI DVD/CDROM
SystemBootOrder not found. Initializing defaults.
Creating boot entry "Boot0003" with label "ubuntu" for file "\EFI\ubuntu\shimx64.efi"

and then end up in grub shell. Now, when I run the commands

insmod chain
set root=(hd0,gpt1)
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
boot

Windows boots and works just fine but entering these every time is not exactly smooth workflow. Any idea how to permanently fix this? Please note that I'd still like to be able to physically boot into both OS's.

Thanks,

like image 543
runs on clozapine Avatar asked Jun 29 '18 12:06

runs on clozapine


1 Answers

I had the same problem. I fixed it, but then updated my kernel and so grub re-un-fixed it for me! Figuring it out for the second time was quicker, but I figured it'd be even quicker next time to find my answer on StackOverflow!

My grub.cfg file in /boot/efi/EFI/ubuntu looked like this:

search.fs_uuid 47d6233f-c0ae-4f89-bf18-184452eac803 root hd0,gpt6
set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg

Because we have setup the VirtualBox vmdk file with only the selected partitions for Windows to work, the search.fs_uuid command was failing, $root was empty and so grub can't find $prefix/grub.cfg (/boot/grub/grub.cfg in my linux rootfs which is on sda6==gpt6)

I automated it by changing the EFI grub.cfg, note my EFI System partition is 2 not 1 as in your example:

search.fs_uuid 47d6233f-c0ae-4f89-bf18-184452eac803 root hd0,gpt6 
set prefix=($root)'/boot/grub'
if [ -f $prefix/grub.cfg ]
then
    configfile $prefix/grub.cfg
else
    insmod chain
    set root=(hd0,gpt2)
    chainloader /EFI/Microsoft/Boot/bootmgfw.efi
    boot
fi

Now if grub can find the cfg file it will give me the menu to select the boot as before, but if it can't - when I'm in VirtualBox - it'll just boot straight into Win10.

Hope this helps!

like image 186
Jimbo Avatar answered Oct 31 '22 21:10

Jimbo