Monday, 20 July 2015

Using Easy2Boot with UEFI-only systems

Summary

Many people have asked me 'how can I boot to E2B and select a UEFI payload, if I only have one UEFI-only system'?

This blog post attempts to describe a solution.

New! SWITCH_E2B.exe is a Windows utility that allows you to switch .imgPTN images without booting in MBR-mode.


Introduction

As you probably know, to boot via UEFI, we need a FAT partition on the USB drive.

This can be in the form of a FAT32 EFI partition or a 'simple' MBR FAT32 partition.

The UEFI firmware will look at the first FAT partition on a USB drive and then look for a \EFI\BOOT\bootx64.efi or \EFI\BOOT\bootia32.efi boot file (depending on if it is a 64-bit UEFI system or a 32-bit UEFI system).

Easy2Boot and Grub4dos

Easy2Boot uses grub4dos. Grub4dos contains code that will only run from a IBM-compatible BIOS - it is not compatible with UEFI booting because there is no BIOS interrupt support from UEFI and the CPU is in a completely different mode.

How Easy2Boot supports UEFI

Say we have an ISO which supports UEFI-booting such as Clonezilla. Typically, CloneZilla has both 32-bit and 64-bit EFI boot files and so can be booted from both 32-bit and 64-bit UEFI systems.

To UEFI-boot from a USB drive instead of a CD, we need to have a FAT32 partition on the USB drive that contains the CloneZilla files.

The Easy2Boot MakePartImage ToolKit (MPI Toolkit) actually makes a FAT32 partition in memory, copies the ISO file contents to it and then saves it as a .imgPTN file. The .imgPTN file can then be copied to your E2B USB drive as a 'payload' file. It is a sector-for-sector copy of a complete partition.

When you select this .imgPTN file from the E2B menu (or using SWITCH_E2B.exe), E2B will replace the partition table on the E2B USB drive with a partition table which 'points' to the .imgPTN file. We now have a single FAT32 'simple' MBR-style partition on our E2B USB drive which we can connect to a UEFI system.

The UEFI system will see the .EFI boot file on the FAT32 partition and allow us to boot from it.



For more details about UEFI-booting, see this page on the E2B website.

Catch 22

The problem with E2B\grub4dos is that we need to boot in MBR\CSM\Legacy (IBM-compatible BIOS) mode, in order to select a UEFI payload .imgPTN file.

BUT WHAT IF WE CAN ONLY BOOT USING UEFI?

Easy2Boot does not contain any UEFI boot manager such as rEFInd because of one really annoying bug that seems to be in many UEFI systems. These systems will NOT MBR-boot if a valid UEFI boot file is detected. Even if you enable CSM support and disable secure-boot in the UEFI firmware, these 'bad' systems will not MBR-boot to E2B! This means we cannot run E2B or any 'MBR\CSM' ISOs or other MBR\CSM payloads on those systems.

Even if we just ignore these 'bad' UEFI systems, it also means that our E2B USB drive would need to be FAT32 and so would be limited to 4GB files.

This is why E2B uses this 'partition swap' system. All UEFI systems 'should' boot from a simple FAT32 USB drive as long as it contains the correct UEFI boot files. It also means that Secure Boot should work because we don't need to use a UEFI boot manager.

Solutions

In order to select the desired UEFI payload on our E2B USB drive, we need to replace the partition table on the E2B USB drive.

One way is to use the new SWITCH_E2B.exe Windows utility - just double-click on a .imgPTN file and it will be 'switched-in' and replace the E2B partitions.

Another simple way to do this on a Windows system, is to use the \QEMU_MENU_TEST (run as admin).cmd Windows batch file to run the QEMU emulator which is already on the E2B USB drive. Using QEMU, we can boot E2B and select the desired .imgPTN file to get to the CSM menu. Then we can connect the E2B USB drive to target system and it will UEFI-boot from the FAT32 partition that it will now detect.

Alternatively, we can MBR-boot to E2B on a real system and select the .imgPTN file from the menu and then run it to swap in the new partition.

But what if we don't have a working Windows system and only have the one UEFI system which will not MBR-boot?

My solution - create a 2nd UEFI-bootable Flash drive

My solution (workaround!) is to always carry another USB drive which contains a 32-bit and 64-bit UEFI-bootable WinPE OS, i.e.  a 'UEFI-boot stick'.

Solution - boot to WinPE and run QEMU (ChrisR's Win8.1SE project).

  1. Connect the spare UEFI-boot stick to the target UEFI system and UEFI-boot to WinPE.
  2. Connect the E2B USB drive (you can use a USB 3.0 port if you have booted to Win8\10 WinPE).
  3. Run \_ISO\SWITCH_E2B.exe - OR - Double-click on the \QEMU_MENU_TEST (run as admin).cmd file on the E2B USB stick if in the E2B menu system, select the desired .imgPTN file (see screenshot above) and switch to the CSM menu, then quit QEMU 
  4. Shutdown WinPE, remove the UEFI-boot stick and reboot from the E2B drive via UEFI.
Once you are finished, you can switch the E2B USB drive back to 'E2B Menu mode' by booting to WinPE again from the 'UEFI-boot stick' (or any Windows system) and running \e2b\SWITCH_E2B.exe or the \e2b\RestoreE2B (run as admin).cmd batch file.

You should now see the normal E2B contents on the USB drive (if not, eject the drive and re-connect it) and you can now repeat the process, as above, to select a different UEFI payload from the E2B Menu.

Tip: If you encounter UEFI-systems regularly, you may want to investigate the E2B grub2 menu system. This allows you to MBR- and UEFI-boot directly from a variety (>60) of .ISO files all from the one grub2 menu system. You can even UEFI-boot from some ISOs that do not contain EFI boot files within them (e.g. debian, Fedora Workstation, knoppix, etc.)!

How to make a WinPE 32+64-bit 'UEFI-boot stick'

Instructions on making a UEFI USB drive that will boot to WinPE on both 32-bit and 64-bit systems can be found here.  Note that this Win8.1SE 64-bit project by ChrisR already includes SysWow which is needed to run 32-bit applications on a 64-bit WinPE OS. This means that QEMU will run on the 64-bit WinPE and the 32-bit WinPE OS's.

Instead of using WinPE, you could use WinToUSB to create a WindowsToGo USB drive (use the VHD option). This will give you a full Windows environment to which you can install other Windows applications and use as a general purpose bootable OS.

It may be useful to copy SWITCH_E2B.exe onto this UEFI-boot stick too.

Tip: You may also find it useful to copy the portable version of RMPrepUSB to the 'UEFI-boot stick' (you can't install RMPrepUSB or copy it to the WinPE Desktop because WinPE runs from a RAM drive so it won't be there when you reboot it!).

If your E2B USB drive is a hard drive and you use a FAT32 'E2B Helper' flash drive with it, you can add the UEFI boot files to the Helper drive.

Note: The latest versions of the MPI Tool Kit contains a RestoreE2B_32_64.cmd file which will restore the E2B partitions from a 64-bit WinPE without needing WoW64 support or a 32-bit WinPE.