122 - Boot directly to UEFI mode using Clover

Introduction

Clover is a later revision of Tianocore. Both are 'firmware in RAM' replacements for UEFI firmware.

It allows you to boot in MBR\CSM mode and then run Clover which acts as a 'pseudo-UEFI boot manager', allowing you to boot to a UEFI OS from an MBR\CSM boot.

You can make a USB drive which boots to grub4dos in MBR mode (grub4dos will not boot in UEFI mode) and then load Clover. From the Clover GUI you can then boot from the UEFI files on the same USB drive (e.g. Windows 7/8 installation files) or UEFI-boot from a different partition/drive.

i.e. without rebooting we will follow this path:

grub4dos --> Clover --> UEFI boot files --> UEFI OS

Note that Easy2Boot now supports Clover for booting 64-bit FAT32 partition images to UEFI.

Note: Clover seems to constantly change and different versions have different bugs. The config.plist syntax also seems to vary a lot between versions. e.g The current release version does not seem to detect \EFI\boot\bootia32.efi files (July 2015).

Theory

I will assume the following:

  1. The UEFI boot files are on the FIRST PRIMARY FAT32 partition of your USB drive. This is a MUST HAVE prerequisite. You could use place the Clover files and PBR on a different FAT32 partition if you wish but you would need to modify the menu.lst file. To have the capability of UEFI-booting directly to the Windows installer, the FAT32 partition needs to be the first one - if you always want to boot via Clover from MBR mode, you could put the Clover boot files on a different partition.

  2. Most UEFI firmware will only boot from a FAT32 partition if it is the first one on the USB drive. You can have other partitions (e.g. NTFS) after this first partition if you wish. Note that Windows\WindowsPE\Windows Setup cannot access any partition, other than the first one, if the USB drive is a Removable-type flash drive.

  3. The Partition Boot Record (PBR) will need to contain Clover boot code, therefore we need to backup the current PBR boot sector to PBR.BIN. To boot to syslinux, we can then use chainloader /PBR.BIN instead of chainloader +1.

  4. The Master Boot Record (MBR) must contain grub4dos boot code

  5. Clover will only be able to access USB drives that are connected to a USB 2.0 port (even though you may be able to boot to grub4dos from a USB 3.0 port)

    1. I will assume we are only interested in 64-bit booting (the \EFI\CLOVER\BOOTIA32.EFI file and drivers32 folder is required for 32-bit UEFI).

Requirements

Obtain the Clover Boot Files

A ready-made download put together by me is here. It contains boot1F32ALT7 and PBR.BIN files and a modified config.plist file to show bootx64.efi entries plus the ntfs.efi driver in the drivers64 folder - or you can make your own version as follows...

      1. You need a Clover bootable file set. I recommend you download BootDiskUtility and use it to install Clover onto a spare USB Flash drive. This will boot directly to Clover. Then copy the files from the USB drive to a folder on your system's hard disk - e.g. C:\temp\Clover\orig.

      2. You can use this flash drive immediately (on a real system not under QEMU) for testing. Tip: Press 7 immediately after it starts to boot to Clover if you have problems booting.

      3. Alternatively, download a bootable Clover ISO from here - e.g. CloverISO-2671.tar.lzma. Unzip it and then unzip the Clover2k-xxxx-X64.iso file to your C:\temp\Clover\orig folder.

      4. You should now have a folder structure like this (ones in red not required):

      5. C:\temp\Clover\orig\EFI

      6. C:\temp\Clover\orig\usr

      7. C:\temp\Clover\orig\Library

      8. C:\temp\Clover\orig\[BOOT]

      9. Make a copy of the orig folder and call it USB - i.e. C:\temp\Clover\USB

      10. Delete from the USB folder the USB\usr, USB\Library and [BOOT] folders (if present)

      11. Delete from the USB folder the USB\EFI\BOOT folder (the Clover \EFI\BOOT\xxx.efi files must NOT be present - these will cause a UEFI boot to boot back to Clover again!)

      12. If present, delete the large 3MB Russian PDF in the USB\EFI\CLOVER\doc folder (unless you speak Russian and find it useful!)

      13. (optional) Some themes are quite large (e.g. USB\EFI\CLOVER\themes\metal is 4MB) - you can delete this 'themes\xxxx' folder and/or replace it with a different theme folder. See 'Themes' below for more details

