Jump to content











Photo
- - - - -

Boot Win10 VHD using Linux Grub2

vhd boot linux win10 grub

  • Please log in to reply
8 replies to this topic

#1 Natrim

Natrim
  • Members
  • 3 posts
  •  
    Ireland

Posted 22 May 2017 - 05:33 PM

Hi All

Thanks for sharing the knowledge and enthusiasm about Computers :)

I have a Linux Laptop (Arch Linux) and I use Virtualbox to run W10 for those things i cant run with Wine.

However I dont have the performance desired, and was wondering how to boot from linux to that VHD I have already there with my W10 Install, so I dont need to create a partition to have dual boot.

I know there is a tool Vboot that allows that but was wondering if there is a way of doing this without this tool since its a Grub modified to allow this.

I have been searching and only found things about doing this with Grub4dos but nothing about using Linux Grub2

Could any of you please point me in the right direction ?

Thanks a million.


  • Brito likes this

#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 May 2017 - 05:50 PM

Could any of you please point me in the right direction ?

The direction is here for having Linux in a image (whether this is the "right" one for your setup is to be found):

http://reboot.pro/to...rom-vhd-how-to/

 

You can use both grub4dos and grub2 (actually any Linux compatible bootloader capable of accessing an image and passing to the Linux kernel some parameters, actually if you take the kernel and initramfs outside the image *any* Linux compatible bootloader will do) but you will need to "insert" in the image kloop or similar (which may be "easy" and documented for a specific distro or not, the given thread does have specific documentation for Archlinux :)).

 

It seems to me however that you are somehow biased against grub4dos :w00t:, and there is really no reason for that, whatever floats your boat boot ;) will do nicely, including both grub4dos and GRUB2.

 

Or are you - viceversa - wanting to boot the Windows 10 from an image file?  :blush:

 

Windows 10 has native VHD support (it depends on the actual edition) but the image will need to be modified (if you are now running it in a VM) because of the different hardware between the VM and your "real" hardware.

 

Maybe you would be better served making a new image of a (Windows 10 based) PE?

Or a "Compact install"?

 

The issue you may have is that you need a NTFS partition anyway to host the VHD (there is no access to EXT2/3/4 or other Linux common filesystems in the early stages of booting) and - if you are using UEFI, also a FAT12/16/32 partition.

 

:duff:

Wonko



#3 Guest_AnonVendetta_*

Guest_AnonVendetta_*
  • Guests

Posted 22 May 2017 - 06:18 PM

@Wonko: I don't see anything in OP's post that would indicate s/he is biased against G4D, it's just your imagination. No negative comments about G4D were made. What you're failing to consider is that OP is *already* using GRUB2 *and* probably doesn't want to go through the hassle (however minor) of essentially changing their setup by switching out bootloaders. So they're asking for help with accomplishing a task using the bootloader they already have.

#4 Natrim

Natrim
  • Members
  • 3 posts
  •  
    Ireland

Posted 22 May 2017 - 06:34 PM

Hi Wonko,

Thanks a lot for that quick answer.

About using grub4dos I dont have nothing against it :) the only reason is trying to avoid multiple installed software to do the same, since I already have grub2 was interested on this option.

 

Maybe Im wrong but the post you point me is about booting a linux image, not a Windows one

 

Let me try to explain what I would like to archive...

 

I already have a VHD (well its really a VDI but i can convert this to any format needed)

This VDI is the drive of my Virtual W10 install and its working fine but want to boot this image as real baremetal pc and not as virtual.

 

I have UEFI system, and I already have an ESP partition.

 

The idea of all of this is getting a dual boot scenario, without having to shrink my linux partition to allocate a new partition for windows and clone the image there, which after some changes will give me a dual boot scenario.

 

I hope this gives a better description of scenario and objective.

Thanks :)

 

PD: Since you told me that a the file needs to be in an NTFS file system which make sense because windows cant read/write to ext filesystems I think I have no choice but to shrink my Linux partition to accommodate an NTFS one for Windows

 