7. Clover can also use a selection of boot files, these are boot2, boot3, boot6, boot7 and boot8 (\boot is the default file - but we won't be using this).

Also we need a special modified PBR boot file called \Clover\boot1F32ALT7.

These boot files can be downloaded from here.

IMPORTANT: If you have a file called \boot then delete it, as it will prevent you from having a folder called \BOOT which is required by Windows.

8. Download and add the file PBR.BIN to the USB folder (from here).

9. For NTFS support, ensure that the ntfs.efi file is in the \EFI\CLOVER\drivers64 folder (and drivers32 if for 32-bit systems).

10. Check the 'Hide' entries in \EFI\CLOVER\config.plist - ensure BOOTX64.EFI is not there (if so delete that line from the file or add XXX in front of it)

11. Delete any files in the \EFI\BOOT folder - these will boot to Clover from a UEFI boot and we will replace these files with our payload .efi files later so that it boots to the payload OS rather than booting to Clover.

You should now have a C:\temp\Clover\USB folder containing one \EFI\CLOVER folder. In the \EFI\CLOVER folder should be CLOVERX64.efi (used for 64-bit MBR booting) and other files and folders. CLOVERIA32.EFI and the \EFI\CLOVER\drivers32 folder are only used when booting on a 32-bit system.

Essential these files, as a minimum, are present:

  • \boot7

  • \PBR.BIN

  • \Clover\BOOT1F32ALT7

  • \Clover\boot0ss

  • \EFI\CLOVER folder

Make a grub4dos-bootable USB Drive

    1. You need a USB drive that contains a FAT32 partition as the first partition (in the partition table). If you wish you can have further Primary partitions (FAT32 or different).

    2. The FAT32 partition should be marked as Active (bootable) - not essential, but it helps 'bootability' on a wider variety of systems.

    3. For best compatability, the partition geometry should be 255 heads x 63 sectors (use RMPrepUSB to partition it, if you are not sure what this means!)

    4. Install grub4dos to the MBR of the drive (I recommend using the RMPrepUSB - Install grub4dos button) Tip: select the No User Prompts tick box first!

    5. Ensure \grldr is present after installing grub4dos - use a 2014 version (or 2013 at the latest!)

I recommend you use RMPrepUSB to wipe and format a USB drive (RMPrepUSB improves write speeds and gives a more reliable boot experience). If you are only going to have one single partition on the USB drive, tick the RMPrepUSB 4 - Boot as HDD (C: 2PTNS) option, otherwise untick it. If you are going to have more than one partition, set the size of the first partition in the Size box before you format it with RMPrepUSB and then use something else to create the 2nd NTFS Primary partition.

Check the USB drive

Before we go any further, use RMPrepUSB to check your USB drive is formatted correctly using RMPrepUSB (or other methods) as below:

    1. Select the USB drive in the drive selection list and click on Drive Info and type 0 - then look at the NotePad window and check that the first partition is a FAT32 partition and is Active

    2. Check that the END POS HD and SEC numbers are 254 and 63. If they are not then it may not boot correctly on some systems - see below (e.g. Acer 77xx Series laptops are fussy!).

    3. Check that the 'Missing MBR-helper' string is present in the first sector data (see below) - this means that the grub4dos code has been correctly installed to the MBR.

    4. Check that it boots to the grub4dos console by clicking on the Test Using QEMU Emulator F11 button in RMPrepUSB (enter 0 for the Virtual Drive size and accept the default for the memory size) - you should see a grub4dos console window. Check that the grub4dos version (shown at the top of the console) is around mid-2013 or later. If not, replace the \grldr file with one from here. Use version 0.4.5c 2014-01-17 or later (avoid 0.4.6a versions as these are Beta versions).

Example Drive Info partitions displayed in NotePad:

=====================================

Partition 1 SIZE=30798.969MiB Type: 0C FAT32LBA (2047GB max) *ACTIVE*

START POS = CYL:0 HD:1 SEC:1 END POS = CYL:1023 HD:254 SEC:63

START (LBA) = 63 (0000003F) SIZE (LBA) = 63,076,289 (03C277C1) [End=63,076,351]

Partition 2 SIZE=0MiB Type: 00

START POS = CYL:0 HD:0 SEC:0 END POS = CYL:0 HD:0 SEC:0

START (LBA) = 0 (00000000) SIZE (LBA) = 0 (00000000)

Partition 3 SIZE=0MiB Type: 00

START POS = CYL:0 HD:0 SEC:0 END POS = CYL:0 HD:0 SEC:0

START (LBA) = 0 (00000000) SIZE (LBA) = 0 (00000000)

Partition 4 SIZE=0MiB Type: 00

START POS = CYL:0 HD:0 SEC:0 END POS = CYL:0 HD:0 SEC:0

START (LBA) = 0 (00000000) SIZE (LBA) = 0 (00000000)

0190 0A 4D 69 73 73 69 6E 67 - 20 4D 42 52 2D 68 65 6C .Missing MBR-hel

01A0 70 65 72 2E 00 00 00 00 - 00 00 00 00 00 00 00 00 per..... ........

Add the Clover Files

Assuming you now have a bootable grub4dos USB 'Active' FAT32 drive, we can now add the Clover files

  1. Copy the USB folder contents from C:\temp\Clover\USB to the root of your USB drive's FAT32 first partition

Essential files, as a minimum, that must be present are:

  • \boot7

  • \PBR.BIN

  • \Clover\BOOT1F32ALT7

  • \Clover\boot0ss

  • \EFI folder

Add your Payload Files

Now we need to copy the OS files to the USB drive. I will assume that you want to add Windows 7/8 Installer files from a Windows 7/8 ISO or DVD. Linux could be added instead.

    1. Copy ALL the source OS files directly to the root of the USB drive (or the 2nd NTFS partition if you prefer)

    2. Check that there is an \EFI\boot\bootx64.efi file (used for 64-bit UEFI booting). If not, then the source files you used are not 64-bit UEFI-bootable or you will need to move\rename some files (e.g. if an early Win7 version) so that the \EFI\boot\bootx64.efi file is present.

Add the grub4dos menu

The grub4dos menu is at \menu.lst. You will need to use an existing menu.lst file from one of your other projects or one of my projects from this site or use NotePad to create a own new file. Note: If using Windows NotePad, ensure you save the file as 'Save as *.*' and it is menu.lst and not menu.lst.txt !

The menu.lst code to add a Clover boot menu entry is shown below. Ensure that the \menu.lst file contains this code.

The PBR code is automatically backed up and is changed by the Clover boot menu code (overwritten, non-volatile and remains patched after a reboot).

If your PBR contained needed boot code (e.g. syslinux boot code), use the backup in \PBR.BIN to boot from the PBR now (see last menu entry below).

# backup PBR - this must go at the start of the menu.lst file

dd if=()+2 of=()/PBR.BIN > nul

iftitle [if exist /boot7 && cat --locate="FAT32" --length=10 --skip=0x50 ()+1 > nul] Clover 64-bit UEFI Boot Menu\n Boot via UEFI (choose the UEFI boot option)\n Note: EFI options are for MBR booting\n Use a USB 2.0 port (USB 3.0 not supported)

set CL=0

## boot7 is default boot file

cat --locate="BOOT7" --length=10 --skip=0x58 ()+1 > nul && set /a CL=%CL%+1 > nul

if "%CL%"=="1" echo Information: Clover is already installed to the PBR

echo ffffffffff > (md)0x350+1

dd if=(hd0,0)+1 of=(md)0x350+1 > nul

dd if=()/clover/boot1f32alt7 of=(md)0x350+1 skip=90 seek=90 bs=1 > nul

dd if=()/clover/boot1f32alt7 of=(md)0x350+1 count=3 bs=1 > nul

#cat --hex (md)0x350+1 && pause

if not "%CL%"=="1" dd if=(md)0x350+1 of=(hd0,0)+1 > nul && pause --wait=2 PBR has been updated with Clover boot code...

chainloader /clover/boot0ss

boot

# User can press 2 for 3 for 32-bit UEFI, 6 for 64-bit UEFI or 1 for Chameleon - within 2 seconds - uses \bootx files in root

# boot0md (multi-drive) displays a boot0 message and is slower and needs an active partition - boot0ss is silent and quick.

iftitle [if exist (hd0,1)/bootmgr] Boot Windows on 2nd partition (MBR-mode)\n Boot Windows using bootmgr on (hd0,1)

root (hd0,1)

chainloader /bootmgr

#syslinux

iftitle [cat --locate="SYSLINUX" --length=10 --skip=0x2 /PBR.BIN > nul] Alternate boot (syslinux)\n Try this if the other boot options don't work.

errorcheck off

chainloader /PBR.BIN && boot

IMPORTANT: If you have other menu entries that use chainloader +1 or chainloader ()+1 or chainloader (hd0,0)+1 then you will need to change the code to

chainloader /PBR.BIN

Ready - Steady - Go!

You should now be able to boot the USB drive to grub4dos, select the Clover menu option and boot to the Clover GUI (if you see a text-mode BIOS-type screen, then it did not boot correctly! - check the \EFI\CLOVER\CLOVERxxxx.efi files are present). If it immediately boots to Windows Setup, then you have booted it from a UEFI system in UEFI mode! You must choose a non-UEFI boot option to boot to grub4dos.

You can either test on a real system or use Virtual Box + DavidB's VMUB utility - set up the VM for UEFI booting (Settings - System - Enable EFI (special OSes only)).

Note: The RMPrepUSB QEMU version is 32-bit onlly and will not boot 64-bit Clover.

Clover - Black and Green theme

Using Clover

You can press F1 for help or select a boot option from one of the larger Clover boot icons.

IMPORTANT: Some Clover themes calls MBR\CSM boot options 'EFI'. So the 'Boot EFI...' options mean boot in MBR mode, whereas the 'Boot UEFI xxxxx' options mean boot in UEFI mode.

EFI = MBR\CSM (old BIOS mode)

UEFI = UEFI (new UEFI mode)

For more information on Clover see here and the wiki here.

Only the \boot7 and \Clover\BOOT1F32ALT7 files are essential (as well as the \EFI folder). If you are short of space, you can delete the other bootx files and the other files in the \Clover folder.

FAT32 is limited to 4GB!

You may notice that the largest file (usually \sources\install.wim) that you can have on a FAT32 partition is 4GB. UEFI booting must be from a FAT formatted partition (though you can ask Clover to boot from an NTFS .efi file manually). If you have a large Windows install (e.g. an All-In-One ISO) which you want to add to the USB drive, you have some choices...

1. Create a 2nd NTFS partition (must NOT be the first partition on the disk!)

This only works for Hard Disks/Fixed Disks (Windows will not access the 2nd partition on a Removable USB drive).

Move the \sources\Setup.exe file and the \sources\install.wim (or install.esd) file to the NTFS partition (note I said MOVE not COPY!) - the NTFS partition will thus have a \sources folder containing these two files and the FAT32 \sources folder will NOT contain these two files.

2. Split the install.wim into small files

Use a tool such as WinToolKit - Tools - Imaging - Wim Splitter to split the install.wim file into 3GB parts. Delete the original \sources\install.wim file to leave \sources\install.swm and install2.swm.

Note: If you have a Win8 Install fileset with .swm files, you will get a 'Microsoft license' error after entering a Product Key, to avoid this error, add a EI.CFG file to the same \sources folder that contains the \sources\install.wim and Setup.exe file; this prevents the Product Key from being requested. The EI.cfg file must be tailored to suit the type of install you are using (i.e. Volume Licence or Retail/OEM).

3. Add a 2nd NTFS partition (and boot from the UEFI NTFS partition)

This only works for Hard Disks/Fixed Disks (Windows will not access the 2nd partition on a Removable USB drive).

  • Partition 1 = FAT32 MUST NOT contain a \EFI\BOOT\bootx64.efi file and a \sources\Setup.exe file.

  • Partition 2 = NTFS MUST contain both \EFI\BOOT\bootx64.efi and \Sources\Setup.exe (and the install.wim or install.esd file as usual). - i.e. just extract all files from a Windows installer ISO.

When you boot to grub4dos, you can choose to boot to whatever payload you have in the FAT32 partition (e.g. Win7/8 32-bit installer) as usual.

How it works

The whole Clover boot chain is:

MBR - grldr - (grub4dos menu) - \Clover\boot0ss - PBR (code from \Clover\BOOT1F32ALT7) - \boot7 - \EFI\CLOVER\CLOVERX64.efi (or CLOVERIA32.EFI if 32-bit system).

BOOT1F32ALT7 looks for \boot7 by default. The normal Clover boot1xxx PBR code files look for \boot by default. You can override the default boot file by pressing a number key within 2 seconds - e.g. press 2 to boot using \boot2. I suggest you read my blog here for more details.

Once in the Clover GUI, we need to boot from the default \EFI\BOOT\bootx64.efi file (or \EFi\BOOT\bootia32.efi if a 32-bit system) to boot to an OS in UEFI mode - Clover will find these files on all drives and display an icon for each one.

The NTFS.efi driver is automatically loaded from \EFI\CLOVER\drivers64.

Boot icons in the GUI menu can be suppressed by editing the \EFI\CLOVER\config.plist file - e.g.

<key>Hide</key>

<array>

<string>Windows</string>

<string>XXXBOOTX64.EFI</string>

<string>cdboot.efi</string>

<string>bootmgr.efi</string>

<string>bootmgfw.efi</string>

</array>

In the GUI menu - normally F1 will give you Help and pressing SPACE when an icon is selected will give you more information and boot options for that entry.

Themes

To change the 'theme' (screen icons, colours, etc.) download a theme package (see here). Extract the 'payload' folder using 7Zip or some other tool and then replace the folder at .\EFI\CLOVER\themes\ with your new folder. If there is only one folder under .\themes then Clover will automatically use it (if you have more than one then you will need to edit \EFI\CLOVER\config.plist to set the default theme).

e.g. For an orange theme, find the folder inside the .pkg file named 'orange' (check that there is an icons folder below it) e.g. the correct path for a typical graphics element in a theme called 'orange' is:

\EFI\CLOVER\themes\orange\icons\xxxxx.png

There should only be one folder under \EFI\CLOVER\themes.

For more information on Clover, see the info and links here.

Read more: http://www.easy2boot.com/configuring-e2b/configure-clover/

Clover files

The files below are needed by Clover if booting on a system with a 64-bit CPU.

Files with 32 or IA32 are files that are used if booting on a 32-bit CPU

Files with '64U' in the name are files that are used when Clover is booted from a 64-bit UEFI system in UEFI mode (there are no 32-bit UEFI systems).

\

=====

\boot7 - 3rd stage boot file (32\64-bit) - other versions may exist such as boot, boot2, boot3, boot6, boot8. If the user press a number key within 2 seconds (e.g. 3 pressed then \boot3 will be used)

\CLOVER

=======

boot0ss - 1st stage boot file (normally found in the MBR) - other variants may exist, e.g. boot0md, boot0af

BOOT1F32ALT7 - 2nd stage boot code (normally found in the PBR) - reads FAT32 filesystems, waits 2 seconds for a number key press - loads \boot7 by default

EFI\CLOVER

==========

config.plist - essential for configuring Clover, contains many software settings (e.g. themes, defaults, hide options, hardware definitions, etc.

CLOVERX64.efi - Clover GUI - required if booting Clover on a 64-bit CPU

\EFI\CLOVER\TOOLS

================

Shell64.efi - (optional) the EFI command line shell - if missing, no Start EFI Shell 64 icon will be displayed in the GUI menu

\EFI\CLOVER\DRIVERS64 - drivers automatically loaded by EFI shell if running on a 64-bit system

===================

FSInject-64.efi - Driver responsible for Clover's /EFI/kexts/XXX kext injection into kernelcache

Ps2MouseDxe-64.efi - PS\2 Mouse driver

UsbMouseDxe-64.efi - USB Mouse driver

NTFS.efi - loads the NTFS driver so Clover can boor from NTFS partitions

\EFI\CLOVER\THEMES - (optional)

=================

Folders in here contain different themes. If only one folder exists then that will be used as the default theme

If no theme folder is present, a minimal theme will be used for the GUI.

All other files and folders are non-essential for booting to Clover via an MBR boot on a 64-bit CPU system.

\EFI\BOOT\BOOTX64.EFI is the default file that is looked for by any x86 64-bit UEFI system when attempting to UEFI-boot from an unknown device.

Note: A \EFI\BOOT\BOOTX64.EFI file may be present in the Clover file set. This is the default file that will be loaded by a system containing UEFI firmware with a 64-bit CPU that will boot it to Clover in UEFI mode. If Clover is running in UEFI mode, it can only boot the UEFI .EFI boot files and cannot boot Legacy\BIOS executables (like ntldr or bootmgr).

As this file and path is the default 64-bit UEFI boot file path that is only loaded by a UEFI system, we usually need this file to be the derived from the 'OS payload' (i.e. the bootx64.efi file from our UEFI linux or Windows 7/8 OS) - we don't want the Clover version or else if we select bootx64.efi in the GUI menu - Clover will just boot back to Clover again!

Clover 32-bit UEFI

You can add support for booting Clover 32-bit UEFI too.

  • Add \boot3

  • Add \EFI\CLOVER\CLOVERIA32.efi

  • Add \EFI\CLOVER\drivers32 (whole folder)

  • Add a new menu entry:

iftitle [if exist /boot3 && cat --locate="FAT32" --length=10 --skip=0x50 ()+1 > nul] Clover 32-bit UEFI Boot Menu\n Boot via UEFI (choose the UEFI boot option)\n Note: EFI options are for MBR booting\n Use a USB 2.0 port (USB 3.0 not supported)

set CL=0

cat --locate="BOOT3" --length=10 --skip=0x58 ()+1 > nul && set /a CL=%CL%+1 > nul

if "%CL%"=="1" echo Information: Clover is already installed to the PBR

echo ffffffffff > (md)0x350+1

dd if=(hd0,0)+1 of=(md)0x350+1 > nul

dd if=()/clover/boot1f32alt7 of=(md)0x350+1 skip=90 seek=90 bs=1 > nul

dd if=()/clover/boot1f32alt7 of=(md)0x350+1 count=3 bs=1 > nul

cat --locatei=boot7 --replace=BOOT3 (md)0x350+1 > nul

if not "%CL%"=="1" dd if=(md)0x350+1 of=(hd0,0)+1 > nul && pause --wait=2 PBR has been updated with Clover boot code...

chainloader /clover/boot0ss || chainloader /clover/boot0md || chainloader /clover/boot0af

boot