Thanks ;)



#5 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 May 2017 - 07:23 PM

Yes, my bad :blush: , I initially thought you wanted to run your ArchLinux from an image, and only later realized that you wanted to boot Windows 10 from a file, but left the initial part of the post untouched.

 

IMHO the issues are more than one.

 

If you are using UEFI (and not BIOS/CSM) you are "limited" to GRUB2 (grub4dos, while having in recent versions compatibility with GPT, needs BIOS calls).

The showstopper here is bootmgr (or bootmgr.efi).

The grub4dos or GRUB2 can only be used as "primary bootmanagers" in BIOS, the actual bootloader remains bootmgr, i.e. the booting chain is on BIOS:
BIOS->MBR->[PBR] depending the way grub4dos or GRUB2 are installed->grub4dos or GRUB2 ("main" bootmanagers) -> chainloading of bootmgr->\boot\BCD->Winload.exe->Windows OS

 

On UEFI the actual bootloader choice can be moved to the UEFI firmware (or you can use GRUB2 and from it chainload the BOOTMGR.EFI, I believe) but anyway in the chain:

UEFI->EFI partition->GRUB2->chainloading of BOOTMGR.EFI->EFI/microsoft/boot/bcd->Winload.EFI->Windows OS

the BOOTMGR.EFI needs to be present.

 

To all effects BOOTMGR is a sort of mini-OS (not entirely unlike DOS) so you are limited (when it needs to access any file) to the various filesystems it supports.

 

On BIOS this can be by-passed in many cases using grub4dos (because grub4dos does have support for EXT2/3/4) using an "all in ram" approach (obviously limited by the amount of RAM you have available) and by using some third party disk drivers (to be seen if actually this is doable with Windows 10, it was doable for 7/8/8.1) because grub4dos has this capability of mapping a file (or an extent) to a "virtual drive" and pass this "handle" to drivers such as Firadisk or Winvblock.

 

GRUB2 AFAIK/AFAICT has a similar mechanism with its loopback device, but I don't think that there is any driver (for Windows) capable of "hooking" it. :unsure: 

 

In any case all "full" Windows installs tend to be (heavily) hardware/drivers dependent, so it is very unlikely that you can use the same image (which will be "tailored" to the VirtualBox "virtual" hardware) to boot the Windows on "real" hardware (in these regards a PE would be much more suited).

In these regards I believe that Windows 10 is a tad bit more "flexible" or "universal" than previous versions, but you would have anyway hardware/drivers issues (if you plan to alternately boot the same image in the VM and on bare metal) and most probably also issues (I believe it depends on the Windows editions/license you have) with activation/authentication/whatever of the OS.

 

And if you are going to need a NTFS partition anyway (to host the Windows 10 VHD) the only advantages of actually having it in a VHD is - maybe - related to backups, otherwise it would make more sense to eliminate the VHD container and just have a "plain" on-volume install.

 

All in all, since booting a "full" Windows from USB is doable and if you have UEFI very likely you have USB3 ports, the easiest for nto touching your current "Linux only" partitioning would be a USB 3 flash stick with a Windows to Go (original MS one or a similar build) or a PE of some kind.

 

:duff:

Wonko



#6 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 23 May 2017 - 12:31 PM

If you want full performance, you will need to run the VHD from your internal HDD, but you could boot from a USB drive.

Using a VHD would be a more flexible option because you could update your vdi file and then convert it to vhd to keep it up to date.

 

You will need a Windows system or VM (not sure if WINE will work).

 

1. Create a WinToGO USB drive using WinToUSB and using a VHD file (say 20GB) - use a fast USB drive (HDD or Sandisk Extreme USB 3). For the free version use GPT and .VHD. Do first Setup boot and check it works.

2. Create an NTFS partition on your linux HDD

3. Copy the VHD file from the WinToGo flash drive to your NTFS partition on the internal HDD

4. Convert your VDI to a VHD and copy that to your NTFS partition

5. Boot from the USB drive to WinToGo - mark the system drive as online - use BootIce to add 2 new BCD entries to the BCD on the WinToGo USB drive (depending on how you want to boot, edit \Boot\BCD or \EFI\Microsoft\Boot\BCD or both) pointing it at the VHDs on the internal drive.

 

Now you should be able to boot to either VHD from the USB drive.

 

By having the original VHD and your old VHD, you can check that there is nothing wrong with your old VHD.

Also, you can just copy the boot files on the FAT32 to a smaller USB drive as the NTFS partition is not needed.

Also, if you change your VDI\VHD, you can boot to the original WinToGo VHD and run BootIce if required (or just keep same filename).

 

If it is all working, you could try transferring the files from the EFI  partition on the WinToGo USB drive to a FAT partition on your internal HDD and adding a grub2 entry to boot to /bootmgr or /EFI/BOOT/BOOTx64.EFI. However, any future linux OS updates you make to linux may remove the entries in grub.cfg.

 

I think this might work, but don't blame me if not... :lol:



#7 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 23 May 2017 - 01:24 PM

P.S. I just tried this and I had some issue getting access to the EFI partition and then BootIce would not access the BCD as it said it was in use.

To get around this you can boot to another Windows OS (e.g. VM) and run BootIce from their to edit the USB BCD. Obviously the Windows OS will need access to the internal HDD and the NTFS partition.

 

Doh! Forget this - just use BootIce and BCD - Current System  (I habitually used the 'Other BCD File' button without thinking!).

 

Or

Another trick is to boot to WinToGo and use   mountvol Z: /s  to mount the system EFI partition as Z:

If you previously copied the \EFI\Microsoft\Boot\BCD file, you can then edit it with BootIce to add the entries you need.

Then reboot to another OS and swap the new BCD for the old one.

 

CaptureEFIBCD.JPG

 

Note Display Boot Menu is ticked.

 

P.S. You could use Rufus under WINE to make a WinToGo USB drive rather than WinToUSB. It is reported to work...


Edited by steve6375, 23 May 2017 - 02:07 PM.


#8 cdob

cdob

    Gold Member

  • Expert
  • 1469 posts

Posted 23 May 2017 - 06:28 PM

I already have a VHD (well its really a VDI but i can convert this to any format needed)
This VDI is the drive of my Virtual W10 install and its working fine but want to boot this image as real baremetal pc and not as virtual.
 
I have UEFI system, and I already have an ESP partition.

Which mass storage controller do you use at VirtualBox? Did you use SATA disk?
Does the real hardware use SATA mode too?

Yes, a additional NTFS partition is recommended.
Core windows boot files goes to the ESP partition too.
Did you disable secure boot?
Chainload UEFI bootmgr at grub 2:
chainloader /EFI/Microsoft/Boot/bootmgfw.efi
.
Copy the vhd file to a NTFS partiton.
Boot a Windows 10 installation media.
Run diskpart.exe and mount the VHD file.
Run bcdboot.exe to create windows boot files:
Target: ESP partition: Be aware /efi/boot/bootx64.efi is overwritten. And NVRAM settings are changed.
Target: prefer a intermediate USB drive. Next copy /efi/microsoft/ to the ESP partition.
Adjust grub.cfg

By the way: VirtalBox and VMware can read a fixed size VHD image.

#9 Natrim

Natrim
  • Members
  • 3 posts
  •  
    Ireland

Posted 23 May 2017 - 07:17 PM

@cdob to answer your questions

 

I'm using Sata in Virtualbox

Real hardware uses Sata as well

Secure boot is disabled

 

Thank you all for the tips and tricks, and all the detailed answers. I really appreciate it.

After doing some testing just for learning and improve my knowledge...

I will end up just shrinking the Linux partition and creating a NTFS to accommodate W10 to be used as typical dual boot scenario (using UEFI and GPT).

 

Thanks :)







Also tagged with one or more of these keywords: vhd, boot, linux, win10, grub

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